feat: fix path problem.

This commit is contained in:
EstrellaXD
2023-10-01 03:47:17 +08:00
parent 15eb3db53e
commit a608a541b1
2 changed files with 53 additions and 36 deletions

View File

@@ -1,13 +1,17 @@
import logging
from os import PathLike
import re
from pathlib import Path
from module.conf import settings
from module.conf import settings, PLATFORM
from module.models import Bangumi, BangumiUpdate
logger = logging.getLogger(__name__)
if PLATFORM == "Windows":
from pathlib import WindowsPath as Path
else:
from pathlib import Path
class TorrentPath:
def __init__(self):
@@ -68,3 +72,9 @@ class TorrentPath:
@staticmethod
def _join_path(*args):
return str(Path(*args))
if __name__ == '__main__':
path = "C:\\ABC\\Season 1\\Bangumi Name"
print(TorrentPath()._path_to_bangumi(path))

View File

@@ -1,4 +1,5 @@
import logging
import re
from module.conf import settings
from module.downloader import DownloadClient
@@ -12,6 +13,7 @@ class Renamer(DownloadClient):
def __init__(self):
super().__init__()
self._parser = TitleParser()
self.check_pool = {}
@staticmethod
def print_result(torrent_count, rename_count):
@@ -23,7 +25,7 @@ class Renamer(DownloadClient):
@staticmethod
def gen_path(
file_info: EpisodeFile | SubtitleFile, bangumi_name: str, method: str
file_info: EpisodeFile | SubtitleFile, bangumi_name: str, method: str
) -> str:
season = f"0{file_info.season}" if file_info.season < 10 else file_info.season
episode = (
@@ -47,14 +49,14 @@ class Renamer(DownloadClient):
return file_info.media_path
def rename_file(
self,
torrent_name: str,
media_path: str,
bangumi_name: str,
method: str,
season: int,
_hash: str,
**kwargs,
self,
torrent_name: str,
media_path: str,
bangumi_name: str,
method: str,
season: int,
_hash: str,
**kwargs,
):
ep = self._parser.torrent_parser(
torrent_name=torrent_name,
@@ -64,16 +66,15 @@ class Renamer(DownloadClient):
if ep:
new_path = self.gen_path(ep, bangumi_name, method=method)
if media_path != new_path:
renamed = self.rename_torrent_file(
_hash=_hash, old_path=media_path, new_path=new_path
)
if renamed:
n = Notification(
official_title=bangumi_name,
season=ep.season,
episode=ep.episode,
)
return n
if new_path not in self.check_pool.keys():
if self.rename_torrent_file(
_hash=_hash, old_path=media_path, new_path=new_path
):
return Notification(
official_title=bangumi_name,
season=ep.season,
episode=ep.episode,
)
else:
logger.warning(f"[Renamer] {media_path} parse failed")
if settings.bangumi_manage.remove_bad_torrent:
@@ -81,13 +82,13 @@ class Renamer(DownloadClient):
return None
def rename_collection(
self,
media_list: list[str],
bangumi_name: str,
season: int,
method: str,
_hash: str,
**kwargs,
self,
media_list: list[str],
bangumi_name: str,
season: int,
method: str,
_hash: str,
**kwargs,
):
for media_path in media_list:
if self.is_ep(media_path):
@@ -109,14 +110,14 @@ class Renamer(DownloadClient):
break
def rename_subtitles(
self,
subtitle_list: list[str],
torrent_name: str,
bangumi_name: str,
season: int,
method: str,
_hash,
**kwargs,
self,
subtitle_list: list[str],
torrent_name: str,
bangumi_name: str,
season: int,
method: str,
_hash,
**kwargs,
):
method = "subtitle_" + method
for subtitle_path in subtitle_list:
@@ -171,6 +172,12 @@ class Renamer(DownloadClient):
logger.debug("[Renamer] Rename process finished.")
return renamed_info
def compare_ep_version(self, torrent_name: str, torrent_hash: str):
if re.search(r"v\d.", torrent_name):
pass
else:
self.delete_torrent(hashes=torrent_hash)
if __name__ == "__main__":
from module.conf import setup_logger