From ab7eea1e025cb7c14c719414ea87a60e137a9e8d Mon Sep 17 00:00:00 2001 From: Marks Date: Fri, 25 Nov 2022 20:16:57 -0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E5=B0=81=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scrapinglib/api.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/scrapinglib/api.py b/scrapinglib/api.py index dace413..d520e78 100644 --- a/scrapinglib/api.py +++ b/scrapinglib/api.py @@ -179,15 +179,19 @@ class Scraping: if 'source' in json_data and json_data['source'] == 'javdb': # search other sources other_sources = sources[sources.index('javdb') + 1:] - # If cover not found in other source, then skip using other sources using javdb cover - try: - json_data_other = self.searchAdult(number, other_sources) - if json_data_other is not None: - json_data['cover'] = json_data_other['cover'] - if self.debug: - print(f"[+]Find movie [{number}] cover on website '{json_data_other['cover']}'") - except: - pass + while other_sources: + # If cover not found in other source, then skip using other sources using javdb cover instead + try: + json_data_other = self.searchAdult(number, other_sources) + if json_data_other is not None and json_data_other['cover'] != '': + json_data['cover'] = json_data_other['cover'] + if self.debug: + print(f"[+]Find movie [{number}] cover on website '{json_data_other['cover']}'") + break + # check other sources + other_sources = sources[sources.index(json_data_other['source']) + 1:] + except: + pass # Return if data not found in all sources if not json_data: From e73eb6ae89427a737cc63693f50ce55507898b50 Mon Sep 17 00:00:00 2001 From: Marks Date: Fri, 25 Nov 2022 20:41:02 -0800 Subject: [PATCH 2/2] when no source --- scrapinglib/api.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/scrapinglib/api.py b/scrapinglib/api.py index d520e78..0a9c7fe 100644 --- a/scrapinglib/api.py +++ b/scrapinglib/api.py @@ -182,14 +182,17 @@ class Scraping: while other_sources: # If cover not found in other source, then skip using other sources using javdb cover instead try: - json_data_other = self.searchAdult(number, other_sources) - if json_data_other is not None and json_data_other['cover'] != '': - json_data['cover'] = json_data_other['cover'] + other_json_data = self.searchAdult(number, other_sources) + if other_json_data is not None and 'cover' in other_json_data and other_json_data['cover'] != '': + json_data['cover'] = other_json_data['cover'] if self.debug: - print(f"[+]Find movie [{number}] cover on website '{json_data_other['cover']}'") + print(f"[+]Find movie [{number}] cover on website '{other_json_data['cover']}'") + break + # 当不知道source为何时,只能停止搜索 + if 'source' not in other_json_data: break # check other sources - other_sources = sources[sources.index(json_data_other['source']) + 1:] + other_sources = sources[sources.index(other_json_data['source']) + 1:] except: pass