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