def main(): rewrite = ("--rewrite" in sys.argv) drop = dropbox.Dropbox() new_artists = set() for au_file in drop.tracks(): try: tpe1 = au_file.mutagen_id3["TPE1"].text[0] except: print '** file: %r' % au_file.path raise if artists.standardize(tpe1) is None: new_artists.add(tpe1) to_print = list(new_artists) if rewrite: to_print.extend(artists.all()) to_print.sort(key=artists.sort_key) output = None if rewrite: output = codecs.open(artists._WHITELIST_FILE, "w", "utf-8") for tpe1 in to_print: if output: output.write(tpe1) output.write("\n") else: print tpe1.encode("utf-8") if rewrite: print "Artist whitelist updated"
def main_generator(rewrite): drop = dropbox.Dropbox() new_artists = set() for au_file in drop.tracks(): try: tpe1 = au_file.mutagen_id3["TPE1"].text[0] except: cprint(u'** file: %r' % au_file.path) raise if artists.standardize(tpe1) is None: new_artists.add(tpe1) to_print = list(new_artists) if rewrite: to_print.extend(artists.all()) to_print.sort(key=artists.sort_key) output = None if rewrite: output = codecs.open(artists._WHITELIST_FILE, "w", "utf-8") for tpe1 in to_print: if output: output.write(tpe1) output.write("\n") else: cprint(tpe1) yield if rewrite: cprint('Artist whitelist updated', type='success') else: cprint('Found %d new artists' % len(to_print), type='success')
def main(): print if dry_run: print "+++ This is only a dry run. No actual import will occur." print "+++ We will only scan the dropbox looking for errors." else: print "*" * 70 print "***" print "*** WARNING! This is a real import!" print "*** If no errors are found, the music library will be updated!" print "***" print "*" * 70 print inbox = dropbox.Dropbox() import_albums(inbox)
def add_artists(self): error = False drop = dropbox.Dropbox() new_artists = set() for au_file in drop.tracks(): try: tpe1 = au_file.mutagen_id3["TPE1"].text[0] except: Messages.add_messaage('** file: %r' % au_file.path, 'error') error = True # TODO propagate error to client raise if artists.standardize(tpe1) is None: new_artists.add(tpe1) # do not write if errors if not error and new_artists: to_print = list(new_artists) to_print.extend(artists.all()) to_print.sort(key=artists.sort_key) output = codecs.open(artists._WHITELIST_FILE, "w", "utf-8") for tpe1 in to_print: output.write(tpe1) output.write("\n") output.close() # reload whitelist from file artists._init() message = "Artist whitelist updated.<br>New artists added:<br>" message += "<br>".join(list(new_artists)) Messages.add_message(message, 'success') # push to github self.push_to_github()
def import_albums(dry_run): inbox = dropbox.Dropbox() prescan_timestamp = timestamp.now() error_count = 0 album_count = 0 seen_fp = {} db = database.Database(LIBRARY_DB) try: for alb in inbox.albums(): alb.drop_payloads() album_count += 1 cprint(u'#{num} "{title}"'.format(num=album_count, title=alb.title())) if alb.tags(): cprint(u"(%s)" % ", ".join(alb.tags())) else: print duration_ms = sum(au.duration_ms for au in alb.all_au_files) if alb.is_compilation(): cprint("Compilation") for i, au in enumerate(alb.all_au_files): artist = au.mutagen_id3["TPE1"] cprint(u" {:02d}: {}".format(i + 1, artist)) else: cprint(alb.artist_name()) cprint(u"{} tracks / {} minutes".format(len(alb.all_au_files), int(duration_ms / 60000))) cprint(u"ID=%015x" % alb.album_id) sys.stdout.flush() # Check that the album isn't already in library. collision = False for au in alb.all_au_files: if au.fingerprint in seen_fp: cprint(u"***** ERROR: DUPLICATE TRACK WITHIN IMPORT", type='error') cprint(u"This one is at %s" % au.path) cprint(u"Other one is at %s" % seen_fp[au.fingerprint].path) collision = True break fp_au_file = db.get_by_fingerprint(au.fingerprint) if fp_au_file is not None: cprint(u"***** ERROR: TRACK ALREADY IN LIBRARY", type='error') cprint(fp_au_file.mutagen_id3) collision = True break seen_fp[au.fingerprint] = au if collision: sys.stdout.flush() error_count += 1 # Attach a dummy volume # and timestamp alb.set_volume_and_import_timestamp(0xff, prescan_timestamp) try: alb.standardize() cprint("OK!\n") except (import_file.ImportFileError, album.AlbumError), ex: cprint("***** IMPORT ERROR") cprint("***** %s\n" % str(ex)) error_count += 1 sys.stdout.flush() yield # scanned an album except analyzer.InvalidFileError as ex: cprint("***** INVALID FILE ERROR", type='error') cprint("***** %s\n" % str(ex), type='error') error_count += 1 cprint("-" * 40) cprint("Found %d albums" % album_count) if error_count > 0: cprint("Saw %d errors" % error_count, type='failure') return cprint("No errors found") if dry_run: cprint("Dry run --- terminating", type='success') return txn = None for alb in inbox.albums(): if txn is None: txn = import_transaction.ImportTransaction(db, VOLUME_NUMBER, timestamp.now(), LIBRARY_TMP_PREFIX, dry_run=dry_run) txn.add_album(alb) # If the transaction has grown too large, commit it. if txn.total_size_in_bytes > IMPORT_SIZE_LIMIT: txn.commit(LIBRARY_PREFIX) txn = None yield # import an album # Flush out any remaining tracks. if txn: txn.commit(LIBRARY_PREFIX) return
def get(self): self.add_artists() inbox = dropbox.Dropbox() return self.import_albums(inbox)