def _cmd(self, history, args): tags = {} match_all = False match_exact = False for a in args: if a == '-a': match_all = True elif a == '-e': match_exact = True else: p = a.find('=') if p > 0: tag = a[0:p] value = a[p + 1:] tags[tag] = value else: OUTPUT.error('Invalid argument format: {0}'.format(a)) if match_all: matches = history.get_tag_matches(tags, match_exact) else: matches = set() for k, v in tags.items(): m = history.get_tag_matches({k: v}, match_exact) matches = matches.union(m) OUTPUT.dict_start('Tag Matches') OUTPUT.list_section('Source Files', matches) OUTPUT.dict_end()
def print_entries(entries, history): if isinstance(entries, MediaEntry): entries = [entries] OUTPUT.start() OUTPUT.list_start("Source-Info") for entry in entries: assert isinstance(entry, MediaEntry) OUTPUT.dict_start(entry.source) OUTPUT.dict_item('marked', entry.is_marked) OUTPUT.dict_item('transcoded_to', entry.transcoded_to) OUTPUT.dict_item( 'transcoded_exists', os.path.isfile(entry.transcoded_to) if entry.transcoded_to else False) OUTPUT.dict_item('source_exists', os.path.isfile(entry.source)) OUTPUT.list_start('duplicates') for dn in entry.duplicate_filenames: #OUTPUT.dict_start(dn) #dn_keys = history.get_keywords_for(dn) #OUTPUT.list_section('common_keywords', list(dn_keys.intersection(fn_keys))) #OUTPUT.dict_end() OUTPUT.list_item(dn) OUTPUT.list_end() OUTPUT.dict_section('tags', entry.tags) # OUTPUT.list_section('keywords', entry.keywords) OUTPUT.dict_end() OUTPUT.list_end() OUTPUT.end()
def _cmd(self, history, args): if len(args) == 0: args = history.get_transcoded_filenames() OUTPUT.dict_start('transcoded_from') for tn in args: sources = [] sn = history.get_source_file_for_transcoded_filename(tn) if sn is not None: sources.append(sn) # Get the duplicates, so it traces all the files. sources.extend(history.get_duplicate_filenames(sn)) OUTPUT.list_section(tn, sources) OUTPUT.dict_end()
def _cmd(self, history, args): force = False if args[0] == '-f': force = True args = args[1:] OUTPUT.list_start('affected_files') for fn in history.get_source_files(): tn = history.get_transcoded_to(fn) if tn is None: continue if not _do_check_file(fn, args) and not _do_check_file(tn, args): continue try: probe = probe_media_file(fn) except Exception as e: OUTPUT.error('Problem loading file {0}: {1}'.format(fn, e)) # traceback.print_exc() continue OUTPUT.list_dict_start() OUTPUT.dict_item('source_file', fn) OUTPUT.dict_item('transcoded_file', tn) fn_tags = history.get_tags_for(fn) probe_tags = probe.get_tags() new_tags = dict(fn_tags) altered_tags = False for tag_name, tag_value in probe_tags.items(): if force or tag_name not in fn_tags: if tag_name not in fn_tags or fn_tags[ tag_name] != tag_value: altered_tags = True new_tags[tag_name] = tag_value if altered_tags: OUTPUT.dict_start('original_tags') for tag_name, tag_value in fn_tags.items(): OUTPUT.dict_item(tag_name, tag_value) OUTPUT.dict_end() OUTPUT.dict_start('updated_tags') for tag_name, tag_value in new_tags.items(): OUTPUT.dict_item(tag_name, tag_value) OUTPUT.dict_end() set_tags_on_file(tn, new_tags) history.set_tags_for(fn, new_tags) OUTPUT.dict_end() OUTPUT.list_end() return 0
def _cmd(self, history, args): OUTPUT.list_start('affected_files') for fn in history.get_source_files(): tn = history.get_transcoded_to(fn) if tn is None: continue if not _do_check_file(fn, args) and not _do_check_file(tn, args): continue OUTPUT.list_dict_start() OUTPUT.dict_item('source_file', fn) OUTPUT.dict_item('transcoded_file', tn) fn_tags = history.get_tags_for(fn) new_tags = dict(fn_tags) adjusted_tags = False for tag_name, tag_value in REPLACED_TAGS.items(): if not (tag_name in fn_tags and fn_tags[tag_name] == tag_value): adjusted_tags = True new_tags[tag_name] = tag_value if adjusted_tags: OUTPUT.dict_start('original_tags') for tag_name, tag_value in fn_tags.items(): OUTPUT.dict_item(tag_name, tag_value) OUTPUT.dict_end() OUTPUT.dict_start('updated_tags') for tag_name, tag_value in new_tags.items(): OUTPUT.dict_item(tag_name, tag_value) OUTPUT.dict_end() if not PRETEND_MODE: if FF_PROBES.is_supported(fn): # Fix the source, too. try: set_tags_on_file(fn, new_tags) # TODO This will make the checksums wrong, but, meh. except Exception as e: OUTPUT.error( "Couldn't update tags on source file {0} ({1})" .format(fn, e)) set_tags_on_file(tn, new_tags) history.set_tags_for(fn, new_tags) OUTPUT.dict_end() OUTPUT.list_end() return 0
def _cmd(self, history, args): count = 0 if len(args) > 0: names = set() for name_like in args: names = names.union(history.get_source_files(name_like)) else: names = history.get_source_files() OUTPUT.dict_start('Sources') for fn in names: count += 1 OUTPUT.dict_start(fn) OUTPUT.dict_item('transcode', repr(history.get_transcoded_to(fn))) OUTPUT.list_section('duplicates', history.get_duplicate_filenames(fn)) OUTPUT.dict_end() if count <= 0: OUTPUT.error('No matching files in database') OUTPUT.dict_end() return 0
def _cmd(self, history, args): OUTPUT.list_start("Source-Info") for fn in args: OUTPUT.dict_start(fn) if not history.is_processed(fn): OUTPUT.dict_item('marked', False) sn = history.get_source_file_for_transcoded_filename(fn) OUTPUT.dict_item('transcoded_from', sn) continue OUTPUT.dict_item('marked', True) OUTPUT.dict_item('transcoded_to', history.get_transcoded_to(fn)) fn_keys = history.get_keywords_for(fn) dups = history.get_duplicates(fn) OUTPUT.dict_start('duplicates') for dn in dups: OUTPUT.dict_start(dn) dn_keys = history.get_keywords_for(dn) OUTPUT.list_section('common_keywords', list(dn_keys.intersection(fn_keys))) OUTPUT.dict_end() OUTPUT.dict_end() OUTPUT.dict_section('tags', history.get_tags_for(fn)) OUTPUT.list_section('keywords', list(fn_keys)) OUTPUT.dict_end() return 0