diff --git a/record_m3u8.sh b/record_m3u8.sh index a2b5641..1cececf 100644 --- a/record_m3u8.sh +++ b/record_m3u8.sh @@ -1,7 +1,7 @@ #!/bin/bash # General m3u8 Live Stream Recorder -if [ ! -n "$1" ]; then +if [[ ! -n "$1" ]]; then echo "usage: $0 m3u8_url [loop]" exit 1 fi @@ -11,7 +11,7 @@ while true; do FNAME="stream_$(date +"%Y%m%d_%H%M%S").ts" ffmpeg -i "$1" -codec copy -f mpegts "$FNAME" - [ "$2" != "loop" ] && break + [[ "$2" != "loop" ]] && break LOG_PREFIX=$(date +"[%Y-%m-%d %H:%M:%S]") echo "$LOG_PREFIX The stream is not available now." diff --git a/record_openrec.sh b/record_openrec.sh index 55d7aa4..71a8971 100644 --- a/record_openrec.sh +++ b/record_openrec.sh @@ -1,7 +1,7 @@ #!/bin/bash # OPENREC.tv Live Stream Recorder -if [ ! -n "$1" ]; then +if [[ ! -n "$1" ]]; then echo "usage: $0 openrec_id [format] [loop|once]" exit 1 fi @@ -19,7 +19,7 @@ while true; do LIVE_URL=$(curl -s "https://www.openrec.tv/user/$1" |\ grep -Eoi "href=\"https://www.openrec.tv/live/(.+)\" class" |\ head -n 1 | cut -d '"' -f 2) - [ -n "$LIVE_URL" ] && break + [[ -n "$LIVE_URL" ]] && break echo "$LOG_PREFIX The stream is not available now." echo "$LOG_PREFIX Retry after 30 seconds..." @@ -40,5 +40,5 @@ while true; do # 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 + [[ "$3" == "once" ]] && break done diff --git a/record_twitcast.sh b/record_twitcast.sh index c323953..ee07811 100644 --- a/record_twitcast.sh +++ b/record_twitcast.sh @@ -1,7 +1,7 @@ #!/bin/bash # TwitCasting Live Stream Recorder -if [ ! -n "$1" ]; then +if [[ ! -n "$1" ]]; then echo "usage: $0 twitcasting_id [loop|once]" exit 1 fi @@ -32,5 +32,5 @@ while true; do # 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." - [ "$2" == "once" ] && break + [[ "$2" == "once" ]] && break done diff --git a/record_twitch.sh b/record_twitch.sh index e22f14f..43916fa 100644 --- a/record_twitch.sh +++ b/record_twitch.sh @@ -1,7 +1,7 @@ #!/bin/bash # Twitch Live Stream Recorder -if [ ! -n "$1" ]; then +if [[ ! -n "$1" ]]; then echo "usage: $0 twitch_id [format] [loop|once]" exit 1 fi @@ -35,5 +35,5 @@ while true; do # 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 + [[ "$3" == "once" ]] && break done diff --git a/record_youtube.sh b/record_youtube.sh index 522e36c..e7a121a 100644 --- a/record_youtube.sh +++ b/record_youtube.sh @@ -1,14 +1,13 @@ #!/bin/bash # YouTube Live Stream Recorder -if [ ! -n "$1" ]; then +if [[ ! -n "$1" ]]; then echo "usage: $0 youtube_channel_id|live_url [format] [loop|once]" exit 1 fi # Construct full URL if only channel id given LIVE_URL=$1 -# Use double square brackets construct here to test substring [[ "$1" == "http"* ]] || LIVE_URL="https://www.youtube.com/channel/$1/live" # Record the best format available but not better that 720p by default @@ -26,7 +25,7 @@ while true; do M3U8_URL=$(youtube-dl -g -f "$FORMAT" \ --no-playlist --playlist-items 1 \ --match-filter is_live "$LIVE_URL" 2>/dev/null) - [ -n "$M3U8_URL" ] && break + [[ -n "$M3U8_URL" ]] && break echo "$LOG_PREFIX The stream is not available now." echo "$LOG_PREFIX Retry after 30 seconds..." @@ -52,5 +51,5 @@ while true; do # 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 + [[ "$3" == "once" ]] && break done