Reply
Thread Tools
Posts: 29 | Thanked: 2 times | Joined on Feb 2007
#1
Here are couple of scripts to create a random playlist of music-only tracks. I include them here for anyone that wants to have a go at doing the same.

My favourite media player is Canola but it still doesn't differentiate between "spoken audio" and "music audio". Some days I like to listen to podasts or audio books and some days I like to play all of my music at random. However, when I currently use Canola to play at random all the audio files are mixed together and I have about 1000 music files and almost the same number of audio book files, so the built-in random play feature of Canola is not ideal.

The script doesn't apply just to the Canola media player as it simply creates a playlist of shuffled music files so should work with any media player that can read playlists.

Here are the scripts:

createPlaylist.sh
Code:
#!/bin/sh

MUSIC1="/media/mmc1/audio/music"
MUSIC2="/media/mmc2/audio/music"
PLAYLIST="allMusicShuffled.m3u"
SCRIPTS="/media/mmc2/scripts/playlists"

find ${MUSIC1}|egrep -i ".mp3$|.wma$|.ogg$" > ${MUSIC1}/allMusic1.m3u
find ${MUSIC2}|egrep -i ".mp3$|.wma$|.ogg$" > ${MUSIC1}/allMusic2.m3u

TOTAL1=`cat ${MUSIC1}/allMusic1.m3u|wc -l`
TOTAL2=`cat ${MUSIC1}/allMusic2.m3u|wc -l`

echo "found ${TOTAL1} songs in ${MUSIC1}"
echo "found ${TOTAL2} songs in ${MUSIC2}"

cat ${MUSIC1}/allMusic1.m3u > ${MUSIC1}/allMusic.m3u
cat ${MUSIC1}/allMusic2.m3u >> ${MUSIC1}/allMusic.m3u

echo "writing shuffled playlist to : ${MUSIC1}/${PLAYLIST}"
cat ${MUSIC1}/allMusic.m3u|perl ${SCRIPTS}/shuffle.pl > ${MUSIC1}/${PLAYLIST}
rm ${MUSIC1}/allMusic.m3u
rm ${MUSIC1}/allMusic1.m3u
rm ${MUSIC1}/allMusic2.m3u

echo "done"
shuffle.pl
Code:
#!/usr/bin/perl

use List::Util 'shuffle';

my @list=<STDIN>;

@shuffled = shuffle(@list);
foreach(@shuffled) {
   print $_;
}
Here's a few tips/caveats:
o The scripts should be saved to the folder:
/media/mmc2/scripts/playlists/
o run the following to allow the scripts to be executable:
cd /media/mmc2/scripts/playlists/;chmod 755 *
o the following directories should exist and contain your music-only files:
/media/mmc1/audio/music/
/media/mmc2/audio/music/
o I like to keep my files in the following structure across both SD cards to keep the types of audio separate:
/media/mmcX/audio/music/artist/album/
/media/mmcX/audio/spokenWord
/media/mmcX/audio/podcasts
The above structure is not required though as long as only the music files are contained in the /media/mmcX/audio/music directory and/or sub-directories
o to run from xterm, use the following command (note the sh is required as the script is being run from the SD card):
sh /media/mmc2/scripts/playlists/createPlaylist.sh

Rather than use xterm, a better way to launch it though is via "Personal Launcher" (http://maemo.org/downloads/product/O...rsonal-launch/) or "kerez" (http://maemo.org/downloads/product/OS2007/kerez/).

Once run, the output is:
found XXXX songs in /media/mmc1/audio/music
found XXXX songs in /media/mmc2/audio/music
writing shuffled playlist to :
/media/mmc1/audio/music/allMusicShuffled.m3u
done

An extra tip for Canola users is that if you run the script and then close and re-open Canola the change will be picked up. Then go to your playlists in Canola and you will find the playlist "allMusicShuffled".
 
Reply


 
Forum Jump


All times are GMT. The time now is 07:51.