14

I have all my music, unsorted in /home/blah/Music/. It's in random folders, which doesn't matter for me though since Banshee takes care of everything. I have a large playlist containing a good 2/3 of my music. How can I copy all the mp3 files listed in the playlist into a new folder?

Note: I am not trying to export a playlist, but copy the mp3s listed in the playlist.

0

7 Answers 7

15

Found the solution, works with any media player.

  1. Export your playlist to a m3u file. I called it playlist.m3u

  2. Open a terminal in the folder where you have saved the file.

  3. Copy & paste this:

    sed "s/#.*//g" < playlist.m3u | sed "/^$/d" | while read line; do cp "${line}" '/path/to/output/folder/'; done
    

Remember to change the path to your desired output folder.

Note: Terminal will not give any output whilst files are copied, just be patient ;)

2
  • 1
    Awesome! I wish I could +1 it thousand times.
    – Pratyush
    Jul 14, 2012 at 15:55
  • This is the easiest way, if your player Banshee. Thanks!
    – nitin
    Nov 25, 2013 at 8:24
14

I did this with rhythmbox, make a folder on your desktop give it a name. now find the play list you like when the music list shows click on one of the songs and hold ctrl+a high light the hole list now drag and drop it in to the folder on your desktop. this should make copy's of your music. you can also try clementine music player it has some tools to help you export.

http://www.clementine-player.org/

3
  • 4
    +1 This works with Banshee as well.
    – Sabacon
    May 18, 2011 at 17:55
  • 1
    Guess it doesn't get more intuitive. In Banshee you can make smart playlists, this lets you copy exactly what you want. May 19, 2011 at 10:03
  • Thanks, working fine, best that use scripts(I searched many). You are my hero Oct 20, 2017 at 19:50
4

Good question, this is a well needed feature, It is strange how so few media players have it.

Here is a method you can try, it may have limitations in your case especially if your playlist is very large, write a data CD to disk with the files from the playlist save the resulting .iso image where you want and then extract it.

Here are the steps:

  • Select your playlist on the left. Make sure all Artists is selected in the top right pane.

  • select all tracks in playlist in bottom right pane.

  • Right click and click Write CD.

Brasero should start with all the tracks ready to be burned to CD, it will by default want to Write an audio CD, now there will likely be so many tracks that will not possibly fit on an audio CD so the next step is to change the brasero project.

  • Click the project menu in brasero, then select New Data project in the flyout menu.

You will be asked "Do you want to discard the file selection or add it to the new project?"

  • Click the Keep file selection button.

Brasero is now ready to write an Iso image with all your playlist's files to any location you choose.

  • Click the burn button on the bottom right, choose your location and name the iso image, the write process will be fairly fast as no transcoding or normalizing is done.

  • Right click the .iso image and extract it, this will create a folder with the files.

If you wish you can go ahead and just burn the Cd as backup or if you need to give a copy to someone.

See screenshots:

Main Banshee window

Banshee write CD  menu

Banshee write CD menu

Brasero Audio CD project Window

Brasero Audio CD project, Change this to a Data project

Brasero project selection

The Brasero Menus showing how to change project type

Brasero data cd project

The data project that can handle a fair amount of mp3s

0
4

Thanks The Negative Shape for this great solution! I've modified it so that files are renamed according to their position in the playlist.

sed "s/#.*//g" < playlist.m3u | sed "/^$/d" | while read line; do (( COUNTER++ )); filename="${line##*/}"; cp "${line}" "/path/to/output/folder/$COUNTER - $filename"; done
2

I'll also leave my script as it may be useful for somebody. https://gist.github.com/CRImier/9777606

import os
import shutil

directory_name = "playlist/"
playlist_name = "playlist.m3u"

f = open(playlist_name, "r")
files = []
for line in f:
    line = line.strip().strip("\n").strip("\r")
    if line and not line.startswith("#"):
        files.append(line)
dir_contents = os.listdir(directory_name)
for file in files:
    try:
        filename = os.path.basename(file)
        if filename not in dir_contents:
            shutil.copy(file, "playlist/")
            print filename
        else:
            print ".", #File already there
    except Exception as e:
        print str(e)

It's pure Python and doesn't copy songs twice when run multiple times. Hope this helps somebody =)

0

Here is a script I use to copy files from the /home/user/playlist.m3u file into the /home/user/export/ folder as long as your actual files are in /home/user/Music/ if not just change the one line in the script.

#!/bin/bash
m3u=$(sed /#.*/d "/home/user/playlist.m3u"|sed 's/\.\.\/\.\./\/home\/user/g');

echo "$m3u" | while read line; do
    newFile=$(echo $line| sed 's/\/home\/user\/Music\//\/home\/user\/export\//');
    newPath=$(echo "$newFile" | grep -o .*\\/);

    mkdir -p "$newPath";
    cp "$line" "$newFile";  
done;
exit 0;

The difference with dragging banshee entries into a folder is that this script will keep the hierarchy of your /artists/albums/track.mp3 or whatever hierarchy you have to reflect exactly whatever m3u playlist you create. So this way no duplicates possible and every track is in its former place.

I made this because my phone only has MTP and it's a bit hazy under Ubuntu. Plus banshee will synch my android very chaotically. So I almost HAVE to use this to wifi transfer my export folder.

0

I improved the python script given by user: "Арсений Пичугин" so that it preserves the directory structure when copying files to a new location. This allows you to then copy .m3u file and the target music files to a new device, and the links will not be broken, so the playlist will actually PLAY, like on your mp3-player or phone. The script assumes that it is in the top-level folder where the music files are found and where the .m3u file is located.

import os
import shutil

#here, add the name of the dir where the playlist files will be copied
directory_name = "/home/username/Desktop/Music/"
playlist_name = "Test_Favorites.m3u"

f = open(playlist_name, "r")
files = []
for line in f:
    line = line.strip().strip("\n").strip("\r")
    if line and not line.startswith("#"):
        files.append(line)
dir_contents = os.listdir(directory_name)
#print dir_contents
for file in files:
    try:
        filename = os.path.basename(file)
        filepath = os.path.dirname(file)
        newpath = directory_name + "" + filepath
        newname = newpath + "/" + filename
        if os.path.exists(newname):
          print filename + " already existed, not copied."
        else:
          if not os.path.exists(newpath):
            os.makedirs(newpath)
          shutil.copy(file,newpath)
          print newname
    except Exception as e:
        print str(e)

enjoy!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .