[AnimeLab] Extract both English and Japanese all in one go, if available

This commit is contained in:
Mariusz Skoneczko 2020-04-23 21:03:20 +10:00
parent c3dca171d0
commit 2f6d029e96

View File

@ -94,7 +94,15 @@ class AnimeLabIE(AnimeLabBaseIE):
def _real_extract(self, url):
display_id = self._match_id(url)
webpage = self._download_webpage(url, display_id, 'Downloading requested URL')
# unfortunately we can get different URLs for the same formats
# e.g. if we are using a "free" account so no dubs available
# (so _remove_duplicate_formats is not effective)
# so we use a dictionary as a workaround
formats = {}
for language_option_url in ('https://www.animelab.com/player/%s/subtitles',
'https://www.animelab.com/player/%s/dubbed'):
actual_url = language_option_url % display_id
webpage = self._download_webpage(actual_url, display_id, 'Downloading URL ' + actual_url)
video_collection = self._parse_json(self._search_regex(r'new\s+?AnimeLabApp\.VideoCollection\s*?\((.*?)\);', webpage, 'AnimeLab VideoCollection'), display_id)
position = int_or_none(self._search_regex(r'playlistPosition\s*?=\s*?(\d+)', webpage, 'Playlist Position'))
@ -137,7 +145,6 @@ class AnimeLabIE(AnimeLabBaseIE):
season_number = int_or_none(season_data.get('seasonNumber'))
season_id = str_or_none(season_data.get('id'))
formats = []
for video_data in raw_data['videoList']:
current_video_list = {}
current_video_list['language'] = video_data.get('language', {}).get('languageCode')
@ -169,14 +176,14 @@ class AnimeLabIE(AnimeLabBaseIE):
ext = determine_ext(url)
if ext == 'm3u8':
m3u8_formats = self._extract_m3u8_formats(
url, video_id, m3u8_id=format_id, fatal=False)
formats.extend(m3u8_formats)
for format_ in self._extract_m3u8_formats(
url, video_id, m3u8_id=format_id, fatal=False):
formats[format_['format_id']] = format_
continue
elif ext == 'mpd':
mpd_formats = self._extract_mpd_formats(
url, video_id, mpd_id=format_id, fatal=False)
formats.extend(mpd_formats)
for format_ in self._extract_mpd_formats(
url, video_id, mpd_id=format_id, fatal=False):
formats[format_['format_id']] = format_
continue
current_format['url'] = url
@ -196,8 +203,9 @@ class AnimeLabIE(AnimeLabBaseIE):
current_format['height'] = height
current_format['format_id'] = format_id
formats.append(current_format)
formats[current_format['format_id']] = current_format
formats = list(formats.values())
self._sort_formats(formats)
return {