mirror of
https://github.com/EstrellaXD/Auto_Bangumi.git
synced 2026-04-09 21:49:57 +08:00
feat: update searcher
This commit is contained in:
@@ -8,7 +8,7 @@ h11==0.14.0
|
||||
idna==3.4
|
||||
pydantic~=1.10
|
||||
PySocks==1.7.1
|
||||
qbittorrent-api==2023.6.49
|
||||
qbittorrent-api==2023.9.53
|
||||
requests==2.31.0
|
||||
six==1.16.0
|
||||
sniffio==1.3.0
|
||||
|
||||
@@ -9,13 +9,13 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class SeasonCollector(DownloadClient):
|
||||
def collect_season(self, bangumi: Bangumi, link: str = None, limit: int = None):
|
||||
def collect_season(self, bangumi: Bangumi, link: str = None):
|
||||
logger.info(
|
||||
f"Start collecting {bangumi.official_title} Season {bangumi.season}..."
|
||||
)
|
||||
with SearchTorrent() as st:
|
||||
if not link:
|
||||
torrents = st.search_season(bangumi, limit=limit)
|
||||
torrents = st.search_season(bangumi)
|
||||
else:
|
||||
torrents = st.get_torrents(link, bangumi.filter.replace(",", "|"))
|
||||
if self.add_torrent(torrents, bangumi):
|
||||
|
||||
@@ -16,7 +16,7 @@ class RequestContent(RequestURL):
|
||||
self,
|
||||
_url: str,
|
||||
_filter: str = "|".join(settings.rss_parser.filter),
|
||||
limit: int = 100,
|
||||
limit: int = None,
|
||||
retry: int = 3,
|
||||
) -> list[Torrent]:
|
||||
soup = self.get_xml(_url, retry)
|
||||
|
||||
@@ -21,21 +21,24 @@ BangumiJSON: TypeAlias = str
|
||||
|
||||
class SearchTorrent(RequestContent, RSSAnalyser):
|
||||
def search_torrents(
|
||||
self, rss_item: RSSItem, limit: int = 5
|
||||
self, rss_item: RSSItem
|
||||
) -> list[Torrent]:
|
||||
torrents = self.get_torrents(rss_item.url, limit=limit)
|
||||
torrents = self.get_torrents(rss_item.url)
|
||||
return torrents
|
||||
|
||||
def analyse_keyword(self, keywords: list[str], site: str = "mikan") -> BangumiJSON:
|
||||
def analyse_keyword(self, keywords: list[str], site: str = "mikan", limit: int = 5) -> BangumiJSON:
|
||||
rss_item = search_url(site, keywords)
|
||||
torrents = self.search_torrents(rss_item)
|
||||
# yield for EventSourceResponse (Server Send)
|
||||
exist_list = []
|
||||
for torrent in torrents:
|
||||
if len(exist_list) >= limit:
|
||||
break
|
||||
bangumi = self.torrent_to_data(torrent=torrent, rss=rss_item)
|
||||
if bangumi and bangumi not in exist_list:
|
||||
exist_list.append(bangumi)
|
||||
bangumi.rss_link = self.special_url(bangumi, site).url
|
||||
special_link = self.special_url(bangumi, site).url
|
||||
if bangumi and special_link not in exist_list:
|
||||
bangumi.rss_link = special_link
|
||||
exist_list.append(special_link)
|
||||
yield json.dumps(bangumi.dict(), separators=(',', ':'))
|
||||
|
||||
@staticmethod
|
||||
@@ -44,7 +47,7 @@ class SearchTorrent(RequestContent, RSSAnalyser):
|
||||
url = search_url(site, keywords)
|
||||
return url
|
||||
|
||||
def search_season(self, data: Bangumi, site: str = "mikan", limit: int = None) -> list[Torrent]:
|
||||
def search_season(self, data: Bangumi, site: str = "mikan") -> list[Torrent]:
|
||||
rss_item = self.special_url(data, site)
|
||||
torrents = self.search_torrents(rss_item, limit=limit)
|
||||
torrents = self.search_torrents(rss_item)
|
||||
return [torrent for torrent in torrents if data.title_raw in torrent.name]
|
||||
@@ -69,3 +69,23 @@ def test_raw_parser():
|
||||
assert info.resolution == "720P"
|
||||
assert info.episode == 5
|
||||
assert info.season == 1
|
||||
|
||||
content = "【喵萌奶茶屋】★07月新番★[银砂糖师与黑妖精 ~ Sugar Apple Fairy Tale ~][13][1080p][简日双语][招募翻译]"
|
||||
info = raw_parser(content)
|
||||
assert info.group == "喵萌奶茶屋"
|
||||
assert info.title_zh == "银砂糖师与黑妖精"
|
||||
assert info.title_en == "~ Sugar Apple Fairy Tale ~"
|
||||
assert info.resolution == "1080p"
|
||||
assert info.episode == 13
|
||||
assert info.season == 1
|
||||
|
||||
content = "[星空字幕组&LoliHouse] 五等分的新娘∽ / Go-toubun no Hanayome ∽ 01 [WebRip 1080p HEVC-10bit AAC][简繁日内封字幕](检索用:暑假篇)"
|
||||
info = raw_parser(content)
|
||||
assert info.group == "星空字幕组&LoliHouse"
|
||||
assert info.title_zh == "五等分的新娘∽"
|
||||
assert info.title_jp == "Go-toubun no Hanayome ∽"
|
||||
assert info.resolution == "1080p"
|
||||
assert info.episode == 1
|
||||
assert info.season == 1
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user