Skip to content

Instantly share code, notes, and snippets.

@ggorlen
Last active February 27, 2024 19:31
Show Gist options
  • Save ggorlen/73febb5876d9204a6dcde3cfa89746cb to your computer and use it in GitHub Desktop.
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

Bandcamp

Single album

mpv -no-vid https://robertturman.bandcamp.com/album/chapter-eleven-1976-1987

(or add multiple URLs to build a playlist)

Artist

mpv -no-vid https://takusugimoto.bandcamp.com

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=-

YouTube

Basic usage

mpv -no-vid https://en.wikipedia.org/wiki/YouTube
cat playlist.txt | xargs mpv -no-vid

# or
mpv -no-vid $(cat playlist.txt)

Stream YouTube videos from URLs on a website

mpv -no-vid https://en.wikipedia.org/wiki/YouTube

Although I get an occasional [ytdl_hook] ERROR: No video formats found error for certain videos.

Stream a YT playlist from Discogs

mpv -no-vid https://www.discogs.com/master/50617-Wire-Chairs-Missing

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