From 114ed20e6435f9a68eb757f2d6e26e7ea941afbf Mon Sep 17 00:00:00 2001 From: remitamine Date: Sat, 18 Jul 2015 22:10:57 +0100 Subject: [PATCH 01/10] [shahid] Add new extractor --- youtube_dl/extractor/__init__.py | 1 + youtube_dl/extractor/shahid.py | 56 ++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 youtube_dl/extractor/shahid.py diff --git a/youtube_dl/extractor/__init__.py b/youtube_dl/extractor/__init__.py index 06f21064b..6c1d4f08a 100644 --- a/youtube_dl/extractor/__init__.py +++ b/youtube_dl/extractor/__init__.py @@ -502,6 +502,7 @@ from .servingsys import ServingSysIE from .sexu import SexuIE from .sexykarma import SexyKarmaIE +from .shahid import ShahidIE from .shared import SharedIE from .sharesix import ShareSixIE from .sina import SinaIE diff --git a/youtube_dl/extractor/shahid.py b/youtube_dl/extractor/shahid.py new file mode 100644 index 000000000..d492070da --- /dev/null +++ b/youtube_dl/extractor/shahid.py @@ -0,0 +1,56 @@ +from .common import InfoExtractor +from ..utils import get_element_by_id + +class ShahidIE(InfoExtractor): + _VALID_URL = r'https?://shahid\.mbc\.net/ar/episode/(?P\d+)/?' + _TESTS = [ + { + 'url': 'https://shahid.mbc.net/ar/episode/108084/%D8%AE%D9%88%D8%A7%D8%B7%D8%B1-%D8%A7%D9%84%D9%85%D9%88%D8%B3%D9%85-11-%D8%A7%D9%84%D8%AD%D9%84%D9%82%D8%A9-1.html', + 'info_dict': { + 'id': '108084', + 'ext': 'm3u8', + 'title': 'بسم الله', + 'description': 'بسم الله' + }, + 'params': { + # m3u8 download + 'skip_download': True, + } + }, + { + #shahid plus subscriber only + 'url': 'https://shahid.mbc.net/ar/series/90497/%D9%85%D8%B1%D8%A7%D9%8A%D8%A7-2011.html', + 'only_matching': True + } + ] + + def _real_extract(self, url): + video_id = self._match_id(url) + webpage = self._download_webpage(url, video_id) + json_data = self._parse_json( + get_element_by_id('jsonld', webpage), + video_id + ) + title = json_data['name'] + thumbnail = json_data['image'] + categories = json_data['genre'] + description = json_data['description'] + player_json_data = self._download_json( + 'https://shahid.mbc.net/arContent/getPlayerContent-param-.id-'+video_id+'.type-player.html', + video_id + )['data'] + if 'url' in player_json_data: + m3u8_url = player_json_data['url'] + else: + for error in json_data['error'].values(): + self.report_warning(error) + return + formats = self._extract_m3u8_formats(m3u8_url, video_id) + return { + 'id': video_id, + 'title': title, + 'thumbnail': thumbnail, + 'categories': categories, + 'description': description, + 'formats': formats, + } From 02c126a7c2453b101505e3c7b8209e49e36fcd71 Mon Sep 17 00:00:00 2001 From: remitamine Date: Sat, 18 Jul 2015 22:55:40 +0100 Subject: [PATCH 02/10] [shahid] raise ExtractorError instead of warning --- youtube_dl/extractor/shahid.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/youtube_dl/extractor/shahid.py b/youtube_dl/extractor/shahid.py index d492070da..6d76ef590 100644 --- a/youtube_dl/extractor/shahid.py +++ b/youtube_dl/extractor/shahid.py @@ -1,5 +1,8 @@ from .common import InfoExtractor -from ..utils import get_element_by_id +from ..utils import ( + get_element_by_id, + ExtractorError, +} class ShahidIE(InfoExtractor): _VALID_URL = r'https?://shahid\.mbc\.net/ar/episode/(?P\d+)/?' @@ -43,7 +46,7 @@ def _real_extract(self, url): m3u8_url = player_json_data['url'] else: for error in json_data['error'].values(): - self.report_warning(error) + raise ExtractorError(error) return formats = self._extract_m3u8_formats(m3u8_url, video_id) return { From 84c0ed50a5491146a8a6b489c530c2335c023f8f Mon Sep 17 00:00:00 2001 From: remitamine Date: Sat, 18 Jul 2015 23:10:20 +0100 Subject: [PATCH 03/10] [shahid] fix backets closing --- youtube_dl/extractor/shahid.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/youtube_dl/extractor/shahid.py b/youtube_dl/extractor/shahid.py index 6d76ef590..9846c052c 100644 --- a/youtube_dl/extractor/shahid.py +++ b/youtube_dl/extractor/shahid.py @@ -2,7 +2,7 @@ from ..utils import ( get_element_by_id, ExtractorError, -} +) class ShahidIE(InfoExtractor): _VALID_URL = r'https?://shahid\.mbc\.net/ar/episode/(?P\d+)/?' From 3c07a729a652a25caf9aac6143a19d040ecf9a15 Mon Sep 17 00:00:00 2001 From: remitamine Date: Sat, 18 Jul 2015 23:16:57 +0100 Subject: [PATCH 04/10] [shahid] don't fail on missing info --- youtube_dl/extractor/shahid.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/youtube_dl/extractor/shahid.py b/youtube_dl/extractor/shahid.py index 9846c052c..04de866f4 100644 --- a/youtube_dl/extractor/shahid.py +++ b/youtube_dl/extractor/shahid.py @@ -35,9 +35,9 @@ def _real_extract(self, url): video_id ) title = json_data['name'] - thumbnail = json_data['image'] - categories = json_data['genre'] - description = json_data['description'] + thumbnail = json_data.get('image') + categories = json_data.get('genre') + description = json_data.get('description') player_json_data = self._download_json( 'https://shahid.mbc.net/arContent/getPlayerContent-param-.id-'+video_id+'.type-player.html', video_id From a62fd1af275a125b77d782e821724d6c6c896b69 Mon Sep 17 00:00:00 2001 From: remitamine Date: Sat, 25 Jul 2015 18:13:44 +0100 Subject: [PATCH 05/10] [shahid] improve info extraction --- youtube_dl/extractor/shahid.py | 42 +++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/youtube_dl/extractor/shahid.py b/youtube_dl/extractor/shahid.py index 04de866f4..da3141f11 100644 --- a/youtube_dl/extractor/shahid.py +++ b/youtube_dl/extractor/shahid.py @@ -1,7 +1,8 @@ from .common import InfoExtractor from ..utils import ( - get_element_by_id, + js_to_json, ExtractorError, + int_or_none ) class ShahidIE(InfoExtractor): @@ -12,8 +13,9 @@ class ShahidIE(InfoExtractor): 'info_dict': { 'id': '108084', 'ext': 'm3u8', - 'title': 'بسم الله', - 'description': 'بسم الله' + 'title': 'خواطر الموسم 11 الحلقة 1', + 'description': 'بسم الله', + 'duration': 1166, }, 'params': { # m3u8 download @@ -30,16 +32,33 @@ class ShahidIE(InfoExtractor): def _real_extract(self, url): video_id = self._match_id(url) webpage = self._download_webpage(url, video_id) - json_data = self._parse_json( - get_element_by_id('jsonld', webpage), + player_info = '' + for line in self._search_regex( 'var flashvars = ({[^}]+})', webpage, 'flashvars').splitlines(): + if '+' not in line and '(' not in line and ')' not in line: + player_info += line + player_info = self._parse_json(js_to_json(player_info), video_id) + video_id = player_info['id'] + player_type = player_info['playerType'] + + video_info = self._download_json( + player_info['url'] + '/' + player_type + '/' + video_id + + '?apiKey=sh%40hid0nlin3&hash=b2wMCTHpSmyxGqQjJFOycRmLSex%2BBpTK%2Fooxy6vHaqs%3D', video_id - ) - title = json_data['name'] - thumbnail = json_data.get('image') - categories = json_data.get('genre') - description = json_data.get('description') + )['data'] + if video_info['error']: + for error in video_info['error']: + raise ExtractorError(error) + video_info = video_info[player_type] + if video_info.get('availabilities').get('plus'): + raise ExtractorError('plus members only') + title = video_info['title'] + thumbnail = video_info.get('thumbnailUrl') + categories = [category['name'] for category in video_info.get('genres')] + description = video_info.get('description') + duration = int_or_none(video_info.get('duration')) + player_json_data = self._download_json( - 'https://shahid.mbc.net/arContent/getPlayerContent-param-.id-'+video_id+'.type-player.html', + 'https://shahid.mbc.net/arContent/getPlayerContent-param-.id-' + video_id + '.type-' + player_info['type'] + '.html', video_id )['data'] if 'url' in player_json_data: @@ -55,5 +74,6 @@ def _real_extract(self, url): 'thumbnail': thumbnail, 'categories': categories, 'description': description, + 'duration': duration, 'formats': formats, } From dfaba1ab9586a7c47017bd897ffda0b795a1d27e Mon Sep 17 00:00:00 2001 From: remitamine Date: Sat, 25 Jul 2015 19:14:18 +0100 Subject: [PATCH 06/10] [shahid] fix variable name --- youtube_dl/extractor/shahid.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/youtube_dl/extractor/shahid.py b/youtube_dl/extractor/shahid.py index da3141f11..b3b45da24 100644 --- a/youtube_dl/extractor/shahid.py +++ b/youtube_dl/extractor/shahid.py @@ -64,7 +64,7 @@ def _real_extract(self, url): if 'url' in player_json_data: m3u8_url = player_json_data['url'] else: - for error in json_data['error'].values(): + for error in player_json_data['error'].values(): raise ExtractorError(error) return formats = self._extract_m3u8_formats(m3u8_url, video_id) From 3be3c622dc1d3d7b92c5268a079d202a9f2b0a5a Mon Sep 17 00:00:00 2001 From: remitamine Date: Thu, 6 Aug 2015 19:37:45 +0100 Subject: [PATCH 07/10] [shahid] generic errors handling and check with flake8 --- youtube_dl/extractor/shahid.py | 42 ++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/youtube_dl/extractor/shahid.py b/youtube_dl/extractor/shahid.py index b3b45da24..57c159833 100644 --- a/youtube_dl/extractor/shahid.py +++ b/youtube_dl/extractor/shahid.py @@ -1,3 +1,6 @@ +# coding: utf-8 +from __future__ import unicode_literals + from .common import InfoExtractor from ..utils import ( js_to_json, @@ -5,6 +8,7 @@ int_or_none ) + class ShahidIE(InfoExtractor): _VALID_URL = r'https?://shahid\.mbc\.net/ar/episode/(?P\d+)/?' _TESTS = [ @@ -23,7 +27,7 @@ class ShahidIE(InfoExtractor): } }, { - #shahid plus subscriber only + # shahid plus subscriber only 'url': 'https://shahid.mbc.net/ar/series/90497/%D9%85%D8%B1%D8%A7%D9%8A%D8%A7-2011.html', 'only_matching': True } @@ -32,31 +36,15 @@ class ShahidIE(InfoExtractor): def _real_extract(self, url): video_id = self._match_id(url) webpage = self._download_webpage(url, video_id) + player_info = '' - for line in self._search_regex( 'var flashvars = ({[^}]+})', webpage, 'flashvars').splitlines(): + for line in self._search_regex('var flashvars = ({[^}]+})', webpage, 'flashvars').splitlines(): if '+' not in line and '(' not in line and ')' not in line: player_info += line player_info = self._parse_json(js_to_json(player_info), video_id) video_id = player_info['id'] player_type = player_info['playerType'] - video_info = self._download_json( - player_info['url'] + '/' + player_type + '/' + video_id + - '?apiKey=sh%40hid0nlin3&hash=b2wMCTHpSmyxGqQjJFOycRmLSex%2BBpTK%2Fooxy6vHaqs%3D', - video_id - )['data'] - if video_info['error']: - for error in video_info['error']: - raise ExtractorError(error) - video_info = video_info[player_type] - if video_info.get('availabilities').get('plus'): - raise ExtractorError('plus members only') - title = video_info['title'] - thumbnail = video_info.get('thumbnailUrl') - categories = [category['name'] for category in video_info.get('genres')] - description = video_info.get('description') - duration = int_or_none(video_info.get('duration')) - player_json_data = self._download_json( 'https://shahid.mbc.net/arContent/getPlayerContent-param-.id-' + video_id + '.type-' + player_info['type'] + '.html', video_id @@ -66,8 +54,22 @@ def _real_extract(self, url): else: for error in player_json_data['error'].values(): raise ExtractorError(error) - return formats = self._extract_m3u8_formats(m3u8_url, video_id) + + video_info = self._download_json( + player_info['url'] + '/' + player_type + '/' + video_id + '?apiKey=sh%40hid0nlin3&hash=b2wMCTHpSmyxGqQjJFOycRmLSex%2BBpTK%2Fooxy6vHaqs%3D', + video_id + )['data'] + if video_info.get('error'): + for error in video_info['error']: + raise ExtractorError(error) + video_info = video_info[player_type] + title = video_info['title'] + thumbnail = video_info.get('thumbnailUrl') + categories = [category['name'] for category in video_info.get('genres')] + description = video_info.get('description') + duration = int_or_none(video_info.get('duration')) + return { 'id': video_id, 'title': title, From c29458f3ec77072e9c17169b78871bf4473134d6 Mon Sep 17 00:00:00 2001 From: remitamine Date: Fri, 7 Aug 2015 21:38:50 +0100 Subject: [PATCH 08/10] [shahid] change the tests --- youtube_dl/extractor/shahid.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/youtube_dl/extractor/shahid.py b/youtube_dl/extractor/shahid.py index 57c159833..b2050525e 100644 --- a/youtube_dl/extractor/shahid.py +++ b/youtube_dl/extractor/shahid.py @@ -13,13 +13,13 @@ class ShahidIE(InfoExtractor): _VALID_URL = r'https?://shahid\.mbc\.net/ar/episode/(?P\d+)/?' _TESTS = [ { - 'url': 'https://shahid.mbc.net/ar/episode/108084/%D8%AE%D9%88%D8%A7%D8%B7%D8%B1-%D8%A7%D9%84%D9%85%D9%88%D8%B3%D9%85-11-%D8%A7%D9%84%D8%AD%D9%84%D9%82%D8%A9-1.html', + 'url': 'https://shahid.mbc.net/ar/episode/90574/%D8%A7%D9%84%D9%85%D9%84%D9%83-%D8%B9%D8%A8%D8%AF%D8%A7%D9%84%D9%84%D9%87-%D8%A7%D9%84%D8%A5%D9%86%D8%B3%D8%A7%D9%86-%D8%A7%D9%84%D9%85%D9%88%D8%B3%D9%85-1-%D9%83%D9%84%D9%8A%D8%A8-3.html', 'info_dict': { - 'id': '108084', + 'id': '90574', 'ext': 'm3u8', - 'title': 'خواطر الموسم 11 الحلقة 1', - 'description': 'بسم الله', - 'duration': 1166, + 'title': 'الملك عبدالله الإنسان الموسم 1 كليب 3', + 'description': 'الفيلم الوثائقي - الملك عبد الله الإنسان', + 'duration': 2972, }, 'params': { # m3u8 download @@ -28,7 +28,7 @@ class ShahidIE(InfoExtractor): }, { # shahid plus subscriber only - 'url': 'https://shahid.mbc.net/ar/series/90497/%D9%85%D8%B1%D8%A7%D9%8A%D8%A7-2011.html', + 'url': 'https://shahid.mbc.net/ar/episode/90511/%D9%85%D8%B1%D8%A7%D9%8A%D8%A7-2011-%D8%A7%D9%84%D9%85%D9%88%D8%B3%D9%85-1-%D8%A7%D9%84%D8%AD%D9%84%D9%82%D8%A9-1.html', 'only_matching': True } ] From 59e89e62d7b45554cef502dc4986f35618110679 Mon Sep 17 00:00:00 2001 From: remitamine Date: Sat, 8 Aug 2015 12:59:10 +0100 Subject: [PATCH 09/10] [shahid] add default fallbacks for extracting api vars --- youtube_dl/extractor/shahid.py | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/youtube_dl/extractor/shahid.py b/youtube_dl/extractor/shahid.py index b2050525e..399140189 100644 --- a/youtube_dl/extractor/shahid.py +++ b/youtube_dl/extractor/shahid.py @@ -33,20 +33,30 @@ class ShahidIE(InfoExtractor): } ] + _api_vars = { + 'type': 'player', + 'url': 'http://api.shahid.net/api/v1_1', + 'playerType': 'episode', + } + def _real_extract(self, url): video_id = self._match_id(url) webpage = self._download_webpage(url, video_id) player_info = '' - for line in self._search_regex('var flashvars = ({[^}]+})', webpage, 'flashvars').splitlines(): - if '+' not in line and '(' not in line and ')' not in line: - player_info += line - player_info = self._parse_json(js_to_json(player_info), video_id) - video_id = player_info['id'] - player_type = player_info['playerType'] + flash_vars = self._search_regex('var flashvars = ({[^}]+})', webpage, 'flashvars', None) + if flash_vars is not None: + for line in flash_vars.splitlines(): + if '+' not in line and '(' not in line and ')' not in line: + player_info += line + player_info = self._parse_json(player_info, video_id, js_to_json, False) + if player_info is not None: + for key in self._api_vars: + if key in player_info: + self._api_vars[key] = player_info[key] player_json_data = self._download_json( - 'https://shahid.mbc.net/arContent/getPlayerContent-param-.id-' + video_id + '.type-' + player_info['type'] + '.html', + 'https://shahid.mbc.net/arContent/getPlayerContent-param-.id-' + video_id + '.type-' + self._api_vars['type'] + '.html', video_id )['data'] if 'url' in player_json_data: @@ -57,13 +67,13 @@ def _real_extract(self, url): formats = self._extract_m3u8_formats(m3u8_url, video_id) video_info = self._download_json( - player_info['url'] + '/' + player_type + '/' + video_id + '?apiKey=sh%40hid0nlin3&hash=b2wMCTHpSmyxGqQjJFOycRmLSex%2BBpTK%2Fooxy6vHaqs%3D', + self._api_vars['url'] + '/' + self._api_vars['playerType'] + '/' + video_id + '?apiKey=sh%40hid0nlin3&hash=b2wMCTHpSmyxGqQjJFOycRmLSex%2BBpTK%2Fooxy6vHaqs%3D', video_id )['data'] if video_info.get('error'): for error in video_info['error']: raise ExtractorError(error) - video_info = video_info[player_type] + video_info = video_info[self._api_vars['playerType']] title = video_info['title'] thumbnail = video_info.get('thumbnailUrl') categories = [category['name'] for category in video_info.get('genres')] From c576ef1e7cfd31ca94ca6025c054b3ae4f611b21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergey=20M=E2=80=A4?= Date: Sat, 15 Aug 2015 18:13:37 +0600 Subject: [PATCH 10/10] [shahid] Improve and simplify --- youtube_dl/extractor/shahid.py | 140 ++++++++++++++++++--------------- 1 file changed, 78 insertions(+), 62 deletions(-) diff --git a/youtube_dl/extractor/shahid.py b/youtube_dl/extractor/shahid.py index 399140189..6e9903d5e 100644 --- a/youtube_dl/extractor/shahid.py +++ b/youtube_dl/extractor/shahid.py @@ -2,90 +2,106 @@ from __future__ import unicode_literals from .common import InfoExtractor +from ..compat import compat_urllib_parse from ..utils import ( - js_to_json, ExtractorError, - int_or_none + int_or_none, + parse_iso8601, ) class ShahidIE(InfoExtractor): _VALID_URL = r'https?://shahid\.mbc\.net/ar/episode/(?P\d+)/?' - _TESTS = [ - { - 'url': 'https://shahid.mbc.net/ar/episode/90574/%D8%A7%D9%84%D9%85%D9%84%D9%83-%D8%B9%D8%A8%D8%AF%D8%A7%D9%84%D9%84%D9%87-%D8%A7%D9%84%D8%A5%D9%86%D8%B3%D8%A7%D9%86-%D8%A7%D9%84%D9%85%D9%88%D8%B3%D9%85-1-%D9%83%D9%84%D9%8A%D8%A8-3.html', - 'info_dict': { - 'id': '90574', - 'ext': 'm3u8', - 'title': 'الملك عبدالله الإنسان الموسم 1 كليب 3', - 'description': 'الفيلم الوثائقي - الملك عبد الله الإنسان', - 'duration': 2972, - }, - 'params': { - # m3u8 download - 'skip_download': True, - } + _TESTS = [{ + 'url': 'https://shahid.mbc.net/ar/episode/90574/%D8%A7%D9%84%D9%85%D9%84%D9%83-%D8%B9%D8%A8%D8%AF%D8%A7%D9%84%D9%84%D9%87-%D8%A7%D9%84%D8%A5%D9%86%D8%B3%D8%A7%D9%86-%D8%A7%D9%84%D9%85%D9%88%D8%B3%D9%85-1-%D9%83%D9%84%D9%8A%D8%A8-3.html', + 'info_dict': { + 'id': '90574', + 'ext': 'm3u8', + 'title': 'الملك عبدالله الإنسان الموسم 1 كليب 3', + 'description': 'الفيلم الوثائقي - الملك عبد الله الإنسان', + 'duration': 2972, + 'timestamp': 1422057420, + 'upload_date': '20150123', }, - { - # shahid plus subscriber only - 'url': 'https://shahid.mbc.net/ar/episode/90511/%D9%85%D8%B1%D8%A7%D9%8A%D8%A7-2011-%D8%A7%D9%84%D9%85%D9%88%D8%B3%D9%85-1-%D8%A7%D9%84%D8%AD%D9%84%D9%82%D8%A9-1.html', - 'only_matching': True + 'params': { + # m3u8 download + 'skip_download': True, } - ] + }, { + # shahid plus subscriber only + 'url': 'https://shahid.mbc.net/ar/episode/90511/%D9%85%D8%B1%D8%A7%D9%8A%D8%A7-2011-%D8%A7%D9%84%D9%85%D9%88%D8%B3%D9%85-1-%D8%A7%D9%84%D8%AD%D9%84%D9%82%D8%A9-1.html', + 'only_matching': True + }] - _api_vars = { - 'type': 'player', - 'url': 'http://api.shahid.net/api/v1_1', - 'playerType': 'episode', - } + def _handle_error(self, response): + if not isinstance(response, dict): + return + error = response.get('error') + if error: + raise ExtractorError( + '%s returned error: %s' % (self.IE_NAME, '\n'.join(error.values())), + expected=True) + + def _download_json(self, url, video_id, note='Downloading JSON metadata'): + response = super(ShahidIE, self)._download_json(url, video_id, note)['data'] + self._handle_error(response) + return response def _real_extract(self, url): video_id = self._match_id(url) + webpage = self._download_webpage(url, video_id) - player_info = '' - flash_vars = self._search_regex('var flashvars = ({[^}]+})', webpage, 'flashvars', None) - if flash_vars is not None: - for line in flash_vars.splitlines(): - if '+' not in line and '(' not in line and ')' not in line: - player_info += line - player_info = self._parse_json(player_info, video_id, js_to_json, False) - if player_info is not None: - for key in self._api_vars: - if key in player_info: - self._api_vars[key] = player_info[key] + api_vars = { + 'id': video_id, + 'type': 'player', + 'url': 'http://api.shahid.net/api/v1_1', + 'playerType': 'episode', + } - player_json_data = self._download_json( - 'https://shahid.mbc.net/arContent/getPlayerContent-param-.id-' + video_id + '.type-' + self._api_vars['type'] + '.html', - video_id - )['data'] - if 'url' in player_json_data: - m3u8_url = player_json_data['url'] - else: - for error in player_json_data['error'].values(): - raise ExtractorError(error) - formats = self._extract_m3u8_formats(m3u8_url, video_id) + flashvars = self._search_regex( + r'var\s+flashvars\s*=\s*({[^}]+})', webpage, 'flashvars', default=None) + if flashvars: + for key in api_vars.keys(): + value = self._search_regex( + r'\b%s\s*:\s*(?P["\'])(?P.+?)(?P=q)' % key, + flashvars, 'type', default=None, group='value') + if value: + api_vars[key] = value - video_info = self._download_json( - self._api_vars['url'] + '/' + self._api_vars['playerType'] + '/' + video_id + '?apiKey=sh%40hid0nlin3&hash=b2wMCTHpSmyxGqQjJFOycRmLSex%2BBpTK%2Fooxy6vHaqs%3D', - video_id - )['data'] - if video_info.get('error'): - for error in video_info['error']: - raise ExtractorError(error) - video_info = video_info[self._api_vars['playerType']] - title = video_info['title'] - thumbnail = video_info.get('thumbnailUrl') - categories = [category['name'] for category in video_info.get('genres')] - description = video_info.get('description') - duration = int_or_none(video_info.get('duration')) + player = self._download_json( + 'https://shahid.mbc.net/arContent/getPlayerContent-param-.id-%s.type-%s.html' + % (video_id, api_vars['type']), video_id, 'Downloading player JSON') + + formats = self._extract_m3u8_formats(player['url'], video_id, 'mp4') + + video = self._download_json( + '%s/%s/%s?%s' % ( + api_vars['url'], api_vars['playerType'], api_vars['id'], + compat_urllib_parse.urlencode({ + 'apiKey': 'sh@hid0nlin3', + 'hash': 'b2wMCTHpSmyxGqQjJFOycRmLSex+BpTK/ooxy6vHaqs=', + }).encode('utf-8')), + video_id, 'Downloading video JSON') + + video = video[api_vars['playerType']] + + title = video['title'] + description = video.get('description') + thumbnail = video.get('thumbnailUrl') + duration = int_or_none(video.get('duration')) + timestamp = parse_iso8601(video.get('referenceDate')) + categories = [ + category['name'] + for category in video.get('genres', []) if 'name' in category] return { 'id': video_id, 'title': title, - 'thumbnail': thumbnail, - 'categories': categories, 'description': description, + 'thumbnail': thumbnail, 'duration': duration, + 'timestamp': timestamp, + 'categories': categories, 'formats': formats, }