fix bug
This commit is contained in:
parent
298df1fbf8
commit
a4a391f238
@ -1,6 +1,6 @@
|
|||||||
import re
|
import re
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List, Optional, Tuple, Set
|
from typing import List, Optional, Tuple, Set, Dict
|
||||||
|
|
||||||
from app.chain import ChainBase
|
from app.chain import ChainBase
|
||||||
from app.core import MediaInfo
|
from app.core import MediaInfo
|
||||||
@ -79,7 +79,7 @@ class CommonChain(ChainBase):
|
|||||||
]
|
]
|
||||||
"""
|
"""
|
||||||
# 已下载的项目
|
# 已下载的项目
|
||||||
downloaded_list: list = []
|
downloaded_list: List[Context] = []
|
||||||
|
|
||||||
def __download_torrent(_torrent: TorrentInfo) -> Tuple[Optional[Path], list]:
|
def __download_torrent(_torrent: TorrentInfo) -> Tuple[Optional[Path], list]:
|
||||||
"""
|
"""
|
||||||
@ -141,9 +141,9 @@ class CommonChain(ChainBase):
|
|||||||
userid=userid)
|
userid=userid)
|
||||||
return _hash
|
return _hash
|
||||||
|
|
||||||
def __update_seasons(tmdbid, need, current):
|
def __update_seasons(tmdbid: str, need: list, current: list) -> list:
|
||||||
"""
|
"""
|
||||||
更新need_tvs季数
|
更新need_tvs季数,返回剩余季数
|
||||||
"""
|
"""
|
||||||
need = list(set(need).difference(set(current)))
|
need = list(set(need).difference(set(current)))
|
||||||
for cur in current:
|
for cur in current:
|
||||||
@ -154,9 +154,9 @@ class CommonChain(ChainBase):
|
|||||||
need_tvs.pop(tmdbid)
|
need_tvs.pop(tmdbid)
|
||||||
return need
|
return need
|
||||||
|
|
||||||
def __update_episodes(tmdbid, seq, need, current):
|
def __update_episodes(tmdbid: str, seq: int, need: list, current: set) -> list:
|
||||||
"""
|
"""
|
||||||
更新need_tvs集数
|
更新need_tvs集数,返回剩余集数
|
||||||
"""
|
"""
|
||||||
need = list(set(need).difference(set(current)))
|
need = list(set(need).difference(set(current)))
|
||||||
if need:
|
if need:
|
||||||
@ -167,7 +167,7 @@ class CommonChain(ChainBase):
|
|||||||
need_tvs.pop(tmdbid)
|
need_tvs.pop(tmdbid)
|
||||||
return need
|
return need
|
||||||
|
|
||||||
def __get_season_episodes(tmdbid, season):
|
def __get_season_episodes(tmdbid: str, season: int) -> int:
|
||||||
"""
|
"""
|
||||||
获取需要的季的集数
|
获取需要的季的集数
|
||||||
"""
|
"""
|
||||||
@ -186,7 +186,7 @@ class CommonChain(ChainBase):
|
|||||||
# 电视剧整季匹配
|
# 电视剧整季匹配
|
||||||
if need_tvs:
|
if need_tvs:
|
||||||
# 先把整季缺失的拿出来,看是否刚好有所有季都满足的种子
|
# 先把整季缺失的拿出来,看是否刚好有所有季都满足的种子
|
||||||
need_seasons = {}
|
need_seasons: Dict[str, list] = {}
|
||||||
for need_tmdbid, need_tv in need_tvs.items():
|
for need_tmdbid, need_tv in need_tvs.items():
|
||||||
for tv in need_tv:
|
for tv in need_tv:
|
||||||
if not tv:
|
if not tv:
|
||||||
@ -223,6 +223,7 @@ class CommonChain(ChainBase):
|
|||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
download_id = __download(context)
|
download_id = __download(context)
|
||||||
|
|
||||||
if download_id:
|
if download_id:
|
||||||
# 更新仍需季集
|
# 更新仍需季集
|
||||||
need_season = __update_seasons(tmdbid=need_tmdbid,
|
need_season = __update_seasons(tmdbid=need_tmdbid,
|
||||||
|
@ -83,8 +83,8 @@ class DoubanSyncChain(ChainBase):
|
|||||||
logger.warn(f'{mediainfo.get_title_string()} 未搜索到资源')
|
logger.warn(f'{mediainfo.get_title_string()} 未搜索到资源')
|
||||||
continue
|
continue
|
||||||
# 自动下载
|
# 自动下载
|
||||||
_, lefts = self.common.batch_download(contexts=contexts, need_tvs=no_exists)
|
downloads, lefts = self.common.batch_download(contexts=contexts, need_tvs=no_exists)
|
||||||
if not lefts:
|
if downloads and not lefts:
|
||||||
# 全部下载完成
|
# 全部下载完成
|
||||||
logger.info(f'{mediainfo.get_title_string()} 下载完成')
|
logger.info(f'{mediainfo.get_title_string()} 下载完成')
|
||||||
else:
|
else:
|
||||||
|
@ -105,8 +105,8 @@ class SubscribeChain(ChainBase):
|
|||||||
logger.warn(f'{subscribe.keyword or subscribe.name} 未搜索到资源')
|
logger.warn(f'{subscribe.keyword or subscribe.name} 未搜索到资源')
|
||||||
continue
|
continue
|
||||||
# 自动下载
|
# 自动下载
|
||||||
_, lefts = self.common.batch_download(contexts=contexts, need_tvs=no_exists)
|
downloads, lefts = self.common.batch_download(contexts=contexts, need_tvs=no_exists)
|
||||||
if not lefts:
|
if downloads and not lefts:
|
||||||
# 全部下载完成
|
# 全部下载完成
|
||||||
logger.info(f'{mediainfo.get_title_string()} 下载完成,完成订阅')
|
logger.info(f'{mediainfo.get_title_string()} 下载完成,完成订阅')
|
||||||
self.subscribes.delete(subscribe.id)
|
self.subscribes.delete(subscribe.id)
|
||||||
@ -195,8 +195,8 @@ class SubscribeChain(ChainBase):
|
|||||||
logger(f'{mediainfo.get_title_string()} 匹配完成,共匹配到{len(_match_context)}个资源')
|
logger(f'{mediainfo.get_title_string()} 匹配完成,共匹配到{len(_match_context)}个资源')
|
||||||
if _match_context:
|
if _match_context:
|
||||||
# 批量择优下载
|
# 批量择优下载
|
||||||
_, lefts = self.common.batch_download(contexts=_match_context, need_tvs=no_exists)
|
downloads, lefts = self.common.batch_download(contexts=_match_context, need_tvs=no_exists)
|
||||||
if not lefts:
|
if downloads and not lefts:
|
||||||
# 全部下载完成
|
# 全部下载完成
|
||||||
logger.info(f'{mediainfo.get_title_string()} 下载完成,完成订阅')
|
logger.info(f'{mediainfo.get_title_string()} 下载完成,完成订阅')
|
||||||
self.subscribes.delete(subscribe.id)
|
self.subscribes.delete(subscribe.id)
|
||||||
|
@ -128,7 +128,24 @@ class UserMessageChain(ChainBase):
|
|||||||
userid=userid)
|
userid=userid)
|
||||||
return
|
return
|
||||||
# 批量下载
|
# 批量下载
|
||||||
self.common.batch_download(contexts=cache_list, need_tvs=no_exists, userid=userid)
|
downloads, lefts = self.common.batch_download(contexts=cache_list,
|
||||||
|
need_tvs=no_exists,
|
||||||
|
userid=userid)
|
||||||
|
if downloads and not lefts:
|
||||||
|
# 全部下载完成
|
||||||
|
logger.info(f'{self._current_media.get_title_string()} 下载完成')
|
||||||
|
else:
|
||||||
|
# 未完成下载
|
||||||
|
logger.info(f'{self._current_media.get_title_string()} 未下载未完整,添加订阅 ...')
|
||||||
|
# 添加订阅
|
||||||
|
state, msg = self.subscribes.add(self._current_media,
|
||||||
|
season=self._current_meta.begin_season)
|
||||||
|
if state:
|
||||||
|
# 订阅成功
|
||||||
|
self.common.post_message(
|
||||||
|
title=f"{self._current_media.get_title_string()} 已添加订阅",
|
||||||
|
text=f"用户:{userid}",
|
||||||
|
image=self._current_media.get_message_image())
|
||||||
else:
|
else:
|
||||||
# 下载种子
|
# 下载种子
|
||||||
torrent: TorrentInfo = cache_list[int(text) - 1]
|
torrent: TorrentInfo = cache_list[int(text) - 1]
|
||||||
|
@ -279,7 +279,7 @@ class MediaInfo(object):
|
|||||||
# 本体
|
# 本体
|
||||||
self.douban_info = info
|
self.douban_info = info
|
||||||
# 豆瓣ID
|
# 豆瓣ID
|
||||||
self.douban_id = info.get("id")
|
self.douban_id = str(info.get("id"))
|
||||||
# 评分
|
# 评分
|
||||||
if not self.vote_average:
|
if not self.vote_average:
|
||||||
rating = info.get('rating')
|
rating = info.get('rating')
|
||||||
@ -350,7 +350,7 @@ class MediaInfo(object):
|
|||||||
返回背景图片地址
|
返回背景图片地址
|
||||||
"""
|
"""
|
||||||
if self.backdrop_path:
|
if self.backdrop_path:
|
||||||
return self.backdrop_path
|
return self.backdrop_path.replace("original", "w500")
|
||||||
return default or ""
|
return default or ""
|
||||||
|
|
||||||
def get_message_image(self, default: bool = None):
|
def get_message_image(self, default: bool = None):
|
||||||
@ -358,7 +358,7 @@ class MediaInfo(object):
|
|||||||
返回消息图片地址
|
返回消息图片地址
|
||||||
"""
|
"""
|
||||||
if self.backdrop_path:
|
if self.backdrop_path:
|
||||||
return self.backdrop_path
|
return self.backdrop_path.replace("original", "w500")
|
||||||
return self.get_poster_image(default=default)
|
return self.get_poster_image(default=default)
|
||||||
|
|
||||||
def get_poster_image(self, default: bool = None):
|
def get_poster_image(self, default: bool = None):
|
||||||
@ -366,7 +366,7 @@ class MediaInfo(object):
|
|||||||
返回海报图片地址
|
返回海报图片地址
|
||||||
"""
|
"""
|
||||||
if self.poster_path:
|
if self.poster_path:
|
||||||
return self.poster_path
|
return self.poster_path.replace("original", "w500")
|
||||||
return default or ""
|
return default or ""
|
||||||
|
|
||||||
def get_title_string(self):
|
def get_title_string(self):
|
||||||
|
@ -167,8 +167,6 @@ class Telegram(metaclass=Singleton):
|
|||||||
|
|
||||||
# 发送图文消息
|
# 发送图文消息
|
||||||
if image:
|
if image:
|
||||||
# 转换TMDB图片质量
|
|
||||||
image = image.replace("original", "w500")
|
|
||||||
res = request.get_res("https://api.telegram.org/bot%s/sendPhoto?" % self._telegram_token + urlencode(
|
res = request.get_res("https://api.telegram.org/bot%s/sendPhoto?" % self._telegram_token + urlencode(
|
||||||
{"chat_id": chat_id, "photo": image, "caption": caption, "parse_mode": "Markdown"}))
|
{"chat_id": chat_id, "photo": image, "caption": caption, "parse_mode": "Markdown"}))
|
||||||
if __res_parse(res):
|
if __res_parse(res):
|
||||||
|
@ -143,7 +143,7 @@ class TmdbCache(metaclass=Singleton):
|
|||||||
if cache_year:
|
if cache_year:
|
||||||
cache_year = cache_year[:4]
|
cache_year = cache_year[:4]
|
||||||
self._meta_data[self.__get_key(meta)] = {
|
self._meta_data[self.__get_key(meta)] = {
|
||||||
"id": info.get("id"),
|
"id": str(info.get("id")),
|
||||||
"type": info.get("media_type"),
|
"type": info.get("media_type"),
|
||||||
"year": cache_year,
|
"year": cache_year,
|
||||||
"title": cache_title,
|
"title": cache_title,
|
||||||
|
@ -15,13 +15,13 @@ if __name__ == '__main__':
|
|||||||
# 测试名称识别
|
# 测试名称识别
|
||||||
suite.addTest(MetaInfoTest('test_metainfo'))
|
suite.addTest(MetaInfoTest('test_metainfo'))
|
||||||
# 测试媒体识别
|
# 测试媒体识别
|
||||||
suite.addTest(RecognizeTest('test_recognize'))
|
# suite.addTest(RecognizeTest('test_recognize'))
|
||||||
# 测试CookieCloud同步
|
# 测试CookieCloud同步
|
||||||
suite.addTest(CookieCloudTest('test_cookiecloud'))
|
# suite.addTest(CookieCloudTest('test_cookiecloud'))
|
||||||
# 测试文件转移
|
# 测试文件转移
|
||||||
# suite.addTest(TransferTest('test_transfer'))
|
# suite.addTest(TransferTest('test_transfer'))
|
||||||
# 测试豆瓣同步
|
# 测试豆瓣同步
|
||||||
# suite.addTest(DoubanSyncTest('test_doubansync'))
|
suite.addTest(DoubanSyncTest('test_doubansync'))
|
||||||
|
|
||||||
# 运行测试
|
# 运行测试
|
||||||
runner = unittest.TextTestRunner()
|
runner = unittest.TextTestRunner()
|
||||||
|
@ -12,6 +12,6 @@ class DoubanSyncTest(TestCase):
|
|||||||
def tearDown(self) -> None:
|
def tearDown(self) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def test_doubansync(self):
|
@staticmethod
|
||||||
result = DoubanSyncChain().process()
|
def test_doubansync():
|
||||||
self.assertTrue(result[0])
|
DoubanSyncChain().process()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user