]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/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%AC%D9%84%D8%B3-%D8%A7%D9%84%D8%B4%D8%A8%D8%A7%D8%A8-%D8%A7%D9%84%D9%85%D9%88%D8%B3%D9%85-1-%D9%83%D9%84%D9%8A%D8%A8-1/clip-275286',
58 'title': 'مجلس الشباب الموسم 1 كليب 1',
59 'timestamp': 1506988800,
60 'upload_date': '20171003',
64 'skip_download': True,
67 'url': 'https://shahid.mbc.net/ar/movies/%D8%A7%D9%84%D9%82%D9%86%D8%A7%D8%B5%D8%A9/movie-151746',
70 # shahid plus subscriber only
71 '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',
75 def _real_initialize(self
):
76 email
, password
= self
._get
_login
_info
()
81 user_data
= self
._download
_json
(
82 'https://shahid.mbc.net/wd/service/users/login',
83 None, 'Logging in', data
=json
.dumps({
87 }).encode('utf-8'), headers
={
88 'Content-Type': 'application/json; charset=UTF-8',
90 except ExtractorError
as e
:
91 if isinstance(e
.cause
, compat_HTTPError
):
95 self
._download
_webpage
(
96 'https://shahid.mbc.net/populateContext',
97 None, 'Populate Context', data
=urlencode_postdata({
98 'firstName': user_data
['firstName'],
99 'lastName': user_data
['lastName'],
100 'userName': user_data
['email'],
101 'csg_user_name': user_data
['email'],
102 'subscriberId': user_data
['id'],
103 'sessionId': user_data
['sessionId'],
106 def _real_extract(self
, url
):
107 page_type
, video_id
= re
.match(self
._VALID
_URL
, url
).groups()
108 if page_type
== 'clip':
109 page_type
= 'episode'
111 playout
= self
._call
_api
(
112 'playout/url/' + video_id
, video_id
)['playout']
114 if playout
.get('drm'):
115 raise ExtractorError('This video is DRM protected.', expected
=True)
117 formats
= self
._extract
_m
3u8_formats
(playout
['url'], video_id
, 'mp4')
118 self
._sort
_formats
(formats
)
120 # video = self._call_api(
121 # 'product/id', video_id, {
123 # 'productType': 'ASSET',
124 # 'productSubType': page_type.upper()
127 response
= self
._download
_json
(
128 'http://api.shahid.net/api/v1_1/%s/%s' % (page_type
, video_id
),
129 video_id
, 'Downloading video JSON', query
={
130 'apiKey': 'sh@hid0nlin3',
131 'hash': 'b2wMCTHpSmyxGqQjJFOycRmLSex+BpTK/ooxy6vHaqs=',
133 data
= response
.get('data', {})
134 error
= data
.get('error')
136 raise ExtractorError(
137 '%s returned error: %s' % (self
.IE_NAME
, '\n'.join(error
.values())),
140 video
= data
[page_type
]
141 title
= video
['title']
144 for category
in video
.get('genres', []) if 'name' in category
]
149 'description': video
.get('description'),
150 'thumbnail': video
.get('thumbnailUrl'),
151 'duration': int_or_none(video
.get('duration')),
152 'timestamp': parse_iso8601(video
.get('referenceDate')),
153 'categories': categories
,
154 'series': video
.get('showTitle') or video
.get('showName'),
155 'season': video
.get('seasonTitle'),
156 'season_number': int_or_none(video
.get('seasonNumber')),
157 'season_id': str_or_none(video
.get('seasonId')),
158 'episode_number': int_or_none(video
.get('number')),
159 'episode_id': video_id
,
164 class ShahidShowIE(ShahidBaseIE
):
165 _VALID_URL
= r
'https?://shahid\.mbc\.net/ar/(?:show|serie)s/[^/]+/(?:show|series)-(?P<id>\d+)'
167 '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',
170 'title': 'رامز قرش البحر',
171 'description': 'md5:c88fa7e0f02b0abd39d417aee0d046ff',
173 'playlist_mincount': 32,
175 'url': 'https://shahid.mbc.net/ar/series/How-to-live-Longer-(The-Big-Think)/series-291861',
176 'only_matching': True
180 def _real_extract(self
, url
):
181 show_id
= self
._match
_id
(url
)
183 product
= self
._call
_api
(
184 'playableAsset', show_id
, {'showId': show_id
})['productModel']
185 playlist
= product
['playlist']
186 playlist_id
= playlist
['id']
187 show
= product
.get('show', {})
189 def page_func(page_num
):
190 playlist
= self
._call
_api
(
191 'product/playlist', show_id
, {
192 'playListId': playlist_id
,
193 'pageNumber': page_num
,
200 for product
in playlist
.get('productList', {}).get('products', []):
201 product_url
= product
.get('productUrl', []).get('url')
204 yield self
.url_result(
205 product_url
, 'Shahid',
206 str_or_none(product
.get('id')),
207 product
.get('title'))
209 entries
= InAdvancePagedList(
211 math
.ceil(playlist
['count'] / self
._PAGE
_SIZE
),
214 return self
.playlist_result(
215 entries
, show_id
, show
.get('title'), show
.get('description'))