From e760978756c0c9f5ff8e3a0d85a760d2a22252c5 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Sun, 22 Jan 2023 20:25:06 +0800 Subject: [PATCH 1/4] fix #3098 --- app/helper/db_helper.py | 5 ++--- app/subscribe.py | 29 ++++++++++++++++++++++------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/app/helper/db_helper.py b/app/helper/db_helper.py index 71545a7dfd..099d633841 100644 --- a/app/helper/db_helper.py +++ b/app/helper/db_helper.py @@ -778,9 +778,8 @@ def update_rss_movie_state(self, title=None, year=None, rssid=None, state='R'): "STATE": state }) else: - self._db.query(RSSMOVIES).filter( - RSSMOVIES.NAME == title, - RSSMOVIES.YEAR == str(year)).update( + self._db.query(RSSMOVIES).filter(RSSMOVIES.NAME == title, + RSSMOVIES.YEAR == str(year)).update( { "STATE": state }) diff --git a/app/subscribe.py b/app/subscribe.py index ba9ab03762..a6bab0cf62 100644 --- a/app/subscribe.py +++ b/app/subscribe.py @@ -663,9 +663,9 @@ def subscribe_search_movie(self, rssid=None, state='D'): if search_result: # 洗版 if over_edition: - if not self.update_subscribe_over_edition(rssid=rssid, media=search_result): - # 更新为继续订阅状态 - self.dbhelper.update_rss_movie_state(rssid=rssid, state='R') + self.update_subscribe_over_edition(rtype=search_result.type, + rssid=rssid, + media=search_result) else: self.finish_rss_subscribe(rssid=rssid, media=media_info) else: @@ -789,9 +789,9 @@ def subscribe_search_tv(self, rssid=None, state="D"): and (not no_exists or not no_exists.get(media_info.tmdb_id)): # 洗版 if over_edition: - if not self.update_subscribe_over_edition(rssid=rssid, media=search_result): - # 更新为继续订阅状态 - self.dbhelper.update_rss_tv_state(rssid=rssid, state='R') + self.update_subscribe_over_edition(rtype=media_info.type, + rssid=rssid, + media=search_result) else: # 完成订阅 self.finish_rss_subscribe(rssid=rssid, media=media_info) @@ -801,9 +801,22 @@ def subscribe_search_tv(self, rssid=None, state="D"): media_info=media_info, seasoninfo=no_exists.get(media_info.tmdb_id)) - def update_subscribe_over_edition(self, rssid, media): + def update_rss_state(self, rtype, rssid, state): + """ + 根据类型更新订阅状态 + :param rtype: 订阅类型 + :param rssid: 订阅ID + :param state: 状态 R/D/S + """ + if rtype == MediaType.MOVIE: + self.dbhelper.update_rss_movie_state(rssid=rssid, state=state) + else: + self.dbhelper.update_rss_tv_state(rssid=rssid, state=state) + + def update_subscribe_over_edition(self, rtype, rssid, media): """ 更新洗版订阅 + :param rtype: 订阅类型 :param rssid: 订阅ID :param media: 含订阅信息的媒体信息 :return 完成订阅返回True,否则返回False @@ -823,6 +836,8 @@ def update_subscribe_over_edition(self, rssid, media): # 完成洗版订阅 self.finish_rss_subscribe(rssid=rssid, media=media) return True + else: + self.update_rss_state(rtype=rtype, rssid=rssid, state='R') return False def check_subscribe_over_edition(self, rtype, rssid, res_order): From 8ff140df8464851cd65e2afa6b9296e8531062ad Mon Sep 17 00:00:00 2001 From: jxxghp Date: Sun, 22 Jan 2023 20:32:33 +0800 Subject: [PATCH 2/4] fix #3098 --- app/rss.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/rss.py b/app/rss.py index a7ca7c500f..9573f1008c 100644 --- a/app/rss.py +++ b/app/rss.py @@ -595,7 +595,8 @@ def __update_over_edition(download_item): if download_item.get_episode_list(): return updated_rss_torrents.append(download_item.rssid) - self.subscribe.update_subscribe_over_edition(rssid=download_item.rssid, + self.subscribe.update_subscribe_over_edition(rtype=download_item.type, + rssid=download_item.rssid, media=download_item) # 去重择优后开始添加下载 From 07953605c3a60c629fcfdfeed6429056ea0aa4c9 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Sun, 22 Jan 2023 21:02:18 +0800 Subject: [PATCH 3/4] media api --- app/media/media.py | 302 ++++++++++++++++++++++++++++++++++++++++++- app/media/scraper.py | 27 +--- 2 files changed, 301 insertions(+), 28 deletions(-) diff --git a/app/media/media.py b/app/media/media.py index e0d7ce5506..bf692352d3 100644 --- a/app/media/media.py +++ b/app/media/media.py @@ -936,6 +936,94 @@ def __get_tmdb_movie_detail(self, tmdbid, append_to_response=None): :param tmdbid: TMDB ID :return: TMDB信息 """ + """ + { + "adult": false, + "backdrop_path": "/r9PkFnRUIthgBp2JZZzD380MWZy.jpg", + "belongs_to_collection": { + "id": 94602, + "name": "穿靴子的猫(系列)", + "poster_path": "/anHwj9IupRoRZZ98WTBvHpTiE6A.jpg", + "backdrop_path": "/feU1DWV5zMWxXUHJyAIk3dHRQ9c.jpg" + }, + "budget": 90000000, + "genres": [ + { + "id": 16, + "name": "动画" + }, + { + "id": 28, + "name": "动作" + }, + { + "id": 12, + "name": "冒险" + }, + { + "id": 35, + "name": "喜剧" + }, + { + "id": 10751, + "name": "家庭" + }, + { + "id": 14, + "name": "奇幻" + } + ], + "homepage": "", + "id": 315162, + "imdb_id": "tt3915174", + "original_language": "en", + "original_title": "Puss in Boots: The Last Wish", + "overview": "时隔11年,臭屁自大又爱卖萌的猫大侠回来了!如今的猫大侠(安东尼奥·班德拉斯 配音),依旧幽默潇洒又不拘小节、数次“花式送命”后,九条命如今只剩一条,于是不得不请求自己的老搭档兼“宿敌”——迷人的软爪妞(萨尔玛·海耶克 配音)来施以援手来恢复自己的九条生命。", + "popularity": 8842.129, + "poster_path": "/rnn30OlNPiC3IOoWHKoKARGsBRK.jpg", + "production_companies": [ + { + "id": 33, + "logo_path": "/8lvHyhjr8oUKOOy2dKXoALWKdp0.png", + "name": "Universal Pictures", + "origin_country": "US" + }, + { + "id": 521, + "logo_path": "/kP7t6RwGz2AvvTkvnI1uteEwHet.png", + "name": "DreamWorks Animation", + "origin_country": "US" + } + ], + "production_countries": [ + { + "iso_3166_1": "US", + "name": "United States of America" + } + ], + "release_date": "2022-12-07", + "revenue": 260725470, + "runtime": 102, + "spoken_languages": [ + { + "english_name": "English", + "iso_639_1": "en", + "name": "English" + }, + { + "english_name": "Spanish", + "iso_639_1": "es", + "name": "Español" + } + ], + "status": "Released", + "tagline": "", + "title": "穿靴子的猫2", + "video": false, + "vote_average": 8.614, + "vote_count": 2291 + } + """ if not self.movie: return {} try: @@ -952,6 +1040,165 @@ def __get_tmdb_tv_detail(self, tmdbid, append_to_response=None): :param tmdbid: TMDB ID :return: TMDB信息 """ + """ + { + "adult": false, + "backdrop_path": "/uDgy6hyPd82kOHh6I95FLtLnj6p.jpg", + "created_by": [ + { + "id": 35796, + "credit_id": "5e84f06a3344c600153f6a57", + "name": "Craig Mazin", + "gender": 2, + "profile_path": "/uEhna6qcMuyU5TP7irpTUZ2ZsZc.jpg" + }, + { + "id": 1295692, + "credit_id": "5e84f03598f1f10016a985c0", + "name": "Neil Druckmann", + "gender": 2, + "profile_path": "/bVUsM4aYiHbeSYE1xAw2H5Z1ANU.jpg" + } + ], + "episode_run_time": [], + "first_air_date": "2023-01-15", + "genres": [ + { + "id": 18, + "name": "剧情" + }, + { + "id": 10765, + "name": "Sci-Fi & Fantasy" + }, + { + "id": 10759, + "name": "动作冒险" + } + ], + "homepage": "https://www.hbo.com/the-last-of-us", + "id": 100088, + "in_production": true, + "languages": [ + "en" + ], + "last_air_date": "2023-01-15", + "last_episode_to_air": { + "air_date": "2023-01-15", + "episode_number": 1, + "id": 2181581, + "name": "当你迷失在黑暗中", + "overview": "在一场全球性的流行病摧毁了文明之后,一个顽强的幸存者负责照顾一个 14 岁的小女孩,她可能是人类最后的希望。", + "production_code": "", + "runtime": 81, + "season_number": 1, + "show_id": 100088, + "still_path": "/aRquEWm8wWF1dfa9uZ1TXLvVrKD.jpg", + "vote_average": 8, + "vote_count": 33 + }, + "name": "最后生还者", + "next_episode_to_air": { + "air_date": "2023-01-22", + "episode_number": 2, + "id": 4071039, + "name": "虫草变异菌", + "overview": "", + "production_code": "", + "runtime": 55, + "season_number": 1, + "show_id": 100088, + "still_path": "/jkUtYTmeap6EvkHI4n0j5IRFrIr.jpg", + "vote_average": 10, + "vote_count": 1 + }, + "networks": [ + { + "id": 49, + "name": "HBO", + "logo_path": "/tuomPhY2UtuPTqqFnKMVHvSb724.png", + "origin_country": "US" + } + ], + "number_of_episodes": 9, + "number_of_seasons": 1, + "origin_country": [ + "US" + ], + "original_language": "en", + "original_name": "The Last of Us", + "overview": "不明真菌疫情肆虐之后的美国,被真菌感染的人都变成了可怕的怪物,乔尔(Joel)为了换回武器答应将小女孩儿艾莉(Ellie)送到指定地点,由此开始了两人穿越美国的漫漫旅程。", + "popularity": 5585.639, + "poster_path": "/nOY3VBFO0VnlN9nlRombnMTztyh.jpg", + "production_companies": [ + { + "id": 3268, + "logo_path": "/tuomPhY2UtuPTqqFnKMVHvSb724.png", + "name": "HBO", + "origin_country": "US" + }, + { + "id": 11073, + "logo_path": "/aCbASRcI1MI7DXjPbSW9Fcv9uGR.png", + "name": "Sony Pictures Television Studios", + "origin_country": "US" + }, + { + "id": 23217, + "logo_path": "/kXBZdQigEf6QiTLzo6TFLAa7jKD.png", + "name": "Naughty Dog", + "origin_country": "US" + }, + { + "id": 115241, + "logo_path": null, + "name": "The Mighty Mint", + "origin_country": "US" + }, + { + "id": 119645, + "logo_path": null, + "name": "Word Games", + "origin_country": "US" + }, + { + "id": 125281, + "logo_path": "/3hV8pyxzAJgEjiSYVv1WZ0ZYayp.png", + "name": "PlayStation Productions", + "origin_country": "US" + } + ], + "production_countries": [ + { + "iso_3166_1": "US", + "name": "United States of America" + } + ], + "seasons": [ + { + "air_date": "2023-01-15", + "episode_count": 9, + "id": 144593, + "name": "第 1 季", + "overview": "", + "poster_path": "/aUQKIpZZ31KWbpdHMCmaV76u78T.jpg", + "season_number": 1 + } + ], + "spoken_languages": [ + { + "english_name": "English", + "iso_639_1": "en", + "name": "English" + } + ], + "status": "Returning Series", + "tagline": "", + "type": "Scripted", + "vote_average": 8.924, + "vote_count": 601 + } + """ if not self.tv: return {} try: @@ -1026,6 +1273,30 @@ def get_tmdb_season_episodes_num(self, sea: int, tv_info=None, tmdbid=None): return int(season.get("episode_count")) return 0 + @staticmethod + def get_tmdb_directors_actors(tmdbinfo): + """ + 查询导演和演员 + :param tmdbinfo: TMDB元数据 + :return: 导演列表,演员列表 + """ + if not tmdbinfo: + return [], [] + _credits = tmdbinfo.get("credits") + directors = [] + actors = [] + for cast in _credits.get("cast") or []: + if not cast: + continue + if cast.get("known_for_department") == "Acting": + actors.append(cast) + for crew in _credits.get("crew") or []: + if not crew: + continue + if crew.get("job") == "Director": + directors.append(crew) + return directors, actors + def get_tmdb_en_title(self, media_info): """ 获取TMDB的英文名称 @@ -1059,14 +1330,41 @@ def get_movie_discover(self, page=1): 发现电影 """ if not self.movie: - return {} + return [] try: movies = self.movie.discover(page) + if movies: + return movies.get("results") + except Exception as e: + print(str(e)) + return [] + + def get_movie_similar(self, tmdbid, page=1): + """ + 查询类似电影 + """ + if not self.movie: + return [] + try: + movies = self.movie.similar(movie_id=tmdbid, page=page) or [] return movies except Exception as e: print(str(e)) return {} + def get_tv_similar(self, tmdbid, page=1): + """ + 查询类似电视剧 + """ + if not self.tv: + return [] + try: + tvs = self.tv.similar(tv_id=tmdbid, page=page) or [] + return tvs + except Exception as e: + print(str(e)) + return {} + @staticmethod def __search_engine(feature_name): """ @@ -1260,7 +1558,7 @@ def get_random_discover_backdrop(self): """ movies = self.get_movie_discover() if movies: - backdrops = [movie.get("backdrop_path") for movie in movies.get("results")] + backdrops = [movie.get("backdrop_path") for movie in movies] return TMDB_IMAGE_ORIGINAL_URL % backdrops[round(random.uniform(0, len(backdrops) - 1))] return "" diff --git a/app/media/scraper.py b/app/media/scraper.py index f08d2704b5..fbadeda1fb 100644 --- a/app/media/scraper.py +++ b/app/media/scraper.py @@ -54,7 +54,7 @@ def __gen_common_nfo(self, xoutline.appendChild(doc.createCDATASection(tmdbinfo.get("overview") or "")) if scraper_nfo.get("credits"): # 导演 - directors, actors = self.__get_tmdbinfo_directors_actors(tmdbinfo.get("credits")) + directors, actors = self.media.get_tmdb_directors_actors(tmdbinfo) if chinese: directors, actors = self.__gen_people_chinese_info(directors, actors, doubaninfo) for director in directors: @@ -514,28 +514,3 @@ def __match_people_in_douban(self, people, peoples_douban): if latin_match_res or (people_douban.get("name") == people_aka_name): return people_douban return None - - @staticmethod - def __get_tmdbinfo_directors_actors(tmdbinfo): - """ - 查询导演和演员 - :param tmdbinfo: TMDB元数据 - :return: 导演列表,演员列表 - """ - if not tmdbinfo: - return [], [] - directors = [] - actors = [] - casts = tmdbinfo.get("cast") or [] - for cast in casts: - if not cast: - continue - if cast.get("known_for_department") == "Acting": - actors.append(cast) - crews = tmdbinfo.get("crew") or [] - for crew in crews: - if not crew: - continue - if crew.get("job") == "Director": - directors.append(crew) - return directors, actors From 4e5e7ad5031360b4afad2ba7f790f968a4a78c0d Mon Sep 17 00:00:00 2001 From: jxxghp Date: Sun, 22 Jan 2023 21:09:04 +0800 Subject: [PATCH 4/4] fix #3098 --- app/filter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/filter.py b/app/filter.py index bd257240b7..0d0aefda15 100644 --- a/app/filter.py +++ b/app/filter.py @@ -89,7 +89,7 @@ def get_rule_first_order(self, rulegroup): """ if not rulegroup: rulegroup = self.get_rule_groups(default=True) - first_order = min([rule_info.get("pri") for rule_info in self.get_rules(groupid=rulegroup)] or [0]) + first_order = min([int(rule_info.get("pri")) for rule_info in self.get_rules(groupid=rulegroup)] or [0]) return 100 - first_order def check_rules(self, meta_info, rulegroup=None):