예제 #1
0
 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()
예제 #2
0
 def _parse_args(self, args):
     normalize = False
     if args[0] == '-n':
         normalize = True
         args = args[1:]
     if len(args) <= 0:
         OUTPUT.error('Must provide at least one file matching argument')
         return False, []
     return True, [normalize, *args]
예제 #3
0
 def _parse_args(self, args):
     if len(args) <= 0:
         OUTPUT.error('Must provide at least one of `a` or `t` arguments.')
         return False, []
     tags = []
     for i in args[0]:
         if i not in TAG_TYPES:
             OUTPUT.error('Invalid tag types ({0}) must be at least one of `a` or `t`.'.format(args[0]))
             return False, []
         tags.append(TAG_TYPES[i])
     return True, [tags, args[1:]]
예제 #4
0
    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
예제 #5
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
예제 #6
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
예제 #7
0
 def _cmd(self, history, args):
     for fn in history.get_source_files():
         tn = history.get_transcoded_to(fn)
         if tn is None:
             continue
         local_tn = reverse_tcode(tn)
         if (not _do_check_file(fn, args)
             and not _do_check_file(tn, args)
             and not _do_check_file(reverse_tcode(tn), args)
             ):
             continue
         print(fn)
         fn_tags = history.get_tags_for(fn)
         print('- Tags: {0}'.format(repr(fn_tags)))
         adjusted_tags = False
         while True:
             tag_name = prompt_value('Tag to edit (empty to continue)')
             if tag_name is None:
                 break
             tag_name = tag_name.strip()
             tag_value = prompt_value('New value')
             if tag_value is None:
                 if tag_name in fn_tags:
                     del fn_tags[tag_name]
                     adjusted_tags = True
             else:
                 fn_tags[tag_name] = tag_value
                 adjusted_tags = True
         if adjusted_tags:
             if FF_PROBES.is_supported(fn):
                 # Fix the source, too.
                 try:
                     set_tags_on_file(fn, fn_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(local_tn, fn_tags)
             history.set_tags_for(fn, fn_tags)
     return 0
예제 #8
0
 def _cmd(self, history, args):
     tag_names = args[0]
     args = args[1]
     for fn in history.get_source_files_without_tag_names(tag_names):
         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
         print(fn)
         print(' -> {0}'.format(tn))
         fn_tags = history.get_tags_for(fn)
         print('- Tags: {0}'.format(repr(fn_tags)))
         adjusted_tags = False
         for t in tag_names:
             if t not in fn_tags or len(fn_tags[t].strip()) <= 0:
                 tv = prompt_value(t)
                 if tv is not None:
                     fn_tags[t] = tv
                     adjusted_tags = True
             else:
                 print("Already handled {0}".format(t))
         if adjusted_tags:
             if FF_PROBES.is_supported(fn):
                 # Fix the source, too.
                 try:
                     set_tags_on_file(fn, fn_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, fn_tags)
             history.set_tags_for(fn, fn_tags)
     print("Finished with tag handling")
     return 0
예제 #9
0
 def process(self, arg):
     if arg is None:
         OUTPUT.error('Must provide an argument for the option -t')
         return False, None
     p = arg.find(':')
     if p < 0:
         OUTPUT.error('Must provide a value')
         return False
     tag_name = arg[0:p].strip()
     if len(tag_name) <= 0:
         OUTPUT.error('Tag name cannot be zero-length')
         return False
     tag_value = None
     if p < len(arg):
         tag_value = arg[p + 1:].strip()
         if len(tag_value) <= 0:
             tag_value = None
     REPLACED_TAGS[tag_name] = tag_value
     return True
예제 #10
0
 def _parse_args(self, args):
     if len(args) <= 0:
         OUTPUT.error('Must provide at least one file matching argument')
         return False, []
     return True, args