Rockbox Technical Forums

Third Party => Other Utilities => Topic started by: Neongrau on March 10, 2013, 09:26:15 AM

Title: turn m3u into playlist with relative adjusted path
Post by: Neongrau on March 10, 2013, 09:26:15 AM
hi there, can anyone recommend a plugin for foobar2000 or a sepparate tool, which will do this job? right now i still have to edit each playlist manually.
Title: Re: turn m3u into playlist with relative adjusted path
Post by: saratoga on March 10, 2013, 12:14:59 PM
If a path doesn't exist Rockbox treats it as a relative path so you shouldn't need to edit them. What are you trying to do?
Title: Re: turn m3u into playlist with relative adjusted path
Post by: Neongrau on March 10, 2013, 12:39:20 PM
ok maybe i should explain further... i create playlists with foobar on my pc library and sync later (msc) with my fuze. that is why i am looking for  a way to save playlists in foobar directly with relative adjusted paths.
Title: Re: turn m3u into playlist with relative adjusted path
Post by: saratoga on March 10, 2013, 12:53:02 PM
What do you mean by adjusted?
Title: Re: turn m3u into playlist with relative adjusted path
Post by: Neongrau on March 10, 2013, 01:15:40 PM
maybe a foobar plugin exists that automatically adjust the path when saving m3u

hd:\folder\folder\music\

to

..\music
Title: Re: turn m3u into playlist with relative adjusted path
Post by: bluebrother on March 10, 2013, 02:18:32 PM
You should ask the foobar people then.
Title: Re: turn m3u into playlist with relative adjusted path
Post by: saratoga on March 10, 2013, 02:31:28 PM
If you just put the playlist in some folder below the one with the files it should work even without relative paths.
Title: Re: turn m3u into playlist with relative adjusted path
Post by: Neongrau on March 11, 2013, 05:27:07 AM
You should ask the foobar people then.
yes, but i thought my chances are not bad either asking over here first ;)

If you just put the playlist in some folder below the one with the files it should work even without relative paths.
well i tried what you suggested and it works for foobar, but the fuze wont play them. the path starts missing the initial ..\ infront.

i read somwhere that creating relative m3us with this structure is possible with mp3tag, but have to check further.

hard to believe there is no tool that will create relative m3us or correct the path later.
Title: Re: turn m3u into playlist with relative adjusted path
Post by: bluebrother on March 11, 2013, 03:05:38 PM
hard to believe there is no tool that will create relative m3us or correct the path later.

Shouldn't be hard to write a converter to change path names in a couple of lines of Python code. Or a similar scripting language.
Title: Re: turn m3u into playlist with relative adjusted path
Post by: Crafty on March 11, 2013, 03:58:20 PM

Quote
hard to believe there is no tool that will create relative m3us or correct the path later.
I've use win's Notepad editor Find & Replace funtion for m3u's. 
Title: Re: turn m3u into playlist with relative adjusted path
Post by: Neongrau on March 12, 2013, 04:04:08 AM
Shouldn't be hard to write a converter to change path names in a couple of lines of Python code. Or a similar scripting language.
yes and i wish i could write such a code..

I've use win's Notepad editor Find & Replace funtion for m3u's. 
sure, i should have better written automatically. does there exist an editor where you can define a path (and save it) so just to hit ''find & replace''?
Title: Re: turn m3u into playlist with relative adjusted path
Post by: Crafty on March 12, 2013, 05:10:28 AM
Quote
sure, i should have better written automatically. does there exist an editor where you can define a path (and save it) so just to hit ''find & replace''?

The windows Notepad editor has a funtion called "Replace" under the edit tab.
The prompt is:
Find what:  E:\My music\
Replace with: /microSD1/

then press [Replace All] 
be safe...make backups

before:
E:\tunes\U2\Unknown\Spanish Eyes.mp3
E:\tunes\Van Halen\Live Right Here, Right Now (Disc One)\05 Ain't Talkin' 'Bout Love.mp3
E:\tunes\Van Halen\Live Right Here, Right Now (Disk Two)\11 Top Of The World.mp3
E:\tunes\Van Halen\Live Right Here, Right Now (Disc One)\02 Judgement Day.mp3
E:\tunes\Ozzy Osbourne\Untitled\Ozzy Shot In The Dark.mp3
E:\tunes\Ozzy Osbourne\Bark At The Moon\01 Bark At The Moon.mp3

after:
/microSD1/U2\Unknown\Spanish Eyes.mp3
/microSD1/Van Halen\Live Right Here, Right Now (Disc One)\05 Ain't Talkin' 'Bout Love.mp3
/microSD1/Van Halen\Live Right Here, Right Now (Disk Two)\11 Top Of The World.mp3
/microSD1/Van Halen\Live Right Here, Right Now (Disc One)\02 Judgement Day.mp3
/microSD1/Ozzy Osbourne\Untitled\Ozzy Shot In The Dark.mp3
/microSD1/Ozzy Osbourne\Bark At The Moon\01 Bark At The Moon.mp3

Title: Re: turn m3u into playlist with relative adjusted path
Post by: Neongrau on March 12, 2013, 06:26:20 AM
that is what i do already.

i am talking about something similar like burrrn cueditor. there you can define a replace code. in the future all you have to do is hit a button. i found out that it works also with m3us, but it is very slow.
Title: Re: turn m3u into playlist with relative adjusted path
Post by: bluebrother on March 12, 2013, 03:53:24 PM
yes and i wish i could write such a code..

The following Python code can do it. It's rather simple (fails on the first line if the file contains a BOM and doesn't do error handling, but that shouldn't be much of a problem).

Code: [Select]
import sys
import os

infile = sys.argv[1]
basepath = os.path.dirname(os.path.abspath(infile))

outlines = []
fp = open(infile)
for line in fp.readlines():
    if line.startswith('#'):  # m3u comments start with #
        outlines.append(line)
    else:
        outlines.append(os.path.relpath(line, basepath))
fp.close()

fp = open(infile, "w")
for line in outlines:
    fp.write(line)
fp.close()

To use it: save it in a file on your PC, install Python, run it with Python and pass the name of the m3u file you want to get converted as argument. It will make all paths relative to the location of the m3u. If you have the file associations for Python scripts properly set you should be able to simply drop the m3u file on the script and it will do the conversion.

Also, foobar2000 will save m3u files with relative paths as long as you save them in the same or a parent folder of the files it contains -- i.e. if you have a folder /music/artist1/album1 and your playlist contains files in that folder you'll get relative paths in the m3u if you save it in /music, /music/artist1 or /music/artist1/album1. You get absolute paths if you save it in a location like /music/someotherfolder.
Title: Re: turn m3u into playlist with relative adjusted path
Post by: Neongrau on March 13, 2013, 04:55:09 AM
vielen dank bluebrother ;) i will check it out.

concerning foobar and relative m3us, have a look at my post above. it works for foobar, but the initial ..\  is missing, and rockbox wont load them.

music\..\%artist% - %title%

is this the only path that rockbox will accept in a m3u, or am i missing something?

..\music\..\%artist% - %title%
Title: Re: turn m3u into playlist with relative adjusted path
Post by: bluebrother on March 18, 2013, 03:41:09 AM
concerning foobar and relative m3us, have a look at my post above. it works for foobar, but the initial ..\  is missing, and rockbox wont load them.

This sounds like you're moving the playlist file around after saving it. Or how did you manage to produce this kind of files? It works fine for me.
Title: Re: turn m3u into playlist with relative adjusted path
Post by: Neongrau on March 20, 2013, 12:02:26 PM
It works fine for me.

a quick question, foobar does not create the ..\ within your m3us either, is that right?
Title: Re: turn m3u into playlist with relative adjusted path
Post by: Neongrau on March 21, 2013, 04:47:37 AM
nevermind, i saved once more to the music folder and got it working, thank you very much.