mirror of
https://github.com/EstrellaXD/Auto_Bangumi.git
synced 2026-04-13 09:59:45 +08:00
Fix #247
This commit is contained in:
@@ -91,13 +91,13 @@ class DataOperator(DataConnector):
|
||||
self._cursor.execute(
|
||||
"""
|
||||
UPDATE bangumi
|
||||
SET rss_link = :rss_link AND added = 0
|
||||
SET rss_link = :rss_link, added = 0
|
||||
WHERE title_raw = :title_raw
|
||||
""",
|
||||
{"rss_link": rss_set, "title_raw": title_raw},
|
||||
)
|
||||
self._conn.commit()
|
||||
logger.info(f"Update {title_raw} rss_link to {rss_set}.")
|
||||
logger.debug(f"Update {title_raw} rss_link to {rss_set}.")
|
||||
|
||||
def search_id(self, _id: int) -> BangumiData | None:
|
||||
self._cursor.execute(
|
||||
|
||||
@@ -62,22 +62,22 @@ class Renamer(DownloadClient):
|
||||
|
||||
def rename_file(
|
||||
self,
|
||||
info,
|
||||
torrent_name: str,
|
||||
media_path: str,
|
||||
bangumi_name: str,
|
||||
method: str,
|
||||
season: int,
|
||||
_hash: str,
|
||||
):
|
||||
ep = self._renamer.torrent_parser(
|
||||
torrent_name=torrent_name,
|
||||
torrent_path=media_path,
|
||||
season=season,
|
||||
)
|
||||
if ep:
|
||||
new_path = self.gen_path(ep, bangumi_name, method=method)
|
||||
if media_path != new_path:
|
||||
renamed = self.rename_torrent_file(
|
||||
_hash=info.hash, old_path=media_path, new_path=new_path
|
||||
)
|
||||
renamed = self.rename_torrent_file(_hash=_hash, old_path=media_path, new_path=new_path)
|
||||
if renamed:
|
||||
if settings.notification.enable:
|
||||
# self._notification.send_msg()
|
||||
@@ -85,7 +85,7 @@ class Renamer(DownloadClient):
|
||||
else:
|
||||
logger.warning(f"{bangumi_name} Season {ep.season} Ep {ep.episode} rename failed.")
|
||||
if settings.bangumi_manage.remove_bad_torrent:
|
||||
self.delete_torrent(info.hash)
|
||||
self.delete_torrent(hashes=_hash)
|
||||
else:
|
||||
logger.warning(f"{media_path} parse failed")
|
||||
|
||||
@@ -120,6 +120,7 @@ class Renamer(DownloadClient):
|
||||
def rename_subtitles(
|
||||
self,
|
||||
subtitle_list: list[str],
|
||||
torrent_name: str,
|
||||
bangumi_name: str,
|
||||
season: int,
|
||||
method: str,
|
||||
@@ -129,6 +130,7 @@ class Renamer(DownloadClient):
|
||||
for subtitle_path in subtitle_list:
|
||||
sub = self._renamer.torrent_parser(
|
||||
torrent_path=subtitle_path,
|
||||
torrent_name=torrent_name,
|
||||
season=season,
|
||||
)
|
||||
new_path = self.gen_path(sub, bangumi_name, method=method)
|
||||
@@ -189,15 +191,17 @@ class Renamer(DownloadClient):
|
||||
bangumi_name, season = self.get_season_info(info.save_path, download_path)
|
||||
if len(media_list) == 1:
|
||||
self.rename_file(
|
||||
info=info,
|
||||
media_path=media_list[0],
|
||||
torrent_name=info.name,
|
||||
method=rename_method,
|
||||
bangumi_name=bangumi_name,
|
||||
season=season,
|
||||
_hash=info.hash,
|
||||
)
|
||||
if len(subtitle_list) > 0:
|
||||
self.rename_subtitles(
|
||||
subtitle_list=subtitle_list,
|
||||
torrent_name=info.name,
|
||||
bangumi_name=bangumi_name,
|
||||
season=season,
|
||||
method=rename_method,
|
||||
@@ -215,6 +219,7 @@ class Renamer(DownloadClient):
|
||||
if len(subtitle_list) > 0:
|
||||
self.rename_subtitles(
|
||||
subtitle_list=subtitle_list,
|
||||
torrent_name=info.name,
|
||||
bangumi_name=bangumi_name,
|
||||
season=season,
|
||||
method=rename_method,
|
||||
|
||||
@@ -56,10 +56,18 @@ def get_subtitle_lang(subtitle_name: str) -> str:
|
||||
return key
|
||||
|
||||
|
||||
def torrent_parser(torrent_path: str, season: int | None = None, file_type: str = "media") -> EpisodeFile | SubtitleFile:
|
||||
def torrent_parser(
|
||||
torrent_path: str,
|
||||
torrent_name: str | None = None,
|
||||
season: int | None = None,
|
||||
file_type: str = "media"
|
||||
) -> EpisodeFile | SubtitleFile:
|
||||
media_path = split_path(torrent_path)
|
||||
for rule in RULES:
|
||||
match_obj = re.match(rule, media_path, re.I)
|
||||
if torrent_name:
|
||||
match_obj = re.match(rule, torrent_name, re.I)
|
||||
else:
|
||||
match_obj = re.match(rule, media_path, re.I)
|
||||
if match_obj:
|
||||
group, title = get_group(match_obj.group(1))
|
||||
if not season:
|
||||
|
||||
@@ -15,9 +15,10 @@ class TitleParser:
|
||||
@staticmethod
|
||||
def torrent_parser(
|
||||
torrent_path: str,
|
||||
torrent_name: str | None = None,
|
||||
season: int | None = None,
|
||||
):
|
||||
return torrent_parser(torrent_path, season)
|
||||
return torrent_parser(torrent_path, torrent_name, season)
|
||||
|
||||
@staticmethod
|
||||
def tmdb_parser(title: str, season: int, language: str):
|
||||
|
||||
@@ -65,10 +65,4 @@ class RSSAnalyser:
|
||||
self.rss_to_data(rss_link)
|
||||
except Exception as e:
|
||||
logger.debug(e)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from module.conf import setup_logger
|
||||
setup_logger()
|
||||
link = "https://mikan.estrella.cloud/RSS/Bangumi?bangumiId=2906&subgroupid=552"
|
||||
data = RSSAnalyser().rss_to_data(link)
|
||||
logger.error("Failed to collect RSS info.")
|
||||
|
||||
Reference in New Issue
Block a user