Last active
March 23, 2016 07:11
-
-
Save saranya-vatti/4bb3a5a70b1c48c598e1 to your computer and use it in GitHub Desktop.
Copy windows media player playlist to destination directory
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
##code to copy all the songs in the playlist to the directory specified | |
import os | |
import shutil | |
sourcePL = 'C:\\Users\\saranya.v\\Music\\Playlists\\Sleep.wpl' | |
#destDir = 'E:\\Music\\Lyrics\\' | |
destDir = 'D:\\Move\\tmp\\' | |
LOG_LEVELS = { | |
"DEBUG" : 100, | |
"INFO" : 200, | |
"ERROR" : 300, | |
"NONE" : 400 | |
} | |
LOGLVL=LOG_LEVELS["NONE"] | |
def log_error(exception, location): | |
if(LOGLVL <= LOG_LEVELS["ERROR"]): | |
print("Exception encountered : " + str(type(exception)) + " in " + location) | |
print("Exception : " + str(exception)) | |
def log_info(string): | |
if(LOGLVL <= LOG_LEVELS["INFO"]): | |
print(string) | |
def log_debug(string): | |
if(LOGLVL <= LOG_LEVELS["DEBUG"]): | |
print(string) | |
f = open(sourcePL, "r") | |
for line in f: | |
try: | |
tmp = (line.split('src="')[1]) | |
songfilefullpath = tmp.split('"')[0] | |
tmplist = songfilefullpath.split("\\") | |
songfilename = tmplist[len(tmplist) - 1] | |
if os.path.isfile(songfilefullpath) and not os.path.isfile(destDir + songfilename): | |
shutil.copyfile(songfilefullpath, destDir + songfilename) | |
except Exception as e: | |
log_error(e, "splitting line : " + line) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment