This repository has been archived by the owner on Oct 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add general script for websites streamlink supports
- Loading branch information
Showing
2 changed files
with
58 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |