suppose you have a playlist that you always use to stream audio content, but at times it gets boring to always listen to the same sequence of songs. what if you wanted your stream to play a commercial after every 2 or so songs? what if you want to shuffle your songs at random every time the last song on the playlist is heard? what is you want the same for your commercials? the wait is over, “playlist manipulator v432.65″ is finally here, for free, for everyone, yadayada
I’ve been playing around with playlists lately. Sometimes I would want to play albums/songs in a non-sequential manner, doing that would be easy I’d just randomize the .m3u file everytime it’s done being played. But I want something more, I thought of fictitious commercials like the ones being played in GTA games (ingame, when you enter a vehicle you can listen to the radio which plays songs and commercials in between not to mention hilarious commentaries from DJs). So yeah, why not play them commercials in between songs like after every 2 or 3 songs. Do them in random too I say.
There’s a lot of ways to accomplish such task, here’s how I did it:
#remove old playlists
rm -f /usr/local/music/staging/*
#create playlist for individual album, just so you have one for future reference/use
#do this manually, copy created playlist(with .m3u extension) in /usr/local/music/playlists folder
#to create a fresh ordered playlist for each album:
#for i in `ls /usr/local/music/albums`;do find /usr/local/music/albums/$i -name *.mp3 \
cat *.m3u |grep -v commercials >$staging/songs.m3u
/usr/local/bin/sort -R $staging/songs.m3u > $staging/random-songs.m3u
/usr/local/bin/sort -R commercials.m3u >$staging/random-commercials.m3u
#in some cases, depending on which distro you’re using, your “sort” command won’t have the
#-R (randomize) option. Just like in my case(centos 5.4). You have 2 options here:
#1) use ezstream -s option to randomize the playlsit
# ezstream -s songs.m3u >random-songs.m3u
#2) download the source for coreutils, compile then install. be sure not to overwrite your rpm
# coreutils’ package binaries unless you know what you’re doing. To do so, just use an install prefix when
# configuring ./configure –prefix=/usr/local
#merge random-commercials.m3u and random-songs.m3u
#such that 1 commercial is played after every 2 songs
}’ $staging/random-songs.m3u $staging/random-commercials.m3u \
#feed the playlist to ezstream, its config file is now set to stream the playlist only once.
$ezstream -c /usr/local/music/ezstream_mp3_conf
The script will loop infinitely, everytime it loops it creates a new randomized list of songs and commercials.
Sample data would be something like below:
/usr/local/music/playlists folder contains individual playlists of various albums, playlist for commercials is also in said folder:
albumA.m3u – is a playlist of albumA
sample lines would be:
albumB.m3u – is a playlist of albumB
commercials.m3u – playlist of commercials
Once randomized and merged, the playlist to be streamed would look similar to this:
The sequence would change everytime the script loops, it loops when ezstream is done playing the current list.