android
  #1  
Old 04-25-2010, 05:35 AM
soyandrice soyandrice is offline
Junior Member
 
Join Date: Nov 2008
Posts: 18
Default Anyone using Linux? Looking for a shell script that'll modify .m3u

UPDATE: Okay, I can confirm that the script for exaile works. However, I would still like someone to confirm if it actually runs and works for other music players ^^

The Idea:
Note: I use Exaile so it can export playlists as .m3u. Problem is, it uses absolute paths, not relative paths. Depending on how the player outputs the .m3u, the second line starting with sed will be different.

Prerequisites:
You'll need the tofrodos package.
Code:
sudo apt-get install tofrodos

Base:

Code:
#!/bin/bash

sed -i 's#'"${HOME}"'/##g; s#''%20''#'' ''#g; s#''/''#''\\''#g' *.m3u 
unix2dos *.m3u

For Exaile (The Script I Use):
Code:
#!/bin/bash

sed -i 's#file://'"${HOME}"'/##g; s#''%20''#'' ''#g; s#''/''#''\\''#g' *.m3u 
unix2dos *.m3u

For Amarok:

Code:
#!/bin/bash

sed -i 's#./Music#Music#g; s#''%20''#'' ''#g; s#''/''#''\\''#g' *.m3u
unix2dos *.m3u
If there's another player (e.g. banshee, rhythmbox) that you want a script for, just post the output and I can try to make one for that player.

How it Works:
This will remove the "/home/USER/" (and whatever is in front, depending on the script) and replace "/" with "\" in front of all the paths in any file with the extension .m3u. This assumes that the .m3u files are in the same directory as this script is located.
The last line should convert the unix line terminations to dos.

Usage:
Depending on the output, copy and paste the code into your favourite, text editor, save it as SansaPlaylistUpdate.sh (or whatever you want to name) into your Home folder.

Make it executable by going through the File Manager, right-clicking it, selecting Properties, going to Permissions, and checking 'Allow executing file as program' (I use Ubuntu so it may be different for other distros).

Or...


Open a terminal, type
Code:
chmod +x SansaPlaylistUpdate.sh
and press enter.

Move SansaPlaylistUpdate.sh into the root directory of your MicroSD. Be sure to export your playlists onto the root directory of you Sansa Clip+ - that way, your playlists and SansaPlaylistUpdate.sh script is in the same folder.

After that, run SansaPlaylistUpdate.sh and the playlists should show and work on the Sansa Clip+.

Last edited by soyandrice; 05-03-2010 at 07:28 PM.
Reply With Quote

Advertisement [Remove Advertisement]

  #2  
Old 04-25-2010, 08:16 AM
Nikolaus Nikolaus is offline
Junior Member
 
Join Date: Aug 2007
Location: Cologne, Germany
Posts: 77
Default

I'll try it later this day, or tomorrow.
Reply With Quote

  #3  
Old 04-25-2010, 11:17 AM
henriquemaia's Avatar
henriquemaia henriquemaia is offline
Junior Member
 
Join Date: Apr 2010
Posts: 47
Default

Quote:
Originally Posted by soyandrice View Post
You'll also need the tofrodos package.
Code:
sudo apt-get tofrodos
Just to point out that you missed the operation install

Code:
sudo apt-get install tofrodos
I'll try to check this later on.
Reply With Quote

  #4  
Old 04-25-2010, 10:16 PM
soyandrice soyandrice is offline
Junior Member
 
Join Date: Nov 2008
Posts: 18
Default

Thanks heriquemaia for fixing my error!

I'm not too sure if the last line will change everything to unix2dos; I haven't been able to test it since I don't have a Sansa Clip+ yet. I'm hoping to get one soon; it's under $30 on amazon again! I already have my 8gb microSD. If this script works, I'll finally have the pleasure of enjoying portable music once more <3
Reply With Quote

  #5  
Old 04-28-2010, 09:58 AM
Nikolaus Nikolaus is offline
Junior Member
 
Join Date: Aug 2007
Location: Cologne, Germany
Posts: 77
Default

The scripts are only changing the "/" to "\" for me.
Reply With Quote

  #6  
Old 04-28-2010, 07:48 PM
soyandrice soyandrice is offline
Junior Member
 
Join Date: Nov 2008
Posts: 18
Default

Quote:
Originally Posted by Nikolaus View Post
The scripts are only changing the "/" to "\" for me.
Did you install tofrodos? It's supposed to convert the UNIX line terminations to DOS (thus the third line of the script).

It worked for me - I had two copies of the .m3u I made in Ubuntu, transfered one to a usb, converted the other, and transferred it to the usb. I plugged the usb into my windows desktop and compared the files. Opening the unmodified version, everything was crammed onto one line. The converted version, however, was formatted just like the one in my Ubuntu laptop. The only difference, however, was the paths that started with "file:///home/USER/Music/...." was "Music/...."

I'm also making the assumption that all your music is stored in a folder called "Music" on the root directory of your external card and contains the same file structure that is under your Music folder in linux.

Also, it's supposed turn "/" into "\." From what I read on the forums, people are saying that the Clip+ won't read "/" that linux uses.

What did your .m3u look like originally? What program are you using?
Reply With Quote

  #7  
Old 05-03-2010, 07:23 PM
soyandrice soyandrice is offline
Junior Member
 
Join Date: Nov 2008
Posts: 18
Default

Alright! I got my Sansa today!!! But my script didn't work...

But I solved the problem! The script doesn't work because of one flaw - exaile outputs spaces as %20.

So normally, a line would look like this from
file:///home/USER/Music/This%20Artist/This%20Album/This%20Song.mp3

The script before would only remove the file:///home/USER/ part and convert / into \, but the %20 remains there.

I'm not sure if this only happens in exaile, but I was able to fix it =D

So the final script (for exaile) is:
Code:
#!/bin/bash

sed -i 's#file://'"${HOME}"'/##g; s#''%20''#'' ''#g; s#''/''#''\\''#g' *.m3u 
unix2dos *.m3u
I'll update the thread late as I have class soon =P
Reply With Quote

  #8  
Old 05-23-2010, 05:42 PM
b27 b27 is offline
Junior Member
 
Join Date: May 2010
Posts: 1
Default

Hi,
you can use the script provided below. It rewrites the paths relative to the location of the m3u and tranlsates all uri escaped characters (i.e. %20)

Scriptname: convExaileM3U.pl
Code:
#!/usr/bin/perl -w
use File::Basename;
use Cwd 'abs_path';
my $filenamei = basename($ARGV[0]);
my $filedir  = dirname($ARGV[0]);
my $filenameo=".tmp.".$filenamei;
open($fhi, "<". $filedir."/".$filenamei);
open($fho, ">". $filedir."/".$filenameo);
my $cwd = abs_path($filedir)."/";
while (<$fhi>)
{
  $_=~s/^file:\/\/$cwd//;
  $_=~s/\%(\X\X)/chr(hex($1))/exg;
  print $fho $_;
}
close($fhi);
close($fho);
rename($filedir."/".$filenameo, $filedir."/".$filenamei);
Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 11:32 AM.