Skip to content

Instantly share code, notes, and snippets.

@ggorlen
Last active February 28, 2025 02:30
Show Gist options
  • Select an option

  • Save ggorlen/73febb5876d9204a6dcde3cfa89746cb to your computer and use it in GitHub Desktop.

Select an option

Save ggorlen/73febb5876d9204a6dcde3cfa89746cb to your computer and use it in GitHub Desktop.
Streaming web audio on the command line

Web audio on the command line

Install mpv and ytdlp

MPV can play most URLs

mpv -no-vid https://www.youtube.com/watch?v=jJxRjWtwmEE # single YT video
mpv -no-vid https://www.discogs.com/master/50617-Wire-Chairs-Missing # webpage with videos
mpv -no-vid https://robertturman.bandcamp.com/album/chapter-eleven-1976-1987 # bandcamp album
mpv -no-vid https://takusugimoto.bandcamp.com/music # bandcamp artist
mpv -msg-level=all=no -no-vid https://archive.org/details/kiyoshi-mizutani--yokosawairi # archive.org audio

Append multiple URLs to the args to play them all, or keep a playlist in a file:

mpv -no-vid -playlist=playlist.txt

Bandcamp Collection

(seems to be broken at the moment; need to update)

TODO: make it possible to play entire collection

curl -sS "https://bandcamp.com/ggorlen" \
| xmllint --html --xpath '//*[@id="pagedata"]/@data-blob' 2>/dev/null - \
| sed 's/^ data-blob=\"\|\"$//g' \
| perl -MHTML::Entities -pe 'decode_entities($_);' \
| jq '{fan_id: .fan_data.fan_id, older_than_token: .wishlist_data.last_token, count: 10}' \
| curl -sS -X POST -H "Content-Type: Application/JSON" \
  --data-binary "@-" https://bandcamp.com/api/fancollection/1/collection_items \
| jq -r .items[].item_url \
| xargs curl -sS \
| xmllint --html --xpath '//script[@data-tralbum]/@data-tralbum' 2>/dev/null - \
| sed 's/^ data-tralbum=\"\|\"$//g' \
| perl -MHTML::Entities -pe 'decode_entities($_);' \
| jq -r '.trackinfo[].file."mp3-128"' \
| mpv -no-video --playlist=-

MP3s

Stream MP3s on a website

url="https://www.microsound.org/projects/bufferFuct/"
curl -A "Mozilla/8.0" -sS $url \
| xmllint --html --xpath '//a[substring(@href, string-length(@href) - string-length(".mp3") + 1) = ".mp3"]/@href' - \
| sed 's/^ href="\|"$//g' \
| mpv -no-video --playlist=-

Download all mp3s from a website

wget -r -l1 -H -nd -A mp3 -e robots=off http://www.microsound.org/projects/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment