From 1564eea8805b7d353491366cb2875625d0d9f868 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Veres-Szentkir=C3=A1lyi?= Date: Fri, 13 Apr 2018 10:08:14 +0200 Subject: [PATCH 1/7] [IndavideoEmbed] extracted method video_url_to_format --- youtube_dl/extractor/indavideo.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/youtube_dl/extractor/indavideo.py b/youtube_dl/extractor/indavideo.py index 11cf3c609..c0d6f2e15 100644 --- a/youtube_dl/extractor/indavideo.py +++ b/youtube_dl/extractor/indavideo.py @@ -58,11 +58,7 @@ class IndavideoEmbedIE(InfoExtractor): if flv_url not in video_urls: video_urls.append(flv_url) - formats = [{ - 'url': video_url, - 'height': int_or_none(self._search_regex( - r'\.(\d{3,4})\.mp4(?:\?|$)', video_url, 'height', default=None)), - } for video_url in video_urls] + formats = [self.video_url_to_format(video_url) for video_url in video_urls] self._sort_formats(formats) timestamp = video.get('date') @@ -90,6 +86,13 @@ class IndavideoEmbedIE(InfoExtractor): 'formats': formats, } + def video_url_to_format(self, video_url): + return { + 'url': video_url, + 'height': int_or_none(self._search_regex( + r'\.(\d{3,4})\.mp4(?:\?|$)', video_url, 'height', default=None)), + } + class IndavideoIE(InfoExtractor): _VALID_URL = r'https?://(?:.+?\.)?indavideo\.hu/video/(?P[^/#?]+)' From 7f2f876a4da0eeeb2e69718a08c2b90b0207f78f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Veres-Szentkir=C3=A1lyi?= Date: Fri, 13 Apr 2018 10:14:15 +0200 Subject: [PATCH 2/7] [IndavideoEmbed] added token to avoid 403s --- youtube_dl/extractor/indavideo.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/youtube_dl/extractor/indavideo.py b/youtube_dl/extractor/indavideo.py index c0d6f2e15..70301fab3 100644 --- a/youtube_dl/extractor/indavideo.py +++ b/youtube_dl/extractor/indavideo.py @@ -1,6 +1,8 @@ # coding: utf-8 from __future__ import unicode_literals +from urllib.parse import urlsplit, urlunsplit, urlencode, parse_qsl + from .common import InfoExtractor from ..utils import ( int_or_none, @@ -58,7 +60,8 @@ class IndavideoEmbedIE(InfoExtractor): if flv_url not in video_urls: video_urls.append(flv_url) - formats = [self.video_url_to_format(video_url) for video_url in video_urls] + filesh = video.get('filesh') + formats = [self.video_url_to_format(video_url, filesh) for video_url in video_urls] self._sort_formats(formats) timestamp = video.get('date') @@ -86,11 +89,18 @@ class IndavideoEmbedIE(InfoExtractor): 'formats': formats, } - def video_url_to_format(self, video_url): + def video_url_to_format(self, video_url, filesh): + height = int_or_none(self._search_regex( + r'\.(\d{3,4})\.mp4(?:\?|$)', video_url, 'height', default=None)) + if height is not None and filesh is not None: + token = filesh.get(str(height)) + if token is not None: + us = urlsplit(video_url) + query = urlencode(parse_qsl(us.query) + [('token', token)]) + video_url = urlunsplit((us.scheme, us.netloc, us.path, query, us.fragment)) return { 'url': video_url, - 'height': int_or_none(self._search_regex( - r'\.(\d{3,4})\.mp4(?:\?|$)', video_url, 'height', default=None)), + 'height': height, } From 952fb8b8a1f1c57a487b2978686af6a93df7d585 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Veres-Szentkir=C3=A1lyi?= Date: Fri, 13 Apr 2018 10:20:04 +0200 Subject: [PATCH 3/7] [IndavideoEmbed] Python 2 compatibility --- youtube_dl/extractor/indavideo.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/youtube_dl/extractor/indavideo.py b/youtube_dl/extractor/indavideo.py index 70301fab3..d5933f156 100644 --- a/youtube_dl/extractor/indavideo.py +++ b/youtube_dl/extractor/indavideo.py @@ -1,7 +1,13 @@ # coding: utf-8 from __future__ import unicode_literals -from urllib.parse import urlsplit, urlunsplit, urlencode, parse_qsl +try: + # Python 3 + from urllib.parse import urlsplit, urlunsplit, urlencode, parse_qsl +except ImportError: + # Python 2 + from urlparse import urlsplit, urlunsplit, parse_qsl + from urllib import urlencode from .common import InfoExtractor from ..utils import ( From acb14703ba53ca4e075225e5a8d8223dfecb0840 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Veres-Szentkir=C3=A1lyi?= Date: Sat, 14 Apr 2018 21:05:31 +0200 Subject: [PATCH 4/7] [IndavideoEmbed] use __bool__ instead of None comparison per request of @dstftw in #16174 --- youtube_dl/extractor/indavideo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/youtube_dl/extractor/indavideo.py b/youtube_dl/extractor/indavideo.py index d5933f156..f4af4ec46 100644 --- a/youtube_dl/extractor/indavideo.py +++ b/youtube_dl/extractor/indavideo.py @@ -98,7 +98,7 @@ class IndavideoEmbedIE(InfoExtractor): def video_url_to_format(self, video_url, filesh): height = int_or_none(self._search_regex( r'\.(\d{3,4})\.mp4(?:\?|$)', video_url, 'height', default=None)) - if height is not None and filesh is not None: + if height and filesh: token = filesh.get(str(height)) if token is not None: us = urlsplit(video_url) From 425f79940a5b3ad074bf0aaac86640a340435f3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Veres-Szentkir=C3=A1lyi?= Date: Sat, 14 Apr 2018 21:06:49 +0200 Subject: [PATCH 5/7] [IndavideoEmbed] use compat_str instead of str per request of @dstftw in #16174 --- youtube_dl/extractor/indavideo.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/youtube_dl/extractor/indavideo.py b/youtube_dl/extractor/indavideo.py index f4af4ec46..960066347 100644 --- a/youtube_dl/extractor/indavideo.py +++ b/youtube_dl/extractor/indavideo.py @@ -10,6 +10,7 @@ except ImportError: from urllib import urlencode from .common import InfoExtractor +from ..compat import compat_str from ..utils import ( int_or_none, parse_age_limit, @@ -99,7 +100,7 @@ class IndavideoEmbedIE(InfoExtractor): height = int_or_none(self._search_regex( r'\.(\d{3,4})\.mp4(?:\?|$)', video_url, 'height', default=None)) if height and filesh: - token = filesh.get(str(height)) + token = filesh.get(compat_str(height)) if token is not None: us = urlsplit(video_url) query = urlencode(parse_qsl(us.query) + [('token', token)]) From f1a6deb2384f9238c485fd62570019666fe802db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Veres-Szentkir=C3=A1lyi?= Date: Sat, 14 Apr 2018 21:10:34 +0200 Subject: [PATCH 6/7] [IndavideoEmbed] use update_url_query per request of @dstftw in #16174 --- youtube_dl/extractor/indavideo.py | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/youtube_dl/extractor/indavideo.py b/youtube_dl/extractor/indavideo.py index 960066347..909db3706 100644 --- a/youtube_dl/extractor/indavideo.py +++ b/youtube_dl/extractor/indavideo.py @@ -1,20 +1,13 @@ # coding: utf-8 from __future__ import unicode_literals -try: - # Python 3 - from urllib.parse import urlsplit, urlunsplit, urlencode, parse_qsl -except ImportError: - # Python 2 - from urlparse import urlsplit, urlunsplit, parse_qsl - from urllib import urlencode - from .common import InfoExtractor from ..compat import compat_str from ..utils import ( int_or_none, parse_age_limit, parse_iso8601, + update_url_query, ) @@ -102,9 +95,7 @@ class IndavideoEmbedIE(InfoExtractor): if height and filesh: token = filesh.get(compat_str(height)) if token is not None: - us = urlsplit(video_url) - query = urlencode(parse_qsl(us.query) + [('token', token)]) - video_url = urlunsplit((us.scheme, us.netloc, us.path, query, us.fragment)) + video_url = update_url_query(video_url, {'token': token}) return { 'url': video_url, 'height': height, From 0d2e4439fad17e7d49db0308e21f743aca11024c Mon Sep 17 00:00:00 2001 From: Sergey M Date: Sat, 26 May 2018 00:45:04 +0700 Subject: [PATCH 7/7] Update indavideo.py --- youtube_dl/extractor/indavideo.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/youtube_dl/extractor/indavideo.py b/youtube_dl/extractor/indavideo.py index 909db3706..15b766fb2 100644 --- a/youtube_dl/extractor/indavideo.py +++ b/youtube_dl/extractor/indavideo.py @@ -61,7 +61,9 @@ class IndavideoEmbedIE(InfoExtractor): video_urls.append(flv_url) filesh = video.get('filesh') - formats = [self.video_url_to_format(video_url, filesh) for video_url in video_urls] + formats = [ + self.video_url_to_format(video_url, filesh) + for video_url in video_urls] self._sort_formats(formats) timestamp = video.get('date')