Unfortunately, ITune’s “Consolidate” feature did not work on my 2nd generation iPod. Therefore, after having failed to find a free program to extract songs from my originally Windows formatted iPod, I wrote this quick script that would extract my songs and organize them based on ID3 tags. For this script to work, you need to also install the ID3 module for Python. Now I must warn you that you do need some python knowledge to use this script.
# #########################################
# arguments:
# r : the resource directory
# d : the destination directory to save the extracted songs to.
# #########################################
import sys, getopt, os, shutil
from ID3 import *
def getUntitledID(d, str):
untitre = 1
while os.path.isfile(os.path.join(d,("%s %d.mp3" % (str,untitre)))):
untitre = untitre + 1
return "%s %d" % (str,untitre)
def processFile(r,f,d,t):
if f[-3:] != "mp3":
return
print t + "> " + f
ids = ID3(os.path.join(r,f))
art = ids.artist.strip().replace("/", "").replace("\\","")
if art == "":
art = "Various Artist"
try:
if not os.path.isdir(os.path.join(d,art)):
os.mkdir(os.path.join(d,art))
except TypeError, message:
art = "Various Artist"
if not os.path.isdir(os.path.join(d,art)):
os.mkdir(os.path.join(d,art))
name = ids.title.strip().replace("/", "").replace("\\","")
if name == "":
name = "Untitled Track"
try:
if os.path.isfile(os.path.join(d,art,name+".mp3")):
name = getUntitledID(name, os.path.join(d,art))
shutil.copy(os.path.join(r,f), os.path.join(d,art,name+".mp3"))
except TypeError, message:
shutil.copy(os.path.join(r,f), os.path.join(d,art,getUntitledID("Untitled Track", os.path.join(d,art))+".mp3"))
print t + " " + art
def processPath(r,d,t):
print t + r
[processFile(r,f,d,t) for f in os.listdir(r) if os.path.isfile(os.path.join(r, f))]
[processPath(os.path.join(r,f),d,t+t) for f in os.listdir(r) if os.path.isdir(os.path.join(r, f))]
def __main__():
try:
opts, rest = getopt.getopt(sys.argv[1:], "r:d:")
except getopt.GetoptError:
sys.exit(2)
r = ""
d = os.getcwd()
for opt, arg in opts:
if opt in ["-r"]:
r= arg
if opt in ["-d"]:
d= arg
if not os.path.isdir(d):
sys.exit(2)
d = os.path.join(d,"ipod")
if not os.path.isdir(d):
os.mkdir(d)
processPath(r,d," ")
if __name__ == "__main__":
__main__()
Please note that this is not tested fully and is the version that worked for me. If you have songs without ID3 tags set in ITunes, or song’s whose title, artist name, or album name contain non-English letters (i.e. Russian or Greek or something of that nature), you “MAY” experience some problems.
0 Comments until now