def info(paths): # Set up fields to output. fields = [] for name, _, _, mffield in library.ITEM_FIELDS: if mffield: fields.append(name) maxwidth = max(len(name) for name in fields) lineformat = u'{{:>{0}}}: {{}}'.format(maxwidth) first = True for path in paths: if not first: ui.print_() path = library._normpath(path) ui.print_(path) try: mf = mediafile.MediaFile(path) except mediafile.UnreadableFileError: ui.print_('cannot read file') continue for name in fields: ui.print_(lineformat.format(name, getattr(mf, name))) first = False
def read_albums(paths, resume): """A generator yielding all the albums (as sets of Items) found in the user-specified list of paths. `progress` specifies whether the resuming feature should be used. It may be True (resume if possible), False (never resume), or None (ask). """ # Use absolute paths. paths = [library._normpath(path) for path in paths] # Check the user-specified directories. for path in paths: if not os.path.isdir(library._syspath(path)): raise ui.UserError('not a directory: ' + path) # Look for saved progress. progress = resume is not False if progress: resume_dirs = {} for path in paths: resume_dir = progress_get(path) if resume_dir: # Either accept immediately or prompt for input to decide. if resume: do_resume = True ui.print_('Resuming interrupted import of %s' % path) else: do_resume = ui.input_yn("Import of the directory:\n%s" "\nwas interrupted. Resume (Y/n)?" % path) ui.print_() if do_resume: resume_dirs[path] = resume_dir else: # Clear progress; we're starting from the top. progress_set(path, None) for toppath in paths: # Produce each path. if progress: resume_dir = resume_dirs.get(toppath) for path, items in autotag.albums_in_dir(os.path.expanduser(toppath)): if progress and resume_dir: # We're fast-forwarding to resume a previous tagging. if path == resume_dir: # We've hit the last good path! Turn off the # fast-forwarding. resume_dir = None continue yield toppath, path, items # Indicate the directory is finished. yield toppath, DONE_SENTINEL, None
def read_albums(paths): """A generator yielding all the albums (as sets of Items) found in the user-specified list of paths. """ # Use absolute paths. paths = [library._normpath(path) for path in paths] # Check the user-specified directories. for path in paths: if not os.path.isdir(library._syspath(path)): raise ui.UserError('not a directory: ' + path) # Look for saved progress. resume_dirs = {} for path in paths: resume_dir = progress_get(path) if resume_dir: resume = ui.input_yn("Import of the directory:\n%s" "\nwas interrupted. Resume (Y/n)? " % path) if resume: resume_dirs[path] = resume_dir else: # Clear progress; we're starting from the top. progress_set(path, None) ui.print_() for toppath in paths: # Produce each path. resume_dir = resume_dirs.get(toppath) for path, items in autotag.albums_in_dir(os.path.expanduser(toppath)): if resume_dir: # We're fast-forwarding to resume a previous tagging. if path == resume_dir: # We've hit the last good path! Turn off the # fast-forwarding. resume_dir = None continue yield toppath, path, items # Indicate the directory is finished. yield toppath, DONE_SENTINEL, None