views:

489

answers:

4
+6  Q: 

Sorting music

So over the years, I've bought music off iTunes, Urge, and Rhapsody and all these files are lying mixed with my non-DRM'd MP3 files that I've ripped off my CDs. Now some of these files have licenses that have expired, and some of them have valid licenses.

I want to sort my music by various DRM/license restrictions that they have on them. This will make it easier for my to delete the music that I don't have subscription to, and all know which files I can carry on which music player.

Does anyone know if this is possible in .NET/Perl/Python i.e. are there any libraries available that will help me do this?

A: 

Do all the files have different extensions? If so this might work (i wrote it all off the top of my head so its not tested):

import os

music_dir = "/home/johnbloggs/music/" # note the forward slashes and the trailing slash
output_dir = "/home/johnbloggs/sorted_music/"

for file in os.listdir(music_dir):
     if file.find(".mp3") != -1:
          if os.path.exists(output_dir + "mp3"):
               os.system("cp " + music_dir + file " " + output_dir + "mp3")

     elif file.find(".wma") != -1:
          if os.path.exists(output_dir + "wma"):
               os.system("cp " + music_dir + file " " + output_dir + "wma")

     # etc

This is written with Linux in mind. If you are looking to actually read the license type from inside the file, that will be considerably more difficult

jeremy
+4  A: 

Wouldn't it be great if DRM made sense like other API's?

Sadly, you'll have to research each DRM scheme and locate a client API for that DRM scheme.

See this article for a proposal to try and cope with the various inane DRM "solutions".

S.Lott
+1  A: 

I have come across this problem too and wrote a python function to fix it; my advice is to cut your losses with the DRM files and just move them out of whatever program you are using for playlists etc. The typical issue is m4p's mixed in with your mp3's and m4a's; whatever your mix this will move all drm'd files into a new folder at C:\drm_music:

import os, shutil

def move_drm_files(music_folder):
    all_songs = []
    good_filetypes = ['mp3', 'm4a', 'ogg', 'flv', 'wma']
    for root, dirs, files in os.walk(music_folder):
        for name in files:
         full_name = os.path.join(root, name)
         all_songs.append(full_name)
    os.mkdir('/drm_music')
    for song in all_songs:
     if song[-3:] not in good_filetypes:
      shutil.move(song, '/drm_music')

So for example you could run the above with python -i move_drm.py (saving the script as move_drm.py) and call move_drm_files('/users/alienfluid/music'), and all the drm'd filetypes would be moved to their own quarantined folder. If you think you can save some of those you could do this to sort the drm files by type:

def sort_drm(drm_folder, all_songs=[]):
    os.mkdir('/drm_collection')
    known_types = []
    for root, dirs, files in os.walk(drm_folder):
     for name in files:
      full_name = os.path.join(root, name)
      all_songs.append(full_name)
    for item in all_songs:
     if item[-3:] not in known_types:
      known_types.append(item[-3:])
    for item in known_types:
     os.mkdir('/drm_collection/'+item)
    for item in all_songs:
     shutil.copy2(item, '/drm_collection/'+item[-3:])

This will create a folder at C:\drm_collection with subfolders named for their extension (m4p etc), and they will be filled with all instances of each type; if you run the first function, you could just save the second one in the same file and call sort_drm('/drm_music')

bvmou
Thanks for the scripts. They look promising. The only problem is that I am not sure if the DRM'd files have different extensions - i.e. is it not possible to introduce DRM restrictions into a WMA file while it is certainly possible to create non-DRM'd WMA files by ripping CDs in WMP?
alienfluid
+5  A: 

If you need to look at the ID3 tags in the MP3 files then there are a few modules on CPAN that may help u (for eg... MP3::Find MP3::Tag )

Also these articles may help....

I think its the AENC tag you might be looking for. http://www.id3.org

/I3az/

draegtun