From 9c2be90e27e7f25363d7dbc1848cc19dcb49c13b Mon Sep 17 00:00:00 2001 From: Daniel Heath Date: Sat, 23 Jun 2018 09:51:37 +1000 Subject: [PATCH 1/6] [iview] Add playlist support --- youtube_dl/extractor/abc.py | 55 ++++++++++++++++++++++++++++++ youtube_dl/extractor/extractors.py | 1 + 2 files changed, 56 insertions(+) diff --git a/youtube_dl/extractor/abc.py b/youtube_dl/extractor/abc.py index 4ac323bf6..314c4cb50 100644 --- a/youtube_dl/extractor/abc.py +++ b/youtube_dl/extractor/abc.py @@ -103,6 +103,61 @@ class ABCIE(InfoExtractor): } +class ABCIViewShowIE(InfoExtractor): + IE_NAME = 'abc.net.au:iview:show' + _VALID_URL = r'https?://iview\.abc\.net\.au/(?:[^/]+/)*show/(?P[^/?#]+)/?' + _GEO_COUNTRIES = ['AU'] + + # ABC iview programs are normally available for 14 days only. + _TESTS = [{ + 'url': 'https://iview.abc.net.au/show/sarah-and-duck/', + 'info_dict': { + 'id': 'sarah-and-duck', + 'title': 'Sarah And Duck', + 'description': 'Sarah is a 7 year old girl with big eyes and a green hat, who lives with her quacky, flappy, slightly manic, but endearing best friend, Duck.', + }, + 'playlist_count': 14, + 'params': { + 'skip_download': True, + }, + }] + + def _real_extract(self, url): + show_id = self._match_id(url) + show_data = self._download_json('https://api.iview.abc.net.au/v2/show/' + show_id, show_id) + + title = show_data.get('displayTitle') or show_data.get('title') or show_id + description = show_data.get('description') + + entries = [] + for s in show_data['_embedded']['seriesList']: + series_id = s.get('id') + if series_id: + url = 'https://api.iview.abc.net.au/v2/series/' + show_id + '/' + series_id + groupList = self._download_json( + url, + series_id, + fatal=False, + errnote="Failed to fetch series ID '%s' from '%s'" % (series_id, url) + ) + if type(groupList) is not list: + groupList = [groupList] + + for series in groupList: + for ep in series.get('_embedded', {}).get('videoEpisodes'): + path = ep.get('_links', {}).get('deeplink', {}).get('href') + if path: + entries.append(self.url_result('https://iview.abc.net.au' + path)) + + return { + '_type': 'playlist', + 'id': show_id, + 'title': title, + 'description': description, + 'entries': entries, + } + + class ABCIViewIE(InfoExtractor): IE_NAME = 'abc.net.au:iview' _VALID_URL = r'https?://iview\.abc\.net\.au/(?:[^/]+/)*video/(?P[^/?#]+)' diff --git a/youtube_dl/extractor/extractors.py b/youtube_dl/extractor/extractors.py index 3037b5a45..2a4bc9f78 100644 --- a/youtube_dl/extractor/extractors.py +++ b/youtube_dl/extractor/extractors.py @@ -4,6 +4,7 @@ from __future__ import unicode_literals from .abc import ( ABCIE, ABCIViewIE, + ABCIViewShowIE, ) from .abcnews import ( AbcNewsIE, From 4bafc5ec3c972c814852297c885e991af7bb6f50 Mon Sep 17 00:00:00 2001 From: Daniel Heath Date: Tue, 5 Mar 2019 21:47:53 +1100 Subject: [PATCH 2/6] Fixup overzealous regex matching a single episode URL --- youtube_dl/extractor/abc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/youtube_dl/extractor/abc.py b/youtube_dl/extractor/abc.py index 314c4cb50..392d32e6c 100644 --- a/youtube_dl/extractor/abc.py +++ b/youtube_dl/extractor/abc.py @@ -105,7 +105,7 @@ class ABCIE(InfoExtractor): class ABCIViewShowIE(InfoExtractor): IE_NAME = 'abc.net.au:iview:show' - _VALID_URL = r'https?://iview\.abc\.net\.au/(?:[^/]+/)*show/(?P[^/?#]+)/?' + _VALID_URL = r'https?://iview\.abc\.net\.au/(?:[^/]+/)*show/(?P[^/?#]+)/?$' _GEO_COUNTRIES = ['AU'] # ABC iview programs are normally available for 14 days only. From 92d90f65f561a87cd0aa0914ba8697ad36319ff7 Mon Sep 17 00:00:00 2001 From: davidphood <30076632+davidphood@users.noreply.github.com> Date: Fri, 26 Apr 2019 12:34:07 +1000 Subject: [PATCH 3/6] Accept suggested change by @davidphood Co-Authored-By: DanielHeath --- youtube_dl/extractor/abc.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/youtube_dl/extractor/abc.py b/youtube_dl/extractor/abc.py index 392d32e6c..023fd55ec 100644 --- a/youtube_dl/extractor/abc.py +++ b/youtube_dl/extractor/abc.py @@ -105,7 +105,7 @@ class ABCIE(InfoExtractor): class ABCIViewShowIE(InfoExtractor): IE_NAME = 'abc.net.au:iview:show' - _VALID_URL = r'https?://iview\.abc\.net\.au/(?:[^/]+/)*show/(?P[^/?#]+)/?$' + _VALID_URL = r'https?://iview\.abc\.net\.au/(?:[^/]+/)*show/(?P[^/?#]+)/?' _GEO_COUNTRIES = ['AU'] # ABC iview programs are normally available for 14 days only. @@ -122,6 +122,10 @@ class ABCIViewShowIE(InfoExtractor): }, }] +@classmethod +def suitable(cls, url): + return False if ABCIViewIE.suitable(url) else super(ABCIViewShowIE, cls).suitable(url) + def _real_extract(self, url): show_id = self._match_id(url) show_data = self._download_json('https://api.iview.abc.net.au/v2/show/' + show_id, show_id) From da2be542f26df74bcdf9643c020ab06ba993d096 Mon Sep 17 00:00:00 2001 From: Daniel Heath Date: Thu, 2 May 2019 22:36:55 +1000 Subject: [PATCH 4/6] Fixup indentation --- youtube_dl/extractor/abc.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/youtube_dl/extractor/abc.py b/youtube_dl/extractor/abc.py index 023fd55ec..67d1b52b2 100644 --- a/youtube_dl/extractor/abc.py +++ b/youtube_dl/extractor/abc.py @@ -122,9 +122,9 @@ class ABCIViewShowIE(InfoExtractor): }, }] -@classmethod -def suitable(cls, url): - return False if ABCIViewIE.suitable(url) else super(ABCIViewShowIE, cls).suitable(url) + @classmethod + def suitable(cls, url): + return False if ABCIViewIE.suitable(url) else super(ABCIViewShowIE, cls).suitable(url) def _real_extract(self, url): show_id = self._match_id(url) From 8f43270668b0c74bb64a0e100f073f079b563006 Mon Sep 17 00:00:00 2001 From: Daniel Heath Date: Fri, 16 Aug 2019 17:14:08 +1000 Subject: [PATCH 5/6] Update from code review --- youtube_dl/extractor/abc.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/youtube_dl/extractor/abc.py b/youtube_dl/extractor/abc.py index 67d1b52b2..2c9a7a5e0 100644 --- a/youtube_dl/extractor/abc.py +++ b/youtube_dl/extractor/abc.py @@ -128,7 +128,8 @@ class ABCIViewShowIE(InfoExtractor): def _real_extract(self, url): show_id = self._match_id(url) - show_data = self._download_json('https://api.iview.abc.net.au/v2/show/' + show_id, show_id) + show_data = self._download_json( + 'https://api.iview.abc.net.au/v2/show/' + show_id, show_id) title = show_data.get('displayTitle') or show_data.get('title') or show_id description = show_data.get('description') @@ -137,21 +138,20 @@ class ABCIViewShowIE(InfoExtractor): for s in show_data['_embedded']['seriesList']: series_id = s.get('id') if series_id: - url = 'https://api.iview.abc.net.au/v2/series/' + show_id + '/' + series_id - groupList = self._download_json( - url, - series_id, - fatal=False, - errnote="Failed to fetch series ID '%s' from '%s'" % (series_id, url) + series_url = 'https://api.iview.abc.net.au/v2/series/' + show_id + '/' + series_id + group_list = self._download_json( + series_url, series_id, fatal=False, + errnote="Failed to fetch series ID '%s' from '%s'" % (series_id, series_url) ) - if type(groupList) is not list: - groupList = [groupList] + if type(group_list) is not list: + group_list = [group_list] - for series in groupList: - for ep in series.get('_embedded', {}).get('videoEpisodes'): - path = ep.get('_links', {}).get('deeplink', {}).get('href') + for series in group_list: + for ep in try_get(series, lambda x: x['_embedded']['videoEpisodes'], list): + path = url_or_none(ep.get('_links', {}).get('deeplink', {}).get('href')) if path: - entries.append(self.url_result('https://iview.abc.net.au' + path)) + entries.append(self.url_result( + 'https://iview.abc.net.au' + path, ie="ABCIViewShow", video_id="series_id")) return { '_type': 'playlist', From 2dbdf6c38bee32a3dc3d4dfabd56ddfafd2a817b Mon Sep 17 00:00:00 2001 From: Daniel Heath Date: Fri, 16 Aug 2019 17:27:43 +1000 Subject: [PATCH 6/6] Fixup import --- youtube_dl/extractor/abc.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/youtube_dl/extractor/abc.py b/youtube_dl/extractor/abc.py index 2c9a7a5e0..b684c73ff 100644 --- a/youtube_dl/extractor/abc.py +++ b/youtube_dl/extractor/abc.py @@ -11,6 +11,7 @@ from ..utils import ( ExtractorError, js_to_json, int_or_none, + url_or_none, parse_iso8601, try_get, unescapeHTML, @@ -116,7 +117,7 @@ class ABCIViewShowIE(InfoExtractor): 'title': 'Sarah And Duck', 'description': 'Sarah is a 7 year old girl with big eyes and a green hat, who lives with her quacky, flappy, slightly manic, but endearing best friend, Duck.', }, - 'playlist_count': 14, + 'playlist_count': 15, 'params': { 'skip_download': True, }, @@ -148,10 +149,10 @@ class ABCIViewShowIE(InfoExtractor): for series in group_list: for ep in try_get(series, lambda x: x['_embedded']['videoEpisodes'], list): - path = url_or_none(ep.get('_links', {}).get('deeplink', {}).get('href')) + path = url_or_none('https://iview.abc.net.au' + ep.get('_links', {}).get('deeplink', {}).get('href')) if path: entries.append(self.url_result( - 'https://iview.abc.net.au' + path, ie="ABCIViewShow", video_id="series_id")) + path, ie="ABCIViewShow", video_id="series_id")) return { '_type': 'playlist',