This commit is contained in:
EstrellaXD
2023-05-03 17:44:34 +08:00
parent 9235c2d396
commit b781ca72ac

View File

@@ -46,7 +46,7 @@ class Renamer:
def rename_file(self, info, media_path: str, rename_method: str, bangumi_name: str, season: int, remove_bad_torrents: bool):
torrent_name = info.name
suffix = os.path.splitext(media_path)[-1]
compare_name = media_path.split(os.path.sep)[-1]
compare_name = self.get_file_name(media_path)
new_path = self._renamer.torrent_parser(
torrent_name=torrent_name,
bangumi_name=bangumi_name,
@@ -71,7 +71,7 @@ class Renamer:
path_len = len(media_path.split(os.path.sep))
if path_len <= 2:
suffix = os.path.splitext(media_path)[-1]
torrent_name = media_path.split(os.path.sep)[-1]
torrent_name = self.get_file_name(media_path)
new_name = self._renamer.torrent_parser(
torrent_name=torrent_name,
bangumi_name=bangumi_name,
@@ -99,7 +99,7 @@ class Renamer:
):
for subtitle_path in subtitle_list:
suffix = os.path.splitext(subtitle_path)[-1]
old_name = subtitle_path.split(os.path.sep)[-1]
old_name = self.get_file_name(subtitle_path)
new_name = self._renamer.torrent_parser(
method="subtitle",
torrent_name=old_name,
@@ -129,7 +129,7 @@ class Renamer:
if PurePath(save_path).name != save_path \
else PureWindowsPath(save_path).parts
# Get folder name
folder_name = path_parts[1] if path_parts[0] == "/" else path_parts[0]
folder_name = path_parts[1] if path_parts[0] == "/" or path_parts[0] == "\\" else path_parts[0]
# Get season
try:
if re.search(r"S\d{1,2}|[Ss]eason", path_parts[-1]) is not None:
@@ -142,6 +142,16 @@ class Renamer:
season = 1
return folder_name, season
@staticmethod
def get_file_name(file_path: str):
# Check windows or linux path
path_parts = PurePath(file_path).parts \
if PurePath(file_path).name != file_path \
else PureWindowsPath(file_path).parts
# Get file name
file_name = path_parts[-1]
return file_name
def rename(self):
# Get torrent info
download_path = self.settings.downloader.path
@@ -192,15 +202,6 @@ if __name__ == '__main__':
setup_logger()
client = DownloadClient(settings)
renamer = Renamer(client, settings)
info, _ = renamer.get_torrent_info(category="BangumiCollection")
for i in info:
_hash = i.hash
_, subtitle_list = renamer.check_files(i)
print(_hash)
bangumi_name, season = renamer.get_season_info(i.save_path, settings.downloader.path)
renamer.rename_subtitles(
subtitle_list,
bangumi_name=bangumi_name,
season=season,
_hash=_hash
)
save_path = "D:\Videos\Bangumi\我推的孩子\Season 1\[XKsub][Oshi no Ko][01][CHS][1080P][WEBrip][MP4].mp4"
path = renamer.get_file_name(save_path)
print(path)