How can I export playlist mp3's into a folder


sparkymark79

Member
Joined
Jun 10, 2009
Messages
185
I have an inkling somebody has asked something similar before.


Is there any program that can take a playlist and output the mp3 files to a seperate directory (maybe even with the playlist file). This would be really handy when creating playlists for running to, as the Pandora is tad too big to attach to my arm :)
 
Quick, dirty and needs some corrections (need my Linux box and a playlist file)



Code:
#!/usr/bin/perl


use warnings;

use srtict;

use File::Copy;


my $file = $ARGV[0];

my $output = $ARGV[1];


open (PLAYLIST "<, $file") or die $!;


while(<PLAYLIST>) {

	copy($_, "$output/$_") unless $_ =~ /^\#/;

}


close PLAYLIST;


Will correct until midnight (in Moscow)


Since m3u is a plain text file it should be super simple to do, and probably such a script already exists.


I also need to see if Pandora's Thunar version supports custom file actions.
 
Last edited by a moderator:
so is it possible to take your code, build some UI for it, and create a PND :D


many thanks by the way
 
It actually wouldn't work the way it is now. I've made some mistakes there, consider it pseudocode.


As for GUI - Pandora comes with zenity preinstalled and Thunar does support custom actions, which means you can make it add "rip m3u to player" as a context menu item for m3u files only and add a 'normal' xfce'ish GUI to it.


I have a couple of questions though. Could you send me a couple of m3u files you typically use?


Do you have your tunes in ~/Music (or /media/mmcblahblah1/music) directiry or they are everywhere?


My music files are all in /home/tartan/Music dir, and my player looks for them there. If I make a playlist with it, it writes relative paths there, i.e. where does it have to go from my Music folder, not from root, to find them.


Sure we can make the script try to guess where the files are or even look for them with locate or something, but I want to make a simple version work first.


I'm not sure PND is necessary for such sort of stupid hack, it's just a script.
 
Here comes the first working prototype, please test.


Extract the archive, drop the file to an SD card, write your music directory instead of mine, then open terminal where it sits and run perl ./ripm3u /path/to/playslist


It would read the m3u playlist (which is basically a text file) and copy all the tracks listed there wherever you'll tell it to without preserving hierarchy (i.e. it will drop them all in one directory, and let God sort them out). At the same time it will create 'playlists' subdir and a playlist with the same name as the one you'll feed him, but the items there will be pointing at 'one directory up and search there'.


Check it out and send feedback.


Script itself:



Code:
#!/usr/bin/perl


# A script which reads an m3u file and copies

# all the tracks elsewhere;

# It also creates in target dir a playlists

# subdir and writes another m3u there, where

# all the tracks are listed with target dir

# as a path to them

#

# Will only work with m3u playlists

#

# Will only work with music files stored in a

# dedicated directory, not all around hdd/sd


use warnings;

use strict;

use File::Copy;


# path to your music directory goes here


our $DIR = "/home/tartan/Music/";


my $playlist = $ARGV[0];

my $dest = `zenity --file-selection --directory`;

chomp $playlist;

chomp $dest;


die unless ($dest && $playlist);


mkdir "$dest/playlists";


open PLMODIFIED, "> $dest/playlists/$playlist";

open PLAYLIST, "< $playlist";


while(<PLAYLIST>) {


	my $f = $DIR . $_;

	chomp $f;

	copy($f, $dest);


	print PLMODIFIED "../";


	# found this beauty here: http://stackoverflow.com/questions/3439123/how-can-i-match-everything-that-is-after-the-last-occurence-of-some-char-in-a-per


	print PLMODIFIED $_ =~/.*\/(.*)/;

	print PLMODIFIED "\n";

}



close PLAYLIST;

close PLMODIFIED;


P.S. m3u explained, to understand what's doable and how: http://en.wikipedia.org/wiki/M3U

ripm3u.zip
 

Attachments

  • ripm3u.zip
    775 bytes · Views: 166
Last edited by a moderator:
just wanted to say sorry I haven't been able to test this yet, I am appreciative. Unfortunately i am getting no time to sit down and check at the moment :angry:
 
I'm pretty sure it works. I'm not so sure if it's a comfortable thing. If yes, it can be 'integrated' in a file manager in no time. And by the way pretty much anything can be done this way, looks a little bit scary but it's a really simple script anyone can write.
 
Back
Top