From 5abe38ceabb6c5178f4f79e681123cad6af8d59f Mon Sep 17 00:00:00 2001 From: Trim21 Date: Sat, 23 Nov 2024 13:08:26 +0800 Subject: [PATCH] fix subtitle zh --- pt_repost/application.py | 36 ++++++++++++++++++------------------ pt_repost/website.py | 18 +++++++++++++----- 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/pt_repost/application.py b/pt_repost/application.py index d64a469..5fc716d 100644 --- a/pt_repost/application.py +++ b/pt_repost/application.py @@ -152,9 +152,26 @@ def process_task( count = 3 + site_implement = SSD(self.config) + + tc = self.qb.torrents_export(info_hash) + + torrent_name = six.ensure_str(bencode2.bdecode(tc)[b"info"][b"name"]) + + options = site_implement.parse_mediainfo_as_options( + torrent_name, parse_mediainfo_json(mediainfo_json) + ) + + if douban_id: + url = f"https://movie.douban.com/subject/{douban_id}/" + elif imdb_id: + url = f"https://www.imdb.com/title/{imdb_id}/" + else: + raise ValueError("missing media site id") + images = self.db.fetch_all("select * from image where task_id = ?", [task_id]) - if len(images) < count: + if (len(images) < count) and not dry_run: with tempfile.TemporaryDirectory(prefix="pt-repost-") as tempdir: for file in generate_images( video_file, count=count, tmpdir=Path(tempdir) @@ -171,23 +188,6 @@ def process_task( ) ] - site_implement = SSD(self.config) - - tc = self.qb.torrents_export(info_hash) - - torrent_name = six.ensure_str(bencode2.bdecode(tc)[b"info"][b"name"]) - - options = site_implement.parse_mediainfo_as_options( - torrent_name, parse_mediainfo_json(mediainfo_json) - ) - - if douban_id: - url = f"https://movie.douban.com/subject/{douban_id}/" - elif imdb_id: - url = f"https://www.imdb.com/title/{imdb_id}/" - else: - raise ValueError("missing media site id") - info = extract_meta_info(douban_id or imdb_id) if dry_run: logger.info("dry-run mode, skipping create post") diff --git a/pt_repost/website.py b/pt_repost/website.py index fd816a0..c511ff8 100644 --- a/pt_repost/website.py +++ b/pt_repost/website.py @@ -123,11 +123,19 @@ def parse_mediainfo_as_options( for text in m.text: lang = text.language.lower() title = text.title.lower() - for word in {"zh-cn", "zh-cn", "zh-cn", "chinese", "cmn-hans", "cmn-hant"}: - if (word in lang) or (word in title): - logger.info('find tag "中字"') - options["subtitlezh"] = "1" - break + if any( + ((word in lang) or (word in title)) + for word in { + "zh", + "zh-cn", + "chinese", + "cmn-hans", + "cmn-hant", + } + ): + logger.info('find tag "中字"') + options["subtitlezh"] = "1" + break return options