This one goes through an m3u playlist and seperates out the songs that have been moved or deleted.

import sys
import os.path

oldname = sys.argv[-1]
dirname = os.path.dirname(oldname)
goodname = oldname.replace(".m3u","_good.m3u") 
badname = oldname.replace(".m3u","_bad.m3u") 
old=file(oldname)
good=file(goodname,"w")
badlst=[]
for line in old:
    if not line.startswith("#"):
        if os.path.exists(os.path.join(dirname, line.strip())):
            good.write(line)
        else:
            #bad.write(line)
            badlst.append(line)
old.close()
good.close()

if badlst:
    badlst.sort()
    bad=file(badname,"w")
    for x in badlst:
        bad.write(x)
    bad.close()
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s