How to create an xspf (xml) playlist?

Using applications, configuring, problems
Post Reply
Message
Author
User avatar
willhunt
Posts: 495
Joined: Wed 05 Oct 2005, 18:19

How to create an xspf (xml) playlist?

#1 Post by willhunt »

I was trying to write a bash script that creates xspf playlist from
the current dir it should look like this

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<playlist version="1" xmlns="http://xspf.org/ns/0/">
    <trackList>
        <track><location>file:///mp3s/song_1.mp3</location></track>
        <track><location>file:///mp3s/song_2.mp3</location></track>
        <track><location>file:///mp3s/song_3.mp3</location></track>
    </trackList>
</playlist>
I got this far and am skilless again arghhhhhhh

Code: Select all

#!/bin/bash
# Headers and footers
HDR0='<?xml version="1.0" encoding="UTF-8"?>' 
HDR1='<playlist version="1" xmlns="http://xspf.org/ns/0/">'
HDR2='<trackList>'
FTR0='</trackList>'
FTR1='</playlist>'
ATR1='<track><location>file://'
ATR2='</location></track>'
#write header
echo $HDR0 >/tmp/playlist
echo $HDR1 >>/tmp/playlist
echo $HDR2 >>/tmp/playlist
find . -type f | sed "s/.*\(mp3\|wav\|ogg\)"`'|sort>/tmp/playprep
####Now how do i read /tmp/playprep a line at a time and prefix it
####with ATR1 and suffixing it with ATR or is that the way to go any
####help would be great
#write footer
echo $FTR0 >>/tmp/playlist
echo $FTR1 >>/tmp/playlist
echo $FTR2 >>/tmp/playlist
[url=http://hostfile.org/icepak.pet]176 Icewm Themes :!:[/url]
[url=http://tinyurl.com/39fl3x]vlc-0.8.6c-i586.pet[/url]
[url=http://tinyurl.com/2q7cbp]vlc-0.8.6c-i586.pet[/url]

User avatar
HairyWill
Posts: 2928
Joined: Fri 26 May 2006, 23:29
Location: Southampton, UK

#2 Post by HairyWill »

sed reads one line at a time automatically
does this help

Code: Select all

find /mnt/hda5/music -name "*.mp3" | sed 's/^/START/ ; s/$/END/' >> /tmp/playlist
sed oneliners
http://www.student.northpark.edu/pement ... d1line.txt
Will
contribute: [url=http://www.puppylinux.org]community website[/url], [url=http://tinyurl.com/6c3nm6]screenshots[/url], [url=http://tinyurl.com/6j2gbz]puplets[/url], [url=http://tinyurl.com/57gykn]wiki[/url], [url=http://tinyurl.com/5dgr83]rss[/url]

User avatar
willhunt
Posts: 495
Joined: Wed 05 Oct 2005, 18:19

thanks for most helpful tip!

#3 Post by willhunt »

Thanks thats so close do you know how to get /path/to/file
instead of ./
the link is greatly apperciated 8)
[url=http://hostfile.org/icepak.pet]176 Icewm Themes :!:[/url]
[url=http://tinyurl.com/39fl3x]vlc-0.8.6c-i586.pet[/url]
[url=http://tinyurl.com/2q7cbp]vlc-0.8.6c-i586.pet[/url]

User avatar
HairyWill
Posts: 2928
Joined: Fri 26 May 2006, 23:29
Location: Southampton, UK

#4 Post by HairyWill »

the ./ is a function of how you use find, because I specified a full path I get

Code: Select all

START/mnt/hda5/music/Kings of Leon/Aha Shake Heartbreak/04 Pistol of Fire.mp3END
START/mnt/hda5/music/Kings of Leon/Aha Shake Heartbreak/05 Milk.mp3END
START/mnt/hda5/music/Kings of Leon/Aha Shake Heartbreak/06 The Bucket.mp3END
START/mnt/hda5/music/Kings of Leon/Aha Shake Heartbreak/07 Soft.mp3END
you could use

Code: Select all

find $PWD .......
so that $PWD gets expanded before find is executed.
Will
contribute: [url=http://www.puppylinux.org]community website[/url], [url=http://tinyurl.com/6c3nm6]screenshots[/url], [url=http://tinyurl.com/6j2gbz]puplets[/url], [url=http://tinyurl.com/57gykn]wiki[/url], [url=http://tinyurl.com/5dgr83]rss[/url]

User avatar
willhunt
Posts: 495
Joined: Wed 05 Oct 2005, 18:19

#5 Post by willhunt »

here is the resulting /tmp/playlist after $PWD change anyone have a idea how to add the forward slashes?
<?xml version="1.0" encoding="UTF-8"?>
<playlist version="1" xmlns="http://xspf.org/ns/0/">
<trackList>
<track><location>file:/root/my-documents/lamppost.mp3<location><track>
<track><location>file:/root/my-documents/who53.mp3<location><track>
</trackList>
</playlist>
<?xml version="1.0" encoding="UTF-8"?>
[url=http://hostfile.org/icepak.pet]176 Icewm Themes :!:[/url]
[url=http://tinyurl.com/39fl3x]vlc-0.8.6c-i586.pet[/url]
[url=http://tinyurl.com/2q7cbp]vlc-0.8.6c-i586.pet[/url]

User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#6 Post by MU »

DO NOT USE!
Better example further down!

Code: Select all

#!/bin/bash

SEARCHLOCATION="/root/tests/playlist"

#SEARCHLOCATION="."

# Headers and footers
HDR0='<?xml version="1.0" encoding="UTF-8"?>'
HDR1='<playlist version="1" xmlns="http://xspf.org/ns/0/">'
HDR2='<trackList>'
FTR0='</trackList>'
FTR1='</playlist>'
ATR1='<track><location>file://'
ATR2='</location></track>'
#write header
echo $HDR0 >/tmp/playlist
echo $HDR1 >>/tmp/playlist
echo $HDR2 >>/tmp/playlist
#find . -type f | sed "s/.*\(mp3\|wav\|ogg\)"`'|sort>/tmp/playprep


#FOLDER=`gtkbasic002 -e 'a=xwin_getdir("$SEARCHLOCATION"):print a'`

HERE=`pwd`
cd $SEARCHLOCATION
FOLDER=`pwd`
cd $HERE
find "$FOLDER" -name "*.mp3" | sed 's#^#<track><location>file://# ; s#$#</location></track>#' | sort>> /tmp/playlist


####Now how do i read /tmp/playprep a line at a time and prefix it
####with ATR1 and suffixing it with ATR or is that the way to go any
####help would be great
#write footer
echo $FTR0 >>/tmp/playlist
echo $FTR1 >>/tmp/playlist
echo $FTR2 >>/tmp/playlist 
cheers, Mark
Last edited by MU on Tue 10 Jul 2007, 22:26, edited 2 times in total.

User avatar
willhunt
Posts: 495
Joined: Wed 05 Oct 2005, 18:19

#7 Post by willhunt »

Thanks MU for the help I think there's a glitch somewhere
in the new mod because this is the first time I saw your
post and I've been looking :shock:

Thanks Hairy for letting me reread the link enough to understand :D I really do like to figure it myself when
I can :oops:
final working line is
find $PWD -name "*.mp3" | sed 's/^/<track><location>file:\/\// ; s/$/<\/location><\/track>/' >> /tmp/playlist
[url=http://hostfile.org/icepak.pet]176 Icewm Themes :!:[/url]
[url=http://tinyurl.com/39fl3x]vlc-0.8.6c-i586.pet[/url]
[url=http://tinyurl.com/2q7cbp]vlc-0.8.6c-i586.pet[/url]

User avatar
HairyWill
Posts: 2928
Joined: Fri 26 May 2006, 23:29
Location: Southampton, UK

#8 Post by HairyWill »

There is a good reason why MU has used getdir but I can't remember why a refresher would be great MU.

Also it should be possible to use find $PWD -regex xxxxxx to match all music filteypes but I can't get it to work properly.
Will
contribute: [url=http://www.puppylinux.org]community website[/url], [url=http://tinyurl.com/6c3nm6]screenshots[/url], [url=http://tinyurl.com/6j2gbz]puplets[/url], [url=http://tinyurl.com/57gykn]wiki[/url], [url=http://tinyurl.com/5dgr83]rss[/url]

User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#9 Post by MU »

find . -regex ".*\(mp3\|ogg\)"

xwin_getdir is commented in my example and so not used.
I just took it for tests.
With `pwd` you can get the same results in this case, and so don't need gtkbasic.

Mark

User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#10 Post by MU »

Updated example:

Code: Select all

#!/bin/bash


### comment the line you do not need

#SEARCHLOCATION="/root/tests/playlist"

SEARCHLOCATION="."


FILETYPES='.*\(mp3\|wav\|ogg\)'



# Headers and footers
HDR0='<?xml version="1.0" encoding="UTF-8"?>'
HDR1='<playlist version="1" xmlns="http://xspf.org/ns/0/">'
HDR2='<trackList>'
FTR0='</trackList>'
FTR1='</playlist>'
ATR1='<track><location>file://'
ATR2='</location></track>'
#write header
echo $HDR0 >/tmp/playlist
echo $HDR1 >>/tmp/playlist
echo $HDR2 >>/tmp/playlist

HERE=`pwd`
cd "$SEARCHLOCATION"
FOLDER=`pwd`
cd "$HERE"
find "$FOLDER" -iregex "$FILETYPES" | sed 's#^#<track><location>file://# ; s#$#</location></track>#'|sort >> /tmp/playlist


####Now how do i read /tmp/playprep a line at a time and prefix it
####with ATR1 and suffixing it with ATR or is that the way to go any
####help would be great
#write footer
echo $FTR0 >>/tmp/playlist
echo $FTR1 >>/tmp/playlist
echo $FTR2 >>/tmp/playlist 
Greets, Mark

User avatar
HairyWill
Posts: 2928
Joined: Fri 26 May 2006, 23:29
Location: Southampton, UK

#11 Post by HairyWill »

MU wrote:find . -regex ".*\(mp3\|ogg\)"
Ahhh I missed out the escapes for the brackets thank you.
Will
contribute: [url=http://www.puppylinux.org]community website[/url], [url=http://tinyurl.com/6c3nm6]screenshots[/url], [url=http://tinyurl.com/6j2gbz]puplets[/url], [url=http://tinyurl.com/57gykn]wiki[/url], [url=http://tinyurl.com/5dgr83]rss[/url]

User avatar
willhunt
Posts: 495
Joined: Wed 05 Oct 2005, 18:19

Thanks

#12 Post by willhunt »

wow Idea to working concept in less than 24hrs
and ppl think there's somthing wrong with forum! :shock:
Thanks for all your great help!

now that that part works I've found out I need this also
<title>filename</title> is there a way to add this the
sed line?
i tried but got it wrong again!
<track><location>file:///mp3s/song_1.mp3</location><title>song_1.mp3</title></track>
[url=http://hostfile.org/icepak.pet]176 Icewm Themes :!:[/url]
[url=http://tinyurl.com/39fl3x]vlc-0.8.6c-i586.pet[/url]
[url=http://tinyurl.com/2q7cbp]vlc-0.8.6c-i586.pet[/url]

User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#13 Post by MU »

Code: Select all

find "$FOLDER" -iregex "$FILETYPES" | sed  's#\(.*/\)\(.*\)#<track><location>file://\1\2</location><title>\2</title></location></track># '|sort >> /tmp/playlist
This uses replacements.
\(xxx\)\(yyy\)

the first is placed in the variable \1
the second in \2

Mark

User avatar
willhunt
Posts: 495
Joined: Wed 05 Oct 2005, 18:19

I think I can I think I can.............

#14 Post by willhunt »

that line was the ticket MU :D mission completed!
Thanks for the Help HairyWill and MU the king of sed!
I made a player.html to embed the player in and made
a pet file for anyone who wants to try it

Code: Select all

#!/bin/bash
#/usr/local/sbin/PuppyXspf
## script cut and pasted from the puppylinux forum
## check it out! http://www.murga-linux.com/puppy/viewtopic.php?t=19692
### comment the line you do not need

#SEARCHLOCATION="/root/tests/playlist"

SEARCHLOCATION="."
HERE=`pwd`
cd "$SEARCHLOCATION"
FOLDER=`pwd`
TEZ=$FOLDER
cd "$HERE"
FILETYPES='.*\(mp3\|wav\|ogg\)'

# Headers and footers
HDR0='<?xml version="1.0" encoding="UTF-8"?>'
HDR1='<playlist version="1" xmlns="http://xspf.org/ns/0/">'
HDR2='<trackList>'
FTR0='</trackList></playlist>'
HTH1='<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">'
HTH2='<html><head>'
HTH3='<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">'
HTH4='<title>PuppyXspf</title>'
HTH5='</head><body>'
HTH6='<h3>PuppyXspf Music Player</h3>'
OBJ0='/playlist.xspf"'
OBJ1='<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" id="xspf_player" align="middle" height="170" width="400">'
OBJ2='<param name="allowScriptAccess" value="sameDomain">'
OBJ3='<param name="movie" value="file:///usr/local/xspf/xspf_player.swf?playlist_url=file://'
OBJ4='/playlist.xspf">'
OBJ5='<param name="quality" value="high">'
OBJ6='<param name="bgcolor" value="#e6e6e6">'
EMB0='<embed src="file:///usr/local/xspf/xspf_player.swf?playlist_url=file://'
EMB1='?xn_auth=no;autoload=true" quality="high" bgcolor="#e6e6e6" name="xspf_player" '
EMB2='allowscriptaccess="sameDomain" type="application/x-shockwave-flash "'
EMB3='type="application/x-shockwave-flash"'
EMB4='pluginspage="http://www.macromedia.com/go/getflashplayer" '
EMB5=' align="center" height="168" width="400"> '
EMB6=' </embed></object> '
HT1='<html><head><title>PlayList</title></head><body>'
HB0='</body></html>'
#write playlist header
echo $HDR0 >$FOLDER/playlist.xspf
echo $HDR1 >>$FOLDER/playlist.xspf
echo $HDR2 >>$FOLDER/playlist.xspf
find "$FOLDER" -iregex "$FILETYPES" | sed  's#\(.*/\)\(.*\)#<track><location>file://\1\2</location><title>\2</title></track># '|sort >> $FOLDER/playlist.xspf 
#find "$FOLDER" -iregex "$FILETYPES" | sed 's#^#<track><location>file://# ; s#$#</location></track>#'|sort >> $FOLDER/playlist
#write playlist footer
echo $FTR0 >>$FOLDER/playlist.xspf
#wrie player.html
echo $HTH1 >$FOLDER/player.html
echo $HTH2 >>$FOLDER/player.html
echo $HTH3 >>$FOLDER/player.html
echo $HTH4 >>$FOLDER/player.html
echo $HTH5 >>$FOLDER/player.html
echo $HTH6 >>$FOLDER/player.html
echo $OBJ1 >>$FOLDER/player.html
echo $OBJ2 >>$FOLDER/player.html
echo $OBJ3$TEZ$OBJ4 >>$FOLDER/player.html
echo $OBJ5 >>$FOLDER/player.html
echo $OBJ6 >>$FOLDER/player.html
echo $EMB0$TEZ$OBJ0 >>$FOLDER/player.html
echo $EMB1 >>$FOLDER/player.html
echo $EMB2 >>$FOLDER/player.html
echo $EMB3 >>$FOLDER/player.html
echo $EMB5$EMB6 >>$FOLDER/player.html
echo $HB0 >>$FOLDER/player.html
[url=http://hostfile.org/icepak.pet]176 Icewm Themes :!:[/url]
[url=http://tinyurl.com/39fl3x]vlc-0.8.6c-i586.pet[/url]
[url=http://tinyurl.com/2q7cbp]vlc-0.8.6c-i586.pet[/url]

User avatar
HairyWill
Posts: 2928
Joined: Fri 26 May 2006, 23:29
Location: Southampton, UK

#15 Post by HairyWill »

Works well for me. Not really sure why I'd use it though, did you have a particular usage scenario in mind?
Will
contribute: [url=http://www.puppylinux.org]community website[/url], [url=http://tinyurl.com/6c3nm6]screenshots[/url], [url=http://tinyurl.com/6j2gbz]puplets[/url], [url=http://tinyurl.com/57gykn]wiki[/url], [url=http://tinyurl.com/5dgr83]rss[/url]

User avatar
willhunt
Posts: 495
Joined: Wed 05 Oct 2005, 18:19

#16 Post by willhunt »

well yes I listen to lotsa podcasts and audio books while I surf mozilla
has a sidebar player IF you have the playlist and no way to create
them :( I searched the web and found 0 scripts to acomplish this
now there is one :shock: also by replacing file:// with http:/ and
the location of file:///usr/local/xspf/xspf_player.swf? to
http://your/website/xspf_player.swf? upload the whole dir to your
website rename player.html to index.html,.also it's small size. I have
not had a chance to add all the other file ext it plays but just about
everything.

Still thinking on how to add the album cover
<image>imagefile.jpg</image

For a more professional looking example check out
http://www.hideout.com.br/blog/ or Sherlock Holmes at archive.org the extened player is in the
pet but you could use the button player or slimbar
or FireFox sidepanel
[url=http://hostfile.org/icepak.pet]176 Icewm Themes :!:[/url]
[url=http://tinyurl.com/39fl3x]vlc-0.8.6c-i586.pet[/url]
[url=http://tinyurl.com/2q7cbp]vlc-0.8.6c-i586.pet[/url]

Post Reply