From b91377b6d75856558079ac1c18ed42cef3811079 Mon Sep 17 00:00:00 2001 From: Nasir Date: Mon, 3 May 2021 00:04:43 -0700 Subject: [PATCH 1/4] 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, + } From bc85e70db0cd57fab723a9ee45f6bdfbbf540b0f Mon Sep 17 00:00:00 2001 From: Nasir Date: Tue, 4 May 2021 14:35:53 -0700 Subject: [PATCH 2/4] Make lang code optional and add a only_matching test --- youtube_dl/extractor/funimation.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/youtube_dl/extractor/funimation.py b/youtube_dl/extractor/funimation.py index 38bb4cce4..b5c74e2e8 100644 --- a/youtube_dl/extractor/funimation.py +++ b/youtube_dl/extractor/funimation.py @@ -157,10 +157,10 @@ class FunimationIE(InfoExtractor): class FunimationShowPlaylistIE(FunimationIE): IE_NAME = 'funimation:playlist' - _VALID_URL = r'https?://(?:www\.)?funimation(?:\.com|now\.uk)/[a-z]{2}/shows/(?P[^/?#&]+)' + _VALID_URL = r'https?://(?:www\.)?funimation(?:\.com|now\.uk)/(?:[^/]+/)?shows/(?P[^/?#&]+)' _TESTS = [{ - 'url': 'https://www.funimation.com/en/shows/hacksign/', + 'url': 'https://www.funimation.com/shows/hacksign/', 'info_dict': { 'id': 90646, 'title': '.hack//SIGN' @@ -169,6 +169,10 @@ class FunimationShowPlaylistIE(FunimationIE): 'params': { 'skip_download': True, }, + }, { + # with lang code + 'url': 'https://www.funimation.com/en/shows/hacksign/', + 'only_matching': True, }] def _real_extract(self, url): From e2a4c61afce18a5c072b345f043e7569bc55b506 Mon Sep 17 00:00:00 2001 From: Nasir Date: Tue, 4 May 2021 14:45:02 -0700 Subject: [PATCH 3/4] Add UK site URL only_matching test --- youtube_dl/extractor/funimation.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/youtube_dl/extractor/funimation.py b/youtube_dl/extractor/funimation.py index b5c74e2e8..c2e102a91 100644 --- a/youtube_dl/extractor/funimation.py +++ b/youtube_dl/extractor/funimation.py @@ -169,6 +169,9 @@ class FunimationShowPlaylistIE(FunimationIE): 'params': { 'skip_download': True, }, + }, { + 'url': 'https://www.funimationnow.uk/shows/puzzle-dragons-x/', + 'only_matching': True, }, { # with lang code 'url': 'https://www.funimation.com/en/shows/hacksign/', From 74c3ddbfef19f8d4aaf6ebb452f1b57c0127000f Mon Sep 17 00:00:00 2001 From: Nasir Date: Thu, 20 May 2021 18:55:28 -0700 Subject: [PATCH 4/4] Prevent playlist from matching individual episode URL --- youtube_dl/extractor/funimation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/youtube_dl/extractor/funimation.py b/youtube_dl/extractor/funimation.py index 5a105614e..f4dce6d63 100644 --- a/youtube_dl/extractor/funimation.py +++ b/youtube_dl/extractor/funimation.py @@ -161,7 +161,7 @@ class FunimationIE(InfoExtractor): class FunimationShowPlaylistIE(FunimationIE): IE_NAME = 'funimation:playlist' - _VALID_URL = r'https?://(?:www\.)?funimation(?:\.com|now\.uk)/(?:[^/]+/)?shows/(?P[^/?#&]+)' + _VALID_URL = r'https?://(?:www\.)?funimation(?:\.com|now\.uk)/(?:[^/]+/)?shows/(?P[^/?#&]+)/?$' _TESTS = [{ 'url': 'https://www.funimation.com/shows/hacksign/',