Sort music

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

I want to sort music by the various DRM / license restrictions that they have on them. This will make it easier to delete music that I don’t have a subscription to, and everyone knows which files I can use to play the music player.

Does anyone know if this is possible in .NET / Perl / Python? Are there any libraries available to help me do this?

+5
source share
4

python ; - DRM , .. , m4p mp3 m4a; , drm'd 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')

, , python -i move_drm.py ( script move_drm.py) move_drm_files('/users/alienfluid/music'), drm'd . , , , drm :

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:])

C:\drm_collection , (m4p ..), ; , sort_drm('/drm_music')

+1

, DRM , API?

, DRM API DRM.

. DRAM inane.

+4
source

Do all files have different extensions? If so, then this may work (I wrote all this from the top of my head so that it would not be 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

It is written with Linux in mind. If you really want to read the license type from within the file, it will be much more difficult.

0
source

All Articles