def scrapeFileTags(path): if path.suffix == ".flac": f = FLAC(path) elif path.suffix == ".mp3": f = EasyID3(path) tr = Track(0) tr.file_name = path.name tr.file_path = path # extract artist and title try: tr.artists = f['ARTIST'] or f['artist'] tr.title = f['TITLE'].pop().split(' (')[0] or f['title'].pop().split( ' (')[0] except: print("*** error cannot match file without artist or title") print(f"*** skipping {path.name}") return # try to extract remixer try: tr.remixer = f['TITLE'][0].split('(')[1].split( ')')[0] or f['title'][0].split('(')[1].split(')')[0] except: # assume it's original mix, when no remixer is supplied tr.remixer = "Original Mix" return tr
def addTrackToDB(filepath, db): global processing_iterator filename = Path(filepath).name # don't query if in database for k, v in db.db.items(): if v.file_name == Path(filepath).name: processing_iterator += 1 print( f"{processing_iterator}/{db.track_count} - (already in DB) {Path(filepath).name}" ) return v # if is valid beatport file if beatport_id_pattern.match(filename): beatport_id = int(beatport_id_pattern.match(filename).group()[:-1]) if db.trackInDB(beatport_id): processing_iterator += 1 print( f'{processing_iterator}/{db.track_count} - (already in DB) {filename}' ) return processing_iterator # create and get tags track = Track(beatport_id) track.file_path = Path(filepath) track.file_name = filename try: page = track.queryTrackPage() track.getTags(page) except Exception as ee: processing_iterator += 1 print(f"{processing_iterator}/{db.track_count} - {filename}") print("*** beatport id is invalid") print("*** try to use fuzzy matching (-z)\n") return processing_iterator += 1 db.db[track.beatport_id] = track print(f"{processing_iterator}/{db.track_count} - {track.file_name}") return