Saturday, June 28, 2014

Buffering internet radio

Normally, listening to internet radio consists only of sending data from source server. Given number of different situations it can become drawback:

  • requires not interrupted internet connection, otherwise playing will be stopped

  • some player don't handle metadata correctly when submitting it to external services like Last.fm

    • they could not send it at all

    • or send wrong data that contains radio tags and ads

  • when stopped for some period of time you loose current song

It is quite good solution for problems that go together with working in office whilist listening to internet radio.

  • After starting, each downloaded song is saved on disk

  • Ads are filtered out, metadata fixed

  • Fixed file is added to currently played playlist as new track

  • Every played track is then deleted from playlist and disk

  • In case of office meeting, player can be stopped but data will be still downloaded

  • After meeting you can continue listening from position you stopped

  • Then internet connection is down, but it does not bother you, you have playtime reserve from when you were on meeting! :)

Required apps

  • Streamripper - for downloading songs, filtering and metadata fixing

  • Audacious - managing tracklist, playing music

  • Python3 - for running the script managing two above apps, additionally you will need:

Streambuffer script is available for download here.

How it works

Streamripper connects to given internet radio and downloads songs to given directory. When song is completed it is moved do completed directory, Streambuffer will add it as new track in Audacious. When Audacious changes tracklist position to next track, older tracks fill be deleted in playlist and on disk, but only files that are stored in completed directory.

Streambuffer is using inotify for listening to file changes made by Streamripper and for communication with media player d-bus.

Files and Directories
- project dir
\- data
 \- *.* - completed songs
 \- incomplete
  \- *.* - incomplete songs
\- pattern.txt - streamripper filters

Usage

Firstly you have to start media player - Audacious

Then

as python script:

m = Manager("/my/music", "http://itori.animenfo.com:443/")
m.run()

or from commandline:

./rip "/my/music" "http://itori.animenfo.com:443/"