Skip to content
This repository has been archived by the owner on Oct 31, 2020. It is now read-only.

Commit

Permalink
Add general script for websites streamlink supports
Browse files Browse the repository at this point in the history
  • Loading branch information
prinsss committed Nov 10, 2018
1 parent 0b8f6b3 commit 9042573
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,33 @@ sys.setdefaultencoding('utf8')

录像的文件名格式为 `twitcast_{id}_YYMMDD_HHMMSS.ts`,其他与上面的相同。

## 其他直播平台自动录像

基本上 [streamlink 支持的直播站点](https://streamlink.github.io/plugin_matrix.html) 都支持(包括国内的斗鱼、熊猫什么的)。

```bash
./record_streamlink.sh live_url [format] [loop|once]

# Example
./record_streamlink.sh "https://www.douyu.com/3614"
./record_streamlink.sh "https://www.panda.tv/371037"
```

第一个参数为直播间 URL,第二、第三个参数与 OPENREC 的脚本相同。

录像的文件名格式为 `stream_YYMMDD_HHMMSS.ts`,其他与上面的相同。

## 通过 `.m3u8` 地址手动录像

此脚本适用于任何已知 `.m3u8` 地址的情况,不过只能对传入的该场直播进行录像,无法监视后续直播与自动录像。

如果上面的脚本没有适配某个平台(比如 Mirrativ、SHOWROOM),你也可以自己抓取出 `.m3u8` 地址手动开始录像。

```bash
./record_m3u8.sh https://record.mirrativ.com/archive/hls/39/0018438274/playlist.m3u8
./record_m3u8.sh "https://record.mirrativ.com/archive/hls/39/0018438274/playlist.m3u8"
```

第一个参数为 `.m3u8` 地址,录像的文件名格式为 `stream_{id}_YYMMDD_HHMMSS.ts`
第一个参数为 `.m3u8` 地址,录像的文件名格式为 `stream_YYMMDD_HHMMSS.ts`

第二个参数为可选参数,指定为 `loop` 可以让脚本每隔 30s 尝试下载该 `.m3u8` 地址。

Expand Down
40 changes: 40 additions & 0 deletions record_streamlink.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash
# General Live Stream Recorder Powered by Streamlink

if [[ ! -n "$1" ]]; then
echo "usage: $0 live_url [format] [loop|once]"
exit 1
fi

# Record the best format available but not better that 720p by default
FORMAT="${2:-720p,480p,best}"

while true; do
# Monitor live streams of specific channel
while true; do
LOG_PREFIX=$(date +"[%Y-%m-%d %H:%M:%S]")
echo "$LOG_PREFIX Try to get current live stream of $1"

# Get the m3u8 or flv address with streamlink
STREAM_URL=$(streamlink --stream-url "$1" "$FORMAT")
(echo "$STREAM_URL" | grep -q ".m3u8") && break
(echo "$STREAM_URL" | grep -q ".flv") && break

echo "$LOG_PREFIX The stream is not available now."
echo "$LOG_PREFIX Retry after 30 seconds..."
sleep 30
done

# Record using MPEG-2 TS format to avoid broken file caused by interruption
FNAME="stream_$(date +"%Y%m%d_%H%M%S").ts"
echo "$LOG_PREFIX Start recording, stream saved to \"$FNAME\"."
echo "$LOG_PREFIX Use command \"tail -f $FNAME.log\" to track recording progress."

# Start recording
ffmpeg -i "$STREAM_URL" -codec copy -f mpegts "$FNAME" > "$FNAME.log" 2>&1

# Exit if we just need to record current stream
LOG_PREFIX=$(date +"[%Y-%m-%d %H:%M:%S]")
echo "$LOG_PREFIX Live stream recording stopped."
[[ "$3" == "once" ]] && break
done

0 comments on commit 9042573

Please sign in to comment.