schollz / streammyaudio

Easily stream audio from any computer to the internet.
https://streammyaudio.com
GNU General Public License v3.0
75 stars 9 forks source link

Made a neat audio station script! #2

Closed SuperSonicHub1 closed 2 years ago

SuperSonicHub1 commented 2 years ago

Made a neat little script with yt-dlp in order to stream the entirety of what the program considers a "playlist" (YouTube playlist, Bandcamp album, etc.)

#!/bin/bash

yt-dlp-to-ffconcat() {
    local url=$1
    yt-dlp --format bestaudio --get-url "$url" | sed -e "s/^/file '/" | sed -e "s/$/'/"
}

main() {
    local url=$1
    local station=$2
    ffmpeg -protocol_whitelist file,http,https,tcp,tls,crypto \
        -f concat -safe 0 -i <(yt-dlp-to-ffconcat "$url") \
        -f mp3 -ar 44100 -b:a 256k - | \
        cstream -t 64k | \
        curl -s -k -H "Transfer-Encoding: chunked" -X POST -T -  \
        "https://streammyaudio.com/$station.mp3?stream=true&advertise=true"
}

main "$@"

You can then make this script executable and use it like this:

./stream-playlist.bash "https://www.youtube.com/playlist?list=PL2D4C428C2C10BCFF" vgm

This is pretty awesome as it allows you to stream a lot of content and not have to download it to your PC! You can throw shuf into the mix as well with a big playlist and have music to listen to with your buds for hours!

If I feel like it, I might convert this into a Python script and use aiohttp to send a message about the currently playing song into chat. Perhaps I could even take requests via commands as well.

If you're awake when I create this issue, you can listen to the Street Fighter 3 soundtrack on the vgm station. This feels especially appropriate seeing as you made a blog post about drum and bass the other day.

schollz commented 2 years ago

Hey @SuperSonicHub1 that's one of the neatest little scripts I've seen in a long time!!

I had made something on a similar vein to playback files on my own computer

another script ```bash find ~/Music/ | grep 'wav\|mp3\|flac' | shuf | sed -e "s/^/file '/" | \ sed -e "s/$/'/" > /tmp/playlist.txt && \ ffmpeg -f concat -safe 0 -i /tmp/playlist.txt -f mp3 -ar 44100 -b:a 256k - | \ cstream -t 32k | \ curl -s -k -H "Transfer-Encoding: chunked" -X POST -T - \ "https://streammyaudio,com/YOURSTATIONNAME.mp3?stream=true&advertise=true" ```

but yours is next level!! its like remixing the internet and streaming it back through the internet! love it. Would you like to PR your script? You could add it right here as an example of how to stream playlists! Or if you don't mind, I could add it and attribute you :)

In any case, very cool scriptfu and awesome station

SuperSonicHub1 commented 2 years ago

I'd be happy to add it!

SuperSonicHub1 commented 2 years ago

Just sent my pull! #3

marclundgren commented 2 years ago

@SuperSonicHub1 I can't seem to get cstream installed on a mac. tried pip3 install cstream, python3 -m pip install -U cstream.

Everytime I try to run this script I get cstream command not found. Any tips?

SuperSonicHub1 commented 2 years ago

@marclundgren cstream is written in C. cstream doesn't look to be on Homebrew, so you'll need to compile it yourself.

blogdemoi commented 2 years ago

Thank you, just compiled cstream on Manjaro to use your script, very nice.

SuperSonicHub1 commented 2 years ago

@blogdemoi Glad to hear it! :)