New TorrentInfo class.

This commit is contained in:
EstrellaXD
2023-05-16 22:10:20 +08:00
parent f6e08f61bc
commit e4d17ee60b
8 changed files with 62 additions and 34 deletions

View File

@@ -37,35 +37,33 @@ class RSSAnalyser:
rss_torrents = req.get_torrents(rss_link, "\\d+-\\d+")
return rss_torrents
def get_new_data_list(self, new_dict: dict, rss_link: str, _id: int, full_parse: bool = True) -> list:
def get_new_data_list(self, torrents: list, rss_link: str, _id: int, full_parse: bool = True) -> list:
new_data = []
with RequestContent() as req:
for raw_title, homepage in new_dict.items():
data = self._title_analyser.raw_parser(
raw=raw_title, rss_link=rss_link, _id=_id
)
if data and data.title_raw not in [i.title_raw for i in new_data]:
poster_link, mikan_title = req.get_mikan_info(homepage)
data.poster_link = poster_link
self.official_title_parser(data, mikan_title)
if not full_parse:
return [data]
new_data.append(data)
_id += 1
logger.debug(f"New title found: {data.official_title}")
for torrent in torrents:
data = self._title_analyser.raw_parser(
raw=torrent.name, rss_link=rss_link, _id=_id
)
if data and data.title_raw not in [i.title_raw for i in new_data]:
poster_link, mikan_title = torrent.poster_link, torrent.official_title
data.poster_link = poster_link
self.official_title_parser(data, mikan_title)
if not full_parse:
return [data]
new_data.append(data)
_id += 1
logger.debug(f"New title found: {data.official_title}")
return new_data
def rss_to_data(self, rss_link: str, full_parse: bool = True) -> list[BangumiData]:
rss_torrents = self.get_rss_torrents(rss_link, full_parse)
title_dict = {torrent.name: torrent.homepage for torrent in rss_torrents}
with BangumiDatabase() as database:
new_dict = database.match_list(title_dict, rss_link)
if not new_dict:
torrents_to_add = database.match_list(rss_torrents, rss_link)
if not torrents_to_add:
logger.debug("No new title found.")
return []
_id = database.gen_id()
# New List
new_data = self.get_new_data_list(new_dict, rss_link, _id, full_parse)
new_data = self.get_new_data_list(torrents_to_add, rss_link, _id, full_parse)
database.insert_list(new_data)
return new_data
@@ -75,4 +73,5 @@ class RSSAnalyser:
self.rss_to_data(rss_link)
except Exception as e:
logger.debug(e)
print(e)
logger.error("Failed to collect RSS info.")

View File