nr 修订了这个 Gist 1 week ago. 转到此修订
没有任何变更
nr 修订了这个 Gist 1 week ago. 转到此修订
1 file changed, 31 insertions
play-album.sh(文件已创建)
| @@ -0,0 +1,31 @@ | |||
| 1 | + | #!/bin/bash | |
| 2 | + | ||
| 3 | + | set -e | |
| 4 | + | ||
| 5 | + | function play_album { | |
| 6 | + | local album_path="$1" | |
| 7 | + | [ -z "$album_path" ] && album_path="CrystalCastles/CrystalCastlesI" | |
| 8 | + | ||
| 9 | + | local song_names= | |
| 10 | + | #mapfile -t song_names < <( \ | |
| 11 | + | # ./media.sh "music/${album_path}" | grep --color=never -Eo '[^ ]+\.mp3$' \ | |
| 12 | + | #) | |
| 13 | + | mapfile -t song_names < <( \ | |
| 14 | + | ./media.sh "music/${album_path}" | tail -n+4 | cut -d' ' -f3- \ | |
| 15 | + | ) | |
| 16 | + | ||
| 17 | + | for song_name in "${song_names[@]}"; do | |
| 18 | + | echo "Playing: ${song_name}" | |
| 19 | + | ./media.sh "music/${album_path}/${song_name}" | mpv --quiet - | |
| 20 | + | done | |
| 21 | + | } | |
| 22 | + | ||
| 23 | + | function main { | |
| 24 | + | while [ $# -gt 0 ]; do | |
| 25 | + | echo "Playing album: $1" | |
| 26 | + | play_album "$1" | |
| 27 | + | shift | |
| 28 | + | done | |
| 29 | + | } | |
| 30 | + | ||
| 31 | + | main "$@" | |
nr 修订了这个 Gist 1 week ago. 转到此修订
1 file changed, 36 insertions
media.sh(文件已创建)
| @@ -0,0 +1,36 @@ | |||
| 1 | + | #!/bin/bash | |
| 2 | + | ||
| 3 | + | set -e | |
| 4 | + | ||
| 5 | + | PW= | |
| 6 | + | PW_FILE="${HOME}/.mediapw" | |
| 7 | + | BASE_URL="https://fs.noahro.at" | |
| 8 | + | ||
| 9 | + | function get_pw { | |
| 10 | + | cat "$PW_FILE" | |
| 11 | + | } | |
| 12 | + | ||
| 13 | + | function main { | |
| 14 | + | PW="$( get_pw )" | |
| 15 | + | ||
| 16 | + | local path="$1" | |
| 17 | + | fetch "$path" | |
| 18 | + | } | |
| 19 | + | ||
| 20 | + | function fetch { | |
| 21 | + | local path="$( pathencode "$1" )" | |
| 22 | + | #local path="$1" | |
| 23 | + | curl -s "${BASE_URL}/${path}?pw=${PW}&t" | |
| 24 | + | ||
| 25 | + | #--expand-url \ | |
| 26 | + | #--variable %path --variable %PW \ | |
| 27 | + | } | |
| 28 | + | ||
| 29 | + | function pathencode { | |
| 30 | + | #jq --slurp --raw-input --raw-output @uri <<<"$@" | |
| 31 | + | ||
| 32 | + | sed -E 's/ /%20/g' <<<"$@" | \ | |
| 33 | + | sed -E 's/,/%2C/g' | |
| 34 | + | } | |
| 35 | + | ||
| 36 | + | main "$@" | |