コード例 #1
0
 def _announce_file(self, target: Target):
     media_type = target.metadata.media.value.title()
     description = (f"{media_type} Subtitle" if is_subtitle(
         target.metadata.container) else media_type)
     filename_label = target.source.name
     filesize_label = get_filesize(target.source)
     tty.msg(
         f'\nProcessing {description} "{filename_label}" ({filesize_label})',
         MessageType.HEADING,
     )
     tty.msg(target.source, debug=True)
コード例 #2
0
ファイル: metadata.py プロジェクト: robalar/mnamer
 def extension(self):
     if is_subtitle(self.container) and self.language_sub:
         return f".{self.language_sub.a2}{self.container}"
     else:
         return self.container
コード例 #3
0
    def _process_targets(self) -> None:
        for target in self.targets:
            self._announce_file(target)
            self._list_details(target)

            # find match for target
            matches = []
            try:
                matches = target.query()
            except MnamerNotFoundException:
                tty.msg("no matches found", MessageType.ALERT)
            except MnamerNetworkException:
                tty.msg("network error", MessageType.ALERT)
            if not matches and self.settings.no_guess:
                tty.msg("skipping (--no-guess)", MessageType.ALERT)
                continue
            try:
                if self.settings.batch:
                    match = matches[0] if matches else target.metadata
                elif not matches:
                    match = tty.metadata_guess(target.metadata)
                else:
                    match = tty.metadata_prompt(matches)
            except MnamerSkipException:
                tty.msg("skipping (user request)", MessageType.ALERT)
                continue
            except MnamerAbortException:
                tty.msg("aborting (user request)", MessageType.ERROR)
                break
            target.metadata.update(match)

            if (is_subtitle(target.metadata.container)
                    and not target.metadata.language_sub):
                if self.settings.batch:
                    tty.msg(
                        "skipping (subtitle language can't be detected)",
                        MessageType.ALERT,
                    )
                    continue
                try:
                    target.metadata.language_sub = tty.subtitle_prompt()
                except MnamerSkipException:
                    tty.msg("skipping (user request)", MessageType.ALERT)
                    continue
                except MnamerAbortException:
                    tty.msg("aborting (user request)", MessageType.ERROR)
                    break

            # sanity check move
            if target.destination == target.source:
                tty.msg(
                    "skipping (source and destination paths are the same)",
                    MessageType.ALERT,
                )
                continue
            if self.settings.no_overwrite and target.destination.exists():
                tty.msg(
                    "skipping (--no-overwrite)",
                    MessageType.ALERT,
                )
                continue

            self._rename_and_move_file(target)