Skip to content

Commit

Permalink
Prefer double square brackets for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
prinsss committed Oct 28, 2018
1 parent 3a51874 commit 25d1f0d
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 13 deletions.
4 changes: 2 additions & 2 deletions record_m3u8.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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."
Expand Down
6 changes: 3 additions & 3 deletions record_openrec.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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..."
Expand All @@ -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
4 changes: 2 additions & 2 deletions record_twitcast.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions record_twitch.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
7 changes: 3 additions & 4 deletions record_youtube.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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..."
Expand All @@ -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

0 comments on commit 25d1f0d

Please sign in to comment.