mirror of
https://github.com/EstrellaXD/Auto_Bangumi.git
synced 2026-12-01 00:38:13 +08:00
完成番剧历史补全功能,修复bug,更新数据结构
This commit is contained in:
@@ -20,9 +20,14 @@ logger = logging.getLogger(__name__)
|
||||
def load_data_file():
|
||||
info_path = settings.info_path
|
||||
if not os.path.exists(info_path):
|
||||
bangumi_data = {"rss_link": "", "bangumi_info": []}
|
||||
bangumi_data = {"rss_link": "",
|
||||
"data_version": settings.data_version,
|
||||
"bangumi_info": []
|
||||
}
|
||||
else:
|
||||
bangumi_data = json_config.load(info_path)
|
||||
if bangumi_data["data_version"] != settings.data_version:
|
||||
bangumi_data["bangumi_info"] = []
|
||||
return bangumi_data
|
||||
|
||||
|
||||
|
||||
@@ -12,15 +12,15 @@ class ParserLV2:
|
||||
self.info = json_config.load(settings.rule_path)
|
||||
self.type = None
|
||||
|
||||
def get_group(self, name):
|
||||
for i in self.info:
|
||||
for group in i["group_name"]:
|
||||
if re.search(group, name) is not None:
|
||||
self.type = i["type"]
|
||||
return group
|
||||
logger.warning(f"No Group matched with {name}.")
|
||||
|
||||
def pre_process(self, raw_name):
|
||||
pro_name = raw_name.replace("【", "[").replace("】", "]")
|
||||
return pro_name
|
||||
|
||||
def get_group(self, name):
|
||||
group = re.split(r"[\[\]]", name)[1]
|
||||
return group
|
||||
|
||||
def second_process(self, raw_name):
|
||||
if re.search(r"新番|月?番", raw_name):
|
||||
pro_name = re.sub(".*新番.", "", raw_name)
|
||||
else:
|
||||
@@ -71,8 +71,7 @@ class ParserLV2:
|
||||
if len(split) == 1:
|
||||
if re.search("_{1}", name) is not None:
|
||||
split = re.split("_", name)
|
||||
if len(split) == 1:
|
||||
if re.search(" - {1}", name) is not None:
|
||||
elif re.search(" - {1}", name) is not None:
|
||||
split = re.split("-", name)
|
||||
if len(split) == 1:
|
||||
match_obj = re.match(r"([^\x00-\xff]{1,})(\s)([\x00-\xff]{4,})", name)
|
||||
@@ -87,30 +86,45 @@ class ParserLV2:
|
||||
if re.findall("[aA-zZ]{1}", name).__len__() == compare:
|
||||
return name
|
||||
|
||||
def find_tags(self, other):
|
||||
elements = re.sub(r"[\[\]()()]", " ", other).split(" ")
|
||||
while "" in elements:
|
||||
elements.remove("")
|
||||
# find CHT
|
||||
sub = None
|
||||
dpi = None
|
||||
source = None
|
||||
for element in elements:
|
||||
if re.search(r"[简繁日字幕]|CH|BIG5|GB", element) is not None:
|
||||
sub = element.replace("_MP4","")
|
||||
elif re.search(r"1080|720|2160|4K", element) is not None:
|
||||
dpi = element
|
||||
elif re.search(r"B-Global|[Bb]aha|[Bb]ilibili|AT-X|Web", element) is not None:
|
||||
source = element
|
||||
return sub, dpi, source
|
||||
|
||||
def process(self, raw_name):
|
||||
raw_name = raw_name.replace("【", "[").replace("】", "]")
|
||||
raw_name = self.pre_process(raw_name)
|
||||
group = self.get_group(raw_name)
|
||||
match_obj = re.match(
|
||||
r"(.*|\[.*])( -? \d{1,3} |\[\d{1,3}]|\[\d{1,3}.?[vV]\d{1}]|[第第]\d{1,3}[话話集集]|\[\d{1,3}.?END])(.*)",
|
||||
raw_name,
|
||||
)
|
||||
name_season = self.pre_process(match_obj.group(1))
|
||||
name_season = self.second_process(match_obj.group(1))
|
||||
name, season_number, season_raw = self.season_process(name_season)
|
||||
name = self.name_process(name).strip()
|
||||
episode = int(re.findall(r"\d{1,3}", match_obj.group(2))[0])
|
||||
other = match_obj.group(3).strip()
|
||||
language = None
|
||||
return name, season_number, season_raw, episode
|
||||
sub, dpi, source= self.find_tags(other)
|
||||
return group, name, season_number, season_raw, episode, sub, dpi, source
|
||||
|
||||
def analyse(self, raw) -> Episode:
|
||||
try:
|
||||
info = Episode()
|
||||
info.group = self.get_group(raw)
|
||||
name, season, season_raw, episode = self.process(raw)
|
||||
info.title = name
|
||||
info.season_info.number = season
|
||||
info.season_info.raw = season_raw
|
||||
info.ep_info.number = episode
|
||||
|
||||
info.group, info.title, info.season_info.number,\
|
||||
info.season_info.raw, info.ep_info.number,\
|
||||
info.subtitle, info.dpi, info.source \
|
||||
= self.process(raw)
|
||||
return info
|
||||
except:
|
||||
logger.warning(f"ERROR match {raw}")
|
||||
@@ -129,8 +143,8 @@ if __name__ == "__main__":
|
||||
for name in f:
|
||||
if name != "":
|
||||
try:
|
||||
parser.get_group(name)
|
||||
# title, season, episode = parser.analyse(name)
|
||||
# parser.get_group(name)
|
||||
title, season, episode = parser.analyse(name)
|
||||
# print(name)
|
||||
# print(title)
|
||||
# print(season)
|
||||
|
||||
@@ -21,6 +21,7 @@ class Episode:
|
||||
self.raw: str = None
|
||||
self.number: int = None
|
||||
|
||||
|
||||
@property
|
||||
def title(self) -> str:
|
||||
return self.title_info.name
|
||||
@@ -34,5 +35,6 @@ class Episode:
|
||||
self.title_info = Episode.TitleInfo()
|
||||
self.season_info = Episode.SeasonInfo()
|
||||
self.ep_info = Episode.EpisodeInfo()
|
||||
self.format: str = None
|
||||
self.dpi: str = None
|
||||
self.subtitle: str = None
|
||||
self.source: str = None
|
||||
|
||||
@@ -17,7 +17,8 @@ DEFAULT_SETTINGS = {
|
||||
"rule_name_re": r"\:|\/|\.",
|
||||
"connect_retry_interval": 5,
|
||||
"debug_mode": True,
|
||||
"season_one_tag": True
|
||||
"season_one_tag": True,
|
||||
"data_version": 3.0
|
||||
}
|
||||
|
||||
ENV_TO_ATTR = {
|
||||
|
||||
@@ -46,6 +46,7 @@ class DownloadClient:
|
||||
rule_name = bangumi_name
|
||||
self.client.rss_set_rule(rule_name=rule_name, rule_def=rule)
|
||||
|
||||
|
||||
def rss_feed(self):
|
||||
try:
|
||||
self.client.rss_remove_item(item_path="Mikan_RSS")
|
||||
@@ -71,7 +72,19 @@ class DownloadClient:
|
||||
logger.info("Start collect past eps.")
|
||||
for info in bangumi_info:
|
||||
if info["download_past"]:
|
||||
FullSeasonGet(info["group"], info["title"], info["season"]).run()
|
||||
downloads = FullSeasonGet(
|
||||
info["group"],
|
||||
info["title"],
|
||||
info["season"],
|
||||
info["subtitle"],
|
||||
info["source"]
|
||||
).add_torrents_info()
|
||||
for download in downloads:
|
||||
self.client.torrents_add(
|
||||
urls=download["url"],
|
||||
save_path=download["save_path"],
|
||||
category="Bangumi"
|
||||
)
|
||||
info["download_past"] = False
|
||||
|
||||
def get_torrent_info(self):
|
||||
@@ -85,6 +98,12 @@ class DownloadClient:
|
||||
)
|
||||
logger.info(f"{path_name} >> {new_name}")
|
||||
|
||||
def delete_torrent(self, hash):
|
||||
self.client.torrents_delete(
|
||||
torrent_hash=hash
|
||||
)
|
||||
logger.info(f"Remove bad torrents.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
put = DownloadClient()
|
||||
|
||||
@@ -7,19 +7,26 @@ from bs4 import BeautifulSoup
|
||||
import logging
|
||||
|
||||
from conf import settings
|
||||
from const import FULL_SEASON_SUPPORT_GROUP
|
||||
from downloader import getClient
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class FullSeasonGet:
|
||||
def __init__(self, group, bangumi_name, season):
|
||||
self.torrents = None
|
||||
self.bangumi_name = bangumi_name
|
||||
self.group = group
|
||||
def __init__(self, group, bangumi_name, season, sub, source):
|
||||
self.bangumi_name = re.sub(settings.rule_name_re, " ", bangumi_name).strip()
|
||||
if group is not None:
|
||||
self.group = group
|
||||
else:
|
||||
self.group = ""
|
||||
self.season = season
|
||||
self.client = getClient()
|
||||
if sub is not None:
|
||||
self.subtitle = sub
|
||||
else:
|
||||
self.subtitle = ""
|
||||
if source is not None:
|
||||
self.source = source
|
||||
else:
|
||||
self.source = ""
|
||||
|
||||
def get_season_rss(self):
|
||||
if self.season == "S01":
|
||||
@@ -27,28 +34,25 @@ class FullSeasonGet:
|
||||
else:
|
||||
season = self.season
|
||||
season = requests.get(
|
||||
f"https://mikanani.me/RSS/Search?searchstr={self.group}+{self.bangumi_name}+{season}+1080"
|
||||
f"https://mikanani.me/RSS/Search?searchstr={self.group}+{self.bangumi_name}+{season}+{self.subtitle}+{self.source}+1080"
|
||||
)
|
||||
soup = BeautifulSoup(season.content, "xml")
|
||||
self.torrents = soup.find_all("enclosure")
|
||||
torrents = soup.find_all("enclosure")
|
||||
return torrents
|
||||
|
||||
def add_torrents(self):
|
||||
for torrent in self.torrents:
|
||||
self.client.torrents_add(
|
||||
urls=torrent["url"],
|
||||
save_path=str(
|
||||
os.path.join(
|
||||
def add_torrents_info(self):
|
||||
torrents = self.get_season_rss()
|
||||
downloads = []
|
||||
for torrent in torrents:
|
||||
download_info = {
|
||||
"url": torrent["url"],
|
||||
"save_path": os.path.join(
|
||||
settings.download_path,
|
||||
re.sub(settings.rule_name_re, " ", self.bangumi_name),
|
||||
self.bangumi_name,
|
||||
self.season)
|
||||
),
|
||||
category="Bangumi",
|
||||
)
|
||||
|
||||
def run(self):
|
||||
if self.group in FULL_SEASON_SUPPORT_GROUP:
|
||||
self.get_season_rss()
|
||||
self.add_torrents()
|
||||
}
|
||||
downloads.append(download_info)
|
||||
return downloads
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -66,6 +66,7 @@ class Renamer:
|
||||
self.client.rename_torrent_file(hash, path_name, new_name)
|
||||
rename_count += 1
|
||||
except:
|
||||
self.client.delete_torrent(hash)
|
||||
logger.warning(f"{name} rename fail")
|
||||
self.print_result(torrent_count, rename_count)
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ class RSSCollector:
|
||||
episode = self._simple_analyser.analyse(name)
|
||||
if episode:
|
||||
group, title, season, ep = episode.group, episode.title, episode.season_info, episode.ep_info
|
||||
sub, dpi, source = episode.subtitle, episode.dpi, episode.source
|
||||
for d in bangumi_data["bangumi_info"]:
|
||||
if d["title"] == title:
|
||||
break
|
||||
@@ -43,6 +44,9 @@ class RSSCollector:
|
||||
"title": title,
|
||||
"season": season.raw,
|
||||
"group": group,
|
||||
"subtitle": sub,
|
||||
"source": source,
|
||||
"dpi": dpi,
|
||||
"added": False,
|
||||
"download_past": download_past
|
||||
}
|
||||
|
||||
@@ -39,6 +39,12 @@ class QbDownloader:
|
||||
category=category,
|
||||
)
|
||||
|
||||
def torrents_delete(self, hash):
|
||||
return self._client.torrents_delete(
|
||||
delete_files=True,
|
||||
torrent_hashes=hash
|
||||
)
|
||||
|
||||
def torrents_rename_file(self, torrent_hash, old_path, new_path):
|
||||
self._client.torrents_rename_file(torrent_hash=torrent_hash, old_path=old_path, new_path=new_path)
|
||||
|
||||
|
||||
@@ -59,7 +59,8 @@
|
||||
"Dymy字幕組",
|
||||
"動漫國字幕組",
|
||||
"c.c動漫",
|
||||
"动漫国字幕组"
|
||||
"动漫国字幕组",
|
||||
"c.c动漫"
|
||||
],
|
||||
"type": 2
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user