LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 07-06-2009, 12:03 PM   #1
wademac
Member
 
Registered: Apr 2008
Posts: 37

Rep: Reputation: 15
build a playlist with a script :)


Hello All,

I would like to build a playlist of over 500 songs but I dont see anything online that will construct this with a program the playlist format is xspf for jw flash player.

format of the song are:

Band - Album - 01 - Song1.mp3
Band - Album - 02 - Song2.mp3
Other Band - Other Album - 01 - Other Song.mp3
Other Band - Other Album - 02 - Other Song two.mp3
etc..

File layout for the playlist is

<playlist version="1" xmlns="http://xspf.org/ns/0/">
<title>playlist</title>
<tracklist>

<track>
<title>SONG</title>
<annotation>BAND</annotation>
<location>FILE</location>
</track>

</tracklist>
</playlist>


so if I had a script that could basically rip apart the list of songs and build this playlist that would be grand!
 
Old 07-06-2009, 12:50 PM   #2
rn_
Member
 
Registered: Jun 2009
Location: Orlando, FL, USA
Distribution: Suse, Redhat
Posts: 127
Blog Entries: 1

Rep: Reputation: 25
here's a small shell script that might help. this can probably be done more elegantly in perl; too bad i don't like perl that much ; but perhaps someone else on the list might be able to help.

place this script in a file (mkplaylist.sh for example; and remember to 'chmod +x' it). you'll have to edit it to provide the path to your mp3 files or you can make that a command-line parameter that you pass to the script.

HTH.
-RN.

<code>

echo "<playlist version=\"1\" xmlns=\"http://xspf.org/ns/0/\">"
echo "<title>playlist</title>"
echo "<tracklist>"
find /path/to/mp3files -type f | while read line
do
FN=`basename "$line"`
SONG=`echo $FN | cut -d- -f4 | sed 's/ //g;s/.mp3//'`
BAND=`echo $FN | cut -d- -f1 | sed 's/ //g'`
echo "<track>"
echo "<title>$SONG</title>"
echo "<annotation>$BAND</annotation>"
echo "<location>$line</location>"
echo "</track>"
done
echo "</tracklist>"
echo "</playlist>"

</code>
 
Old 07-06-2009, 01:10 PM   #3
sarin
Member
 
Registered: May 2001
Location: India, Kerala, Thrissur
Distribution: FC 7-10
Posts: 354
Blog Entries: 2

Rep: Reputation: 34
Well, it will be difficult to do it without knowing the exact delimiter and which field corresponds to which. Anyway, my already weak perl scripting skills were getting rusty. So I decided to try it.

<Warning> This is a 10 minutes script and might have errors</warning>

Assumed that your file names are present in list.txt

Code:
#!/usr/bin/perl

open FILE, "<", "list.txt" or die;

print "<playlist version=\"1\" xmlns=\"http://xspf.org/ns/0/\">
<title>playlist</title>
<tracklist>
";

while(<FILE>) {
	chomp;
	@info=split(/-/);
	$num=@info;
	if ( $num == 3 ) {
		print "<track>\n<title>@info[2]</title>\n<annotation>$info[0]</annotation>\n<location>$_</location>\n</track>";
	}
	if ( $num == 4 ) {
		print "<track>\n<title>@info[3]</title>\n<annotation>$info[0]</annotation>\n<location>$_</location>\n</track>";
	}
}

print "
</tracklist>
</playlist>";

Last edited by sarin; 07-06-2009 at 01:13 PM. Reason: line wrap was not set in vi while copying the code
 
Old 07-06-2009, 01:59 PM   #4
wademac
Member
 
Registered: Apr 2008
Posts: 37

Original Poster
Rep: Reputation: 15
tried the perl script and got:

/mkplaylist2.sh: line 3: open: command not found
./mkplaylist2.sh: line 8: print: command not found
./mkplaylist2.sh: line 10: syntax error near unexpected token `)'
./mkplaylist2.sh: line 10: `while(<FILE>) {'
 
Old 07-06-2009, 06:27 PM   #5
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,261

Rep: Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028
Sounds like you tried to run a perl script as a shell script, hence the syntax errors.

Given his script above, just check where your perl is installed and adjust the

#!/usr/bin/perl

line as needed.

Save it as mkplaylist.pl and run as ./mkplaylist.pl (assuming rx perms)
 
Old 07-06-2009, 06:50 PM   #6
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
Look in the bash info manual section on HERE documents.

You could have in a loop something like:
Code:
cat >>playlist <<EOP
<track>
   <title>$SONG</title>
   <annotation>$BAND</annotation>
   <location>$FILE</location>
</track>
EOP
 
Old 07-07-2009, 06:50 AM   #7
wademac
Member
 
Registered: Apr 2008
Posts: 37

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by chrism01 View Post
Sounds like you tried to run a perl script as a shell script, hence the syntax errors.

Given his script above, just check where your perl is installed and adjust the

#!/usr/bin/perl

line as needed.

Save it as mkplaylist.pl and run as ./mkplaylist.pl (assuming rx perms)
I had a space at the first of my perl line of code DUH!

Worked fine after
 
Old 07-14-2009, 01:48 PM   #8
wademac
Member
 
Registered: Apr 2008
Posts: 37

Original Poster
Rep: Reputation: 15
Thanks GUYS (gals) for the help you made this happen for me! ROCK AND ROLLA
 
  


Reply

Tags
player, playlist


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
script for compiling a playlist sthompson Linux - Server 8 06-05-2008 06:34 PM
Build a local playlist to play remote audio files (through HTTP) BillyGalbreath Linux - Software 1 11-01-2006 11:25 PM
mplayer playlist or script help gotcha Linux - Software 0 09-02-2004 08:08 AM
A Program/script making a html playlist? Trinity22 Linux - Software 4 04-13-2004 09:29 PM
Automating a playlist using shell script... DesiLILO Linux - Newbie 4 04-02-2004 11:03 PM


All times are GMT -5. The time now is 12:05 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration