diff options
Diffstat (limited to 'dot/local/bin/musopen')
-rwxr-xr-x | dot/local/bin/musopen | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/dot/local/bin/musopen b/dot/local/bin/musopen index 3ed9962..7d007fb 100755 --- a/dot/local/bin/musopen +++ b/dot/local/bin/musopen | |||
@@ -1,5 +1,26 @@ | |||
1 | #!/bin/sh | 1 | #!/bin/sh |
2 | 2 | ||
3 | usage() | ||
4 | { | ||
5 | cat <<EOF | ||
6 | Usage: $0 [-h|--help] [-n|--no-save] [-s|--save] | ||
7 | EOF | ||
8 | } | ||
9 | |||
10 | DO_SAVE=y | ||
11 | |||
12 | eval set -- "$(getopt -o 'hsn' --long '-help,-save,-no-save' -n 'musopen' -- "$@")" || exit 1 | ||
13 | while true; do | ||
14 | case "$1" in | ||
15 | -h|--help) usage; exit ;; | ||
16 | -s|--save) DO_SAVE=y ;; | ||
17 | -n|--no-save) DO_SAVE= ;; | ||
18 | --) shift; break ;; | ||
19 | *) usage; exit 1 ;; | ||
20 | esac | ||
21 | shift | ||
22 | done | ||
23 | |||
3 | URL=https://radio.musopen.org/v1/pieces/get_current/streamvbr0 | 24 | URL=https://radio.musopen.org/v1/pieces/get_current/streamvbr0 |
4 | JSON=$(curl -s "$URL") | 25 | JSON=$(curl -s "$URL") |
5 | URL_FMT='https://live.musopen.org/music/vbr0/%s' | 26 | URL_FMT='https://live.musopen.org/music/vbr0/%s' |
@@ -14,7 +35,14 @@ title=$(j .title) | |||
14 | 35 | ||
15 | STREAM_URL=$(printf "$URL_FMT" "$filename") | 36 | STREAM_URL=$(printf "$URL_FMT" "$filename") |
16 | 37 | ||
17 | CAPTURE_NAME= | 38 | CAPTURE_NAME="$composer - $title.${filename##*.}" |
18 | [ "$CAPTURE" ] && CAPTURE_NAME="$composer - $title.${filename##*.}" | 39 | |
40 | if [ "$DO_SAVE" -a -e "$CAPTURE_NAME" ]; then | ||
41 | echo "Warning: not saving: file exists: $CAPTURE_NAME" >&2 | ||
42 | DO_SAVE= | ||
43 | else | ||
44 | printf '%s: %s - %s\n' "${DO_SAVE+Saving}${DO_SAVE-Playing}" "$composer" "$title" >&2 | ||
45 | fi | ||
46 | |||
19 | 47 | ||
20 | exec mpv "$STREAM_URL" ${CAPTURE_NAME+ --stream-capture="$CAPTURE_NAME"} | 48 | exec mpv "$STREAM_URL" ${DO_SAVE+ --stream-capture="$CAPTURE_NAME"} |