]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/shahid.py
2 from __future__
import unicode_literals
9 from ..compat
import compat_HTTPError
21 class ShahidBaseIE(AWSIE
):
22 _AWS_PROXY_HOST
= 'api2.shahid.net'
23 _AWS_API_KEY
= '2RRtuMHx95aNI1Kvtn2rChEuwsCogUd4samGPjLh'
25 def _handle_error(self
, e
):
26 fail_data
= self
._parse
_json
(
27 e
.cause
.read().decode('utf-8'), None, fatal
=False)
29 faults
= fail_data
.get('faults', [])
30 faults_message
= ', '.join([clean_html(fault
['userMessage']) for fault
in faults
if fault
.get('userMessage')])
32 raise ExtractorError(faults_message
, expected
=True)
34 def _call_api(self
, path
, video_id
, request
=None):
37 query
['request'] = json
.dumps(request
)
39 return self
._aws
_execute
_api
({
40 'uri': '/proxy/v2/' + path
,
41 'access_key': 'AKIAI6X4TYCIXM2B7MUQ',
42 'secret_key': '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',
44 except ExtractorError
as e
:
45 if isinstance(e
.cause
, compat_HTTPError
):
50 class ShahidIE(ShahidBaseIE
):
51 _NETRC_MACHINE
= 'shahid'
52 _VALID_URL
= r
'https?://shahid\.mbc\.net/ar/(?:serie|show|movie)s/[^/]+/(?P<type>episode|clip|movie)-(?P<id>\d+)'
54 'url': 'https://shahid.mbc.net/ar/shows/%D9%85%D8%AA%D8%AD%D9%81-%D8%A7%D9%84%D8%AF%D8%AD%D9%8A%D8%AD-%D8%A7%D9%84%D9%85%D9%88%D8%B3%D9%85-1-%D9%83%D9%84%D9%8A%D8%A8-1/clip-816924',
58 'title': 'متحف الدحيح الموسم 1 كليب 1',
59 'timestamp': 1602806400,
60 'upload_date': '20201016',
61 'description': 'برومو',
63 'categories': ['كوميديا'],
67 'skip_download': True,
70 'url': 'https://shahid.mbc.net/ar/movies/%D8%A7%D9%84%D9%82%D9%86%D8%A7%D8%B5%D8%A9/movie-151746',
73 # shahid plus subscriber only
74 'url': 'https://shahid.mbc.net/ar/series/%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/episode-90511',
78 def _real_initialize(self
):
79 email
, password
= self
._get
_login
_info
()
84 user_data
= self
._download
_json
(
85 'https://shahid.mbc.net/wd/service/users/login',
86 None, 'Logging in', data
=json
.dumps({
90 }).encode('utf-8'), headers
={
91 'Content-Type': 'application/json; charset=UTF-8',
93 except ExtractorError
as e
:
94 if isinstance(e
.cause
, compat_HTTPError
):
98 self
._download
_webpage
(
99 'https://shahid.mbc.net/populateContext',
100 None, 'Populate Context', data
=urlencode_postdata({
101 'firstName': user_data
['firstName'],
102 'lastName': user_data
['lastName'],
103 'userName': user_data
['email'],
104 'csg_user_name': user_data
['email'],
105 'subscriberId': user_data
['id'],
106 'sessionId': user_data
['sessionId'],
109 def _real_extract(self
, url
):
110 page_type
, video_id
= re
.match(self
._VALID
_URL
, url
).groups()
111 if page_type
== 'clip':
112 page_type
= 'episode'
114 playout
= self
._call
_api
(
115 'playout/new/url/' + video_id
, video_id
)['playout']
117 if not self
.get_param('allow_unplayable_formats') and playout
.get('drm'):
118 raise ExtractorError('This video is DRM protected.', expected
=True)
120 formats
= self
._extract
_m
3u8_formats
(re
.sub(
121 # https://docs.aws.amazon.com/mediapackage/latest/ug/manifest-filtering.html
122 r
'aws\.manifestfilter=[\w:;,-]+&?',
123 '', playout
['url']), video_id
, 'mp4')
124 self
._sort
_formats
(formats
)
126 # video = self._call_api(
127 # 'product/id', video_id, {
129 # 'productType': 'ASSET',
130 # 'productSubType': page_type.upper()
133 response
= self
._download
_json
(
134 'http://api.shahid.net/api/v1_1/%s/%s' % (page_type
, video_id
),
135 video_id
, 'Downloading video JSON', query
={
136 'apiKey': 'sh@hid0nlin3',
137 'hash': 'b2wMCTHpSmyxGqQjJFOycRmLSex+BpTK/ooxy6vHaqs=',
139 data
= response
.get('data', {})
140 error
= data
.get('error')
142 raise ExtractorError(
143 '%s returned error: %s' % (self
.IE_NAME
, '\n'.join(error
.values())),
146 video
= data
[page_type
]
147 title
= video
['title']
150 for category
in video
.get('genres', []) if 'name' in category
]
155 'description': video
.get('description'),
156 'thumbnail': video
.get('thumbnailUrl'),
157 'duration': int_or_none(video
.get('duration')),
158 'timestamp': parse_iso8601(video
.get('referenceDate')),
159 'categories': categories
,
160 'series': video
.get('showTitle') or video
.get('showName'),
161 'season': video
.get('seasonTitle'),
162 'season_number': int_or_none(video
.get('seasonNumber')),
163 'season_id': str_or_none(video
.get('seasonId')),
164 'episode_number': int_or_none(video
.get('number')),
165 'episode_id': video_id
,
170 class ShahidShowIE(ShahidBaseIE
):
171 _VALID_URL
= r
'https?://shahid\.mbc\.net/ar/(?:show|serie)s/[^/]+/(?:show|series)-(?P<id>\d+)'
173 'url': 'https://shahid.mbc.net/ar/shows/%D8%B1%D8%A7%D9%85%D8%B2-%D9%82%D8%B1%D8%B4-%D8%A7%D9%84%D8%A8%D8%AD%D8%B1/show-79187',
176 'title': 'رامز قرش البحر',
177 'description': 'md5:c88fa7e0f02b0abd39d417aee0d046ff',
179 'playlist_mincount': 32,
181 'url': 'https://shahid.mbc.net/ar/series/How-to-live-Longer-(The-Big-Think)/series-291861',
182 'only_matching': True
186 def _real_extract(self
, url
):
187 show_id
= self
._match
_id
(url
)
189 product
= self
._call
_api
(
190 'playableAsset', show_id
, {'showId': show_id}
)['productModel']
191 playlist
= product
['playlist']
192 playlist_id
= playlist
['id']
193 show
= product
.get('show', {})
195 def page_func(page_num
):
196 playlist
= self
._call
_api
(
197 'product/playlist', show_id
, {
198 'playListId': playlist_id
,
199 'pageNumber': page_num
,
206 for product
in playlist
.get('productList', {}).get('products', []):
207 product_url
= product
.get('productUrl', []).get('url')
210 yield self
.url_result(
211 product_url
, 'Shahid',
212 str_or_none(product
.get('id')),
213 product
.get('title'))
215 entries
= InAdvancePagedList(
217 math
.ceil(playlist
['count'] / self
._PAGE
_SIZE
),
220 return self
.playlist_result(
221 entries
, show_id
, show
.get('title'), show
.get('description'))