Last active
November 6, 2017 01:11
-
-
Save BenjaminUrquhart/2cdf19aa02773d6116eeaee4cfe76438 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
import traceback | |
mediaDir = "/media/" | |
def strip(string): | |
toRemove = ["'","/"," "] | |
stripped = "" | |
for i in string: | |
if i in toRemove: | |
stripped = stripped + "\ ".replace(" ","") | |
stripped = stripped + i | |
return stripped | |
try: | |
os.listdir(mediaDir) | |
except: | |
print "Unable to find any removable drives!" | |
print "Are you using Linux?" | |
exit(1) | |
try: | |
os.system("whoami > .user") | |
user = open(".user","r").readline().replace("\n","") | |
print "Finding drives mounted for user " + user + "..." | |
try: | |
drives = os.listdir("/media/" + user) | |
mediaDir = "/media/" + user + "/" | |
except: | |
print "Unable to find drives mounted as " + user | |
print "Finding global drives..." | |
drives = os.listdir("/media/") | |
print "Found " + str(len(drives)) + " drive(s)" | |
ipods = [] | |
for drive in drives: | |
try: | |
os.listdir(mediaDir + drive + "/iPod_Control") | |
ipods.append(drive) | |
print "Drive " + drive + " is an iPod!" | |
except: | |
pass | |
print str(len(ipods)) + " iPod(s) found!" | |
if len(ipods) == 0: | |
exit() | |
if len(ipods) > 1: | |
count = 0 | |
for i in ipods: | |
print str(count) + ": " + i | |
ipod = ipods[int(raw_input("Please enter the index number of the ipod you would like to dump: "))] | |
else: | |
ipod = ipods[0] | |
print "Dumping iPod " + ipod + "..." | |
dirs = os.listdir(mediaDir + ipod + "/iPod_Control/Music/") | |
try: | |
os.makedirs(ipod) | |
except: | |
pass | |
for i in dirs: | |
try: | |
print "Dumping " + i + " (" + str(len(os.listdir(mediaDir + ipod + "/iPod_Control/Music/" + i))) + " songs...)" | |
except OSError: | |
pass | |
os.system("cp -r " + mediaDir + strip(ipod) + "/iPod_Control/Music/" + i + " ./" + strip(ipod)) | |
print "Done!" | |
except: | |
print "That's a problem" | |
exc_type, exc_value, exc_traceback = sys.exc_info() | |
lines = traceback.format_exception(exc_type, exc_value, exc_traceback) | |
print(''.join(line for line in lines)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
KNOWN BUGS: