def main(args): collection_dir = '/Volumes/Media/rcollect' if not os.path.isdir(collection_dir) : os.mkdir(collection_dir) for root, dirs, files in os.walk('.'): for f in files: path = os.path.join(root,f) ext = os.path.splitext(f)[-1] if ext == '.torrent': fopen = open(path) data = fopen.read() try: d = metatorrent.decode(data) except: print 'problematic torrent file', path continue tname = d['info']['name'] tpath = os.path.join(root,tname) if os.path.isdir(tpath): try: srcname = tname spath = tpath dpath = os.path.join(collection_dir,srcname) tor_name=f tor_spath=path tor_dpath=os.path.join(collection_dir,tor_name) shutil.copytree(spath,dpath,True) shutil.copy2(tor_spath,tor_dpath) print('Copied:') print tor_name, " --> ", tor_dpath print srcname, " --> ", dpath except OSError, e: print e
def getsubmission(tfile): data = open(tfile).read() torrent = decode(data) tname = torrent['info']['name'] for file in torrent["info"]["files"]: name = "/".join(file["path"]) flac_re = re.compile(".flac") if flac_re.search(name) != None: flacname=name log_re = re.compile(".log") if log_re.search(name) !=None: logname=name fpath = os.path.join(tname,flacname) lpath = os.path.join(tname,logname) audio = FLAC(fpath) print audio.keys() if not audio.has_key('musicbrainz_albumid'): print "ReleaseID tag is not set. Has this flac been tagged by picard?" return(-1) albumid = audio['musicbrainz_albumid'][0] print albumid q = ws.Query() try: inc = ws.ReleaseIncludes(artist=True, releaseEvents=True, labels=True, discs=True, tracks=True) release = q.getReleaseById(albumid, inc) except ws.WebServiceError, e: print 'Error:', e return(-1)