You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Перестал работать api первой версии, переделал код в anilibria.py чтобы работать с api_v3, но почему-то торрт пытается спарсить торрент с ссылки формата апи/ссылка для скачивания, хотя он уже скачан с правильной ссылки. Я не настолько хорошо разобрался в коде чтобы диагностировать проблему, так что было бы неплохо если кто-нибудь смог бы пофиксить остальное
Код anilibria.py, исправленный под новый api:
importrefromcollectionsimportdefaultdictfromtypingimportList, Dict, Optional, Tuplefrom ..base_trackerimportGenericPublicTrackerREGEX_QUALITY=re.compile(r".+\[(.+)\]")
# This regex is used to remove every non-word character or underscore from quality string.REGEX_NON_WORD=re.compile(r'[\W_]')
REGEX_RANGE=re.compile(r'\d+-\d+')
HOST: str='https://www.anilibria.tv'API_URL: str='https://api.anilibria.tv/v3/title'classAnilibriaTracker(GenericPublicTracker):
"""This class implements .torrent files downloads for https://www.anilibria.tv tracker."""alias: str='anilibria.tv'test_urls: List[str] = [
'https://www.anilibria.tv/release/sword-art-online-alicization.html',
]
def__init__(self, quality_prefs: List[str] =None):
super(AnilibriaTracker, self).__init__()
ifquality_prefsisNone:
quality_prefs= ['HDTVRip 1080p', 'HDTVRip 720p', 'WEBRip 720p']
self.quality_prefs=quality_prefsdefget_download_link(self, url: str) ->str:
"""Tries to find .torrent file download link at forum thread page and return that one."""available_qualities=self.find_available_qualities(url)
self.log_debug(f"Available in qualities: {', '.join(available_qualities)}")
ifavailable_qualities:
quality_prefs= []
forprefinself.quality_prefs:
pref=self.sanitize_quality(pref)
ifprefnotinquality_prefs:
quality_prefs.append(pref)
preferred_qualities= [qualityforqualityinquality_prefsifqualityinavailable_qualities]
ifnotpreferred_qualities:
self.log_info(
'Torrent is not available in preferred qualities: 'f"{', '.join(quality_prefs)}")
quality, link=next(iter(available_qualities.items()))
self.log_info(f'Fallback to `{quality}` quality ...')
returnlinkelse:
target_quality=preferred_qualities[0]
self.log_debug(f'Trying to get torrent in `{target_quality}` quality ...')
returnavailable_qualities[target_quality]
return''deffind_available_qualities(self, url: str) ->Dict[str, str]:
"""Tries to find .torrent download links in `Release` model Returns a dict where key is quality and value is .torrent download link. :param url: url to forum thread page """code=self.extract_release_code(url)
json=self.api_get_release_by_code(code)
ifnotjson.get('status', False):
self.log_error(f'Failed to get release `{code}` from API')
return {}
available_qualities= {}
torrents=json['torrents']['list']
series2torrents=defaultdict(list)
# a release can consist of several torrents:# 1. episode ranges (different qualities),# 2. single episodes (different qualities) - a release is just aired,# 3. trailers,# 4. OVAs# we are trying to recognize `1` and `2`.fortorrentintorrents:
ifREGEX_RANGE.match(torrent['episodes']['string']) ortorrent['episodes']['string'] ==json['torrents']['episodes']['string']:
series2torrents[torrent['episodes']['string']].append(torrent)
# some releases can be broken into several .torrent files, e.g. 1-20 and 21-41 - take the last onesorted_series=sorted(series2torrents.keys(), key=self.to_tuple, reverse=True)
ifnotsorted_series:
return {}
fortorrentinseries2torrents[sorted_series[0]]:
quality=self.sanitize_quality(torrent['quality']['string'])
available_qualities[quality] =HOST+torrent['url']
returnavailable_qualities@staticmethoddefextract_release_code(url: str) ->str:
"""Extracts anilibria release code from forum thread page. Example: `extract_release_code('https://www.anilibria.tv/release/kabukichou-sherlock.html')` -> 'kabukichou-sherlock' :param url: url to forum thread page """returnurl.replace(HOST+'/release/', '').replace('.html', '')
@staticmethoddefsanitize_quality(quality_str: Optional[str]) ->str:
"""Turn passed quality_str into common format in order to simplify comparison. Examples: * `sanitize_quality('WEBRip 1080p')` -> 'webrip1080p' * `sanitize_quality('WEBRip-1080p')` -> 'webrip1080p' * `sanitize_quality('WEBRip_1080p')` -> 'webrip1080p' * `sanitize_quality('')` -> '' * `sanitize_quality(None)` -> '' :param quality_str: """ifquality_str:
returnREGEX_NON_WORD.sub('', quality_str).lower()
return''@staticmethoddefto_tuple(range_str: str) ->Tuple[int, ...]:
""" Turn passed range_str into tuple of integers. Examples: * `to_tuple('1-10')` -> (1, 10) :param range_str: series range string """returntuple(map(int, range_str.split('-')))
defapi_get_release_by_code(self, code: str) ->dict:
""" Get release json by passed `code` from Anilibria API. :param code: release code """response=self.get_response(API_URL+'?code='+code, as_soup=False)
ifnotresponse:
return {}
returnresponse.json()
The text was updated successfully, but these errors were encountered:
Перестал работать api первой версии, переделал код в anilibria.py чтобы работать с api_v3, но почему-то торрт пытается спарсить торрент с ссылки формата апи/ссылка для скачивания, хотя он уже скачан с правильной ссылки. Я не настолько хорошо разобрался в коде чтобы диагностировать проблему, так что было бы неплохо если кто-нибудь смог бы пофиксить остальное
Код anilibria.py, исправленный под новый api:
The text was updated successfully, but these errors were encountered: