From b91377b6d75856558079ac1c18ed42cef3811079 Mon Sep 17 00:00:00 2001 From: Nasir Date: Mon, 3 May 2021 00:04:43 -0700 Subject: [PATCH] Added funimation show playlist extractor --- youtube_dl/extractor/extractors.py | 5 ++- youtube_dl/extractor/funimation.py | 51 +++++++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/youtube_dl/extractor/extractors.py b/youtube_dl/extractor/extractors.py index ac33cd996..527632432 100644 --- a/youtube_dl/extractor/extractors.py +++ b/youtube_dl/extractor/extractors.py @@ -418,7 +418,10 @@ from .frontendmasters import ( FrontendMastersCourseIE ) from .fujitv import FujiTVFODPlus7IE -from .funimation import FunimationIE +from .funimation import ( + FunimationIE, + FunimationShowPlaylistIE +) from .funk import FunkIE from .fusion import FusionIE from .gaia import GaiaIE diff --git a/youtube_dl/extractor/funimation.py b/youtube_dl/extractor/funimation.py index 8bbedca26..38bb4cce4 100644 --- a/youtube_dl/extractor/funimation.py +++ b/youtube_dl/extractor/funimation.py @@ -11,7 +11,8 @@ from ..utils import ( int_or_none, js_to_json, ExtractorError, - urlencode_postdata + urlencode_postdata, + urljoin ) @@ -152,3 +153,51 @@ class FunimationIE(InfoExtractor): 'season_id': title_data.get('seriesId'), 'formats': formats, } + + +class FunimationShowPlaylistIE(FunimationIE): + IE_NAME = 'funimation:playlist' + _VALID_URL = r'https?://(?:www\.)?funimation(?:\.com|now\.uk)/[a-z]{2}/shows/(?P[^/?#&]+)' + + _TESTS = [{ + 'url': 'https://www.funimation.com/en/shows/hacksign/', + 'info_dict': { + 'id': 90646, + 'title': '.hack//SIGN' + }, + 'playlist_count': 28, + 'params': { + 'skip_download': True, + }, + }] + + def _real_extract(self, url): + display_id = self._match_id(url) + + webpage = self._download_webpage(url, display_id) + title_data = self._parse_json(self._search_regex( + r'TITLE_DATA\s*=\s*({[^}]+})', + webpage, 'title data', default=''), + display_id, js_to_json, fatal=False) or {} + + items = self._download_json( + 'https://prod-api-funimationnow.dadcdigital.com/api/funimation/episodes/?limit=99999&title_id=%s' + % title_data.get('id'), display_id).get('items') + + vod_items = list(map(lambda k: + (k.get('mostRecentSvod') or k.get('mostRecentAvod')) + .get('item'), items)) + vod_items = sorted(vod_items, key=lambda k: k.get('episodeOrder')) + entries = [] + for vod_item in vod_items: + entries.append( + self.url_result(urljoin(url, vod_item.get('episodeSlug')), + 'Funimation', vod_item.get('episodeId'), + vod_item.get('episodeSlug'))) + + return { + '_type': 'playlist', + 'id': title_data.get('id'), + 'title': title_data.get('title'), + 'entries': entries, + }