From 30edba52e478cd9aa301eb8354365d7f7ac5a86f Mon Sep 17 00:00:00 2001 From: turicfr Date: Sat, 12 Dec 2020 22:42:38 +0200 Subject: [PATCH 1/3] [nickil] Add new extractor --- youtube_dl/extractor/extractors.py | 1 + youtube_dl/extractor/nick.py | 46 +++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/youtube_dl/extractor/extractors.py b/youtube_dl/extractor/extractors.py index 533c074b3..4456ae83d 100644 --- a/youtube_dl/extractor/extractors.py +++ b/youtube_dl/extractor/extractors.py @@ -733,6 +733,7 @@ from .nick import ( NickDeIE, NickNightIE, NickRuIE, + NickIlIE, ) from .niconico import NiconicoIE, NiconicoPlaylistIE from .ninecninemedia import NineCNineMediaIE diff --git a/youtube_dl/extractor/nick.py b/youtube_dl/extractor/nick.py index 2e8b302ac..3462eb36c 100644 --- a/youtube_dl/extractor/nick.py +++ b/youtube_dl/extractor/nick.py @@ -3,8 +3,12 @@ from __future__ import unicode_literals import re +from .common import InfoExtractor from .mtv import MTVServicesInfoExtractor -from ..utils import update_url_query +from ..utils import ( + update_url_query, + int_or_none, +) class NickIE(MTVServicesInfoExtractor): @@ -247,3 +251,43 @@ class NickRuIE(MTVServicesInfoExtractor): webpage = self._download_webpage(url, video_id) mgid = self._extract_mgid(webpage) return self.url_result('http://media.mtvnservices.com/embed/%s' % mgid) + + +class NickIlIE(InfoExtractor): + _VALID_URL = r'https?://(?:www\.)?nick\.co\.il/video/(?P[0-9]+)' + _TEST = { + 'url': 'http://www.nick.co.il/video/17360', + 'md5': '0974ad5949022e0477a5a28ee5b85634', + 'info_dict': { + 'id': '17360', + 'ext': 'mp4', + 'title': '\u05e9\u05d9\u05e8 \u05d4\u05e4\u05ea\u05d9\u05d7\u05d4 \u05e9\u05dc \u05d3\u05d5\u05e8\u05d2 \u05d5\u05d0\u05df \u05d3\u05e0\u05d2\u05d5', + } + } + + def _real_extract(self, url): + video_id = self._match_id(url) + items = self._download_json( + 'http://nickplay.ilovegames.co.il/api/nicktogoapi/GetItems', video_id, query={ + 'countryCode': 'IL', + 'deviceId': '', + 'isApp': 0, + 'itemId': video_id, + } + ).get('items') + if items is None: + return {} + try: + video = next(filter(lambda i: i.get('id') == int(video_id), items)) + except StopIteration: + return {} + url = video.get('url') + if url is None: + return {} + formats = self._extract_m3u8_formats(url, video_id, ext='mp4') + return { + 'id': video_id, + 'title': video.get('title'), + 'duration': int_or_none(video.get('duration'), scale=1000), + 'formats': formats, + } From 6a2342c7af9e1f2c1fdbbd8a1d75cab1092e824d Mon Sep 17 00:00:00 2001 From: turicfr Date: Mon, 14 Dec 2020 19:58:18 +0200 Subject: [PATCH 2/3] [nickil] Make more robust --- youtube_dl/extractor/nick.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/youtube_dl/extractor/nick.py b/youtube_dl/extractor/nick.py index 3462eb36c..b86bb20f6 100644 --- a/youtube_dl/extractor/nick.py +++ b/youtube_dl/extractor/nick.py @@ -6,8 +6,10 @@ import re from .common import InfoExtractor from .mtv import MTVServicesInfoExtractor from ..utils import ( + try_get, update_url_query, int_or_none, + ExtractorError, ) @@ -268,22 +270,21 @@ class NickIlIE(InfoExtractor): def _real_extract(self, url): video_id = self._match_id(url) items = self._download_json( - 'http://nickplay.ilovegames.co.il/api/nicktogoapi/GetItems', video_id, query={ + 'http://nickplay.ilovegames.co.il/api/nicktogoapi/GetItems', video_id, + query={ 'countryCode': 'IL', 'deviceId': '', 'isApp': 0, 'itemId': video_id, - } - ).get('items') + }).get('items') if items is None: - return {} - try: - video = next(filter(lambda i: i.get('id') == int(video_id), items)) - except StopIteration: - return {} + raise ExtractorError('Unable to extract video data', expected=True, video_id=video_id) + video = try_get([i for i in items if i.get('id') == int(video_id)] or None, lambda x: x[0], dict) + if video is None: + raise ExtractorError('Unable to find video ID', expected=True, video_id=video_id) url = video.get('url') if url is None: - return {} + raise ExtractorError('Unable to extract video data', expected=True, video_id=video_id) formats = self._extract_m3u8_formats(url, video_id, ext='mp4') return { 'id': video_id, From 3ecfa9f9f79bf570b24b4d82ab909e10f14cee67 Mon Sep 17 00:00:00 2001 From: turicfr Date: Mon, 14 Dec 2020 21:52:10 +0200 Subject: [PATCH 3/3] [nickil] Improvements --- youtube_dl/extractor/nick.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/youtube_dl/extractor/nick.py b/youtube_dl/extractor/nick.py index b86bb20f6..3ce6dd922 100644 --- a/youtube_dl/extractor/nick.py +++ b/youtube_dl/extractor/nick.py @@ -256,7 +256,7 @@ class NickRuIE(MTVServicesInfoExtractor): class NickIlIE(InfoExtractor): - _VALID_URL = r'https?://(?:www\.)?nick\.co\.il/video/(?P[0-9]+)' + _VALID_URL = r'https?://(?:www\.)?nick\.co\.il/video/(?P\d+)' _TEST = { 'url': 'http://www.nick.co.il/video/17360', 'md5': '0974ad5949022e0477a5a28ee5b85634', @@ -279,7 +279,7 @@ class NickIlIE(InfoExtractor): }).get('items') if items is None: raise ExtractorError('Unable to extract video data', expected=True, video_id=video_id) - video = try_get([i for i in items if i.get('id') == int(video_id)] or None, lambda x: x[0], dict) + video = try_get([i for i in items if i.get('id') == int(video_id)], lambda x: x[0], dict) if video is None: raise ExtractorError('Unable to find video ID', expected=True, video_id=video_id) url = video.get('url')