[vlc-devel] How to make relative paths in local xspf playlists work?

Michael A. Puls II shadow2531 at gmail.com
Thu Jul 30 18:06:34 CEST 2009

On Thu, 30 Jul 2009 10:33:24 -0400, Rémi <Denis-Courmont"  
<remi at remlab.net>> wrote:

> Le jeudi 30 juillet 2009 16:24:44 Michael A. Puls II, vous avez écrit :
>> I think that would solve the "psz_base should default to the XSPF  
>> resource
>> location" problem mentioned at
>> <https://trac.videolan.org/vlc/browser/modules/demux/playlist/xspf.c#L562>,
>> which will make relative paths in local xspf files work.
> Not really. Sure, you can get the base URL from the demux_t.psz_path,  
> but you
> still need to implement the algorithm to resolve an absolute URI from a  
> base
> absolute URI and a relative URI... gcc is not going to do it for us.


So, you're saying the full deal is needed like URI parser does it?

However, my original thinking was that for dragging and dropping .xspf  
files onto vlc or using file -> open -> file.xspf, you'd always get an  
absolute path to work with. And, the same would apply for "vlc.exe"  
"absolute path to local playlist.xspf".

"vlc.exe" "relative path to local .xspf file" just still wouldn't work for  
relative location paths in the file, but things would perhaps be improved  
for *some* of the situations.

Right now, I just workaround this by doing:

<playlist xml:base="absolute URI to directory the playlist is in">

and changing that if I move the playlist.

I have an idea of how things should fully work though. I can use Firefox  
to simulate it.

1. Load an xspf file with XHR.

2. Get the textContent of a <location> element.

3. Create an HTMLAnchorElement (with the xspf xml doc as the  

4. Set the anchor element's href to the textContent of the <location>  

5. Append the anchor element to the <location> element.

6. Get the href property of the appended anchor element.

7. Remove the anchor element from the <location> element (as it's not  
needed any more)

The keys there are:

#4 will resolve the URI (absolute or not or expansions etc.) to an  
absolute URI based on the xspf file's path.

#5 will update the resolution to honor all the xml:base attributes in the  
xspf xml document that apply to the <location> element

In short, you end up with absolute URI paths to the files all resolved and  
normalized nicely. Of course, Firefox has a really nice XML parser with a  
nice URI resolver/normalizer.


More information about the vlc-devel mailing list