def tracks(self): """Do a fast scan and return all tracks in the dropbox.""" if self._all_tracks is None: self._all_tracks = [] for path in self._dirs: for alb in album.from_directory(path, fast=True): self._all_tracks.extend(alb.all_au_files) return self._all_tracks
def albums(self): """Return unstandardized versions of all albums in the dropbox.""" if self._all_albums is None: self._all_albums = [] for path in sorted(self._dirs): for au in album.from_directory(path): self._all_albums.append(au) yield au else: for au in self._all_albums: yield au
def import_albums(self, inbox): prescan_timestamp = timestamp.now() # timestamp to be referenced by push step ImportTimeStamp.import_time_stamp = timestamp.now() Messages.add_message('Import time stamp set: %s' % ImportTimeStamp.import_time_stamp, 'warning') error_count = 0 album_count = 0 seen_fp = {} albums = [] transaction = [] db = database.Database(LIBRARY_DB) dirs = inbox._dirs for path in sorted(dirs): try: albs = album.from_directory(path) except analyzer.InvalidFileError, ex: album_message = "<br>***** INVALID FILE ERROR<br>" album_message += "<br>%s" % str(ex) Messages.add_message(album_message, 'error') error_count += 1 albums.append({'path': path, 'title': 'There was an error at %s' % path, 'error': True}) continue for alb in albs: # generate response album_path = path album_response = album_to_json(alb, album_path) # initialize error state # import process will halt if an error is seen album_error = False alb.drop_payloads() album_count += 1 # start album_message album_message = (u'"%s"<br>' % alb.title()).encode("utf-8") if alb.tags(): album_message += "(%s)" % ", ".join(alb.tags()) duration_ms = sum(au.duration_ms for au in alb.all_au_files) if alb.is_compilation(): album_message += "Compilation<br>" for i, au in enumerate(alb.all_au_files): album_message += " %02d:" % (i+1,) try: album_message += unicode(au.mutagen_id3["TPE1"]).encode("utf-8") except UnicodeDecodeError, e: album_message += "<br>***** Encoding ERROR<br>" album_message += "<br>%s" % str(ex) error_count += 1 album_error = True else: album_message += alb.artist_name().encode("utf-8") album_message += "<br>%d tracks / %d minutes<br>" % ( len(alb.all_au_files), int(duration_ms / 60000)) album_message += "ID=%015x<br>" % alb.album_id # Check that the album isn't already in library. collision = False for au in alb.all_au_files: if au.fingerprint in seen_fp: album_message += "<br>***** ERROR: DUPLICATE TRACK WITHIN IMPORT<br>" collision = True break fp_au_file = db.get_by_fingerprint(au.fingerprint) if fp_au_file is not None: album_message += "<br>***** ERROR: TRACK ALREADY IN LIBRARY" collision = True break seen_fp[au.fingerprint] = au if collision: album_error = True error_count += 1 # Attach a dummy volume # and timestamp alb.set_volume_and_import_timestamp(0xff, prescan_timestamp) try: alb.standardize() except (import_file.ImportFileError, album.AlbumError), ex: album_message += "<br>***** IMPORT ERROR<br>" album_message += "<br>%s" % str(ex) error_count += 1 album_error = True
def import_albums(self, inbox): prescan_timestamp = timestamp.now() # timestamp to be referenced by push step ImportTimeStamp.import_time_stamp = timestamp.now() Messages.add_message( 'Import time stamp set: %s' % ImportTimeStamp.import_time_stamp, 'warning') error_count = 0 album_count = 0 seen_fp = {} albums = [] transaction = [] db = database.Database(LIBRARY_DB) dirs = inbox._dirs for path in sorted(dirs): try: albs = album.from_directory(path) except analyzer.InvalidFileError, ex: album_message = "<br>***** INVALID FILE ERROR<br>" album_message += "<br>%s" % str(ex) Messages.add_message(album_message, 'error') error_count += 1 albums.append({ 'path': path, 'title': 'There was an error at %s' % path, 'error': True }) continue for alb in albs: # generate response album_path = path album_response = album_to_json(alb, album_path) # initialize error state # import process will halt if an error is seen album_error = False alb.drop_payloads() album_count += 1 # start album_message album_message = (u'"%s"<br>' % alb.title()).encode("utf-8") if alb.tags(): album_message += "(%s)" % ", ".join(alb.tags()) duration_ms = sum(au.duration_ms for au in alb.all_au_files) if alb.is_compilation(): album_message += "Compilation<br>" for i, au in enumerate(alb.all_au_files): album_message += " %02d:" % (i + 1, ) try: album_message += unicode( au.mutagen_id3["TPE1"]).encode("utf-8") except UnicodeDecodeError, e: album_message += "<br>***** Encoding ERROR<br>" album_message += "<br>%s" % str(ex) error_count += 1 album_error = True else: album_message += alb.artist_name().encode("utf-8") album_message += "<br>%d tracks / %d minutes<br>" % (len( alb.all_au_files), int(duration_ms / 60000)) album_message += "ID=%015x<br>" % alb.album_id # Check that the album isn't already in library. collision = False for au in alb.all_au_files: if au.fingerprint in seen_fp: album_message += "<br>***** ERROR: DUPLICATE TRACK WITHIN IMPORT<br>" collision = True break fp_au_file = db.get_by_fingerprint(au.fingerprint) if fp_au_file is not None: album_message += "<br>***** ERROR: TRACK ALREADY IN LIBRARY" collision = True break seen_fp[au.fingerprint] = au if collision: album_error = True error_count += 1 # Attach a dummy volume # and timestamp alb.set_volume_and_import_timestamp(0xff, prescan_timestamp) try: alb.standardize() except (import_file.ImportFileError, album.AlbumError), ex: album_message += "<br>***** IMPORT ERROR<br>" album_message += "<br>%s" % str(ex) error_count += 1 album_error = True