]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/shahid.py
62d41e88a1084c58af259176e28a8b2654ccd4ee
2 from __future__
import unicode_literals
7 from .common
import InfoExtractor
8 from ..compat
import compat_HTTPError
19 class ShahidIE(InfoExtractor
):
20 _NETRC_MACHINE
= 'shahid'
21 _VALID_URL
= r
'https?://shahid\.mbc\.net/ar/(?P<type>episode|movie)/(?P<id>\d+)'
23 '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',
27 'title': 'الملك عبدالله الإنسان الموسم 1 كليب 3',
28 'description': 'الفيلم الوثائقي - الملك عبد الله الإنسان',
30 'timestamp': 1422057420,
31 'upload_date': '20150123',
35 'skip_download': True,
38 'url': 'https://shahid.mbc.net/ar/movie/151746/%D8%A7%D9%84%D9%82%D9%86%D8%A7%D8%B5%D8%A9.html',
41 # shahid plus subscriber only
42 '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',
46 def _real_initialize(self
):
47 email
, password
= self
._get
_login
_info
()
52 user_data
= self
._download
_json
(
53 'https://shahid.mbc.net/wd/service/users/login',
54 None, 'Logging in', data
=json
.dumps({
58 }).encode('utf-8'), headers
={
59 'Content-Type': 'application/json; charset=UTF-8',
61 except ExtractorError
as e
:
62 if isinstance(e
.cause
, compat_HTTPError
):
63 fail_data
= self
._parse
_json
(
64 e
.cause
.read().decode('utf-8'), None, fatal
=False)
66 faults
= fail_data
.get('faults', [])
67 faults_message
= ', '.join([clean_html(fault
['userMessage']) for fault
in faults
if fault
.get('userMessage')])
69 raise ExtractorError(faults_message
, expected
=True)
72 self
._download
_webpage
(
73 'https://shahid.mbc.net/populateContext',
74 None, 'Populate Context', data
=urlencode_postdata({
75 'firstName': user_data
['firstName'],
76 'lastName': user_data
['lastName'],
77 'userName': user_data
['email'],
78 'csg_user_name': user_data
['email'],
79 'subscriberId': user_data
['id'],
80 'sessionId': user_data
['sessionId'],
83 def _get_api_data(self
, response
):
84 data
= response
.get('data', {})
86 error
= data
.get('error')
89 '%s returned error: %s' % (self
.IE_NAME
, '\n'.join(error
.values())),
94 def _real_extract(self
, url
):
95 page_type
, video_id
= re
.match(self
._VALID
_URL
, url
).groups()
97 player
= self
._get
_api
_data
(self
._download
_json
(
98 'https://shahid.mbc.net/arContent/getPlayerContent-param-.id-%s.type-player.html' % video_id
,
99 video_id
, 'Downloading player JSON'))
101 if player
.get('drm'):
102 raise ExtractorError('This video is DRM protected.', expected
=True)
104 formats
= self
._extract
_m
3u8_formats
(player
['url'], video_id
, 'mp4')
105 self
._sort
_formats
(formats
)
107 video
= self
._get
_api
_data
(self
._download
_json
(
108 'http://api.shahid.net/api/v1_1/%s/%s' % (page_type
, video_id
),
109 video_id
, 'Downloading video JSON', query
={
110 'apiKey': 'sh@hid0nlin3',
111 'hash': 'b2wMCTHpSmyxGqQjJFOycRmLSex+BpTK/ooxy6vHaqs=',
114 title
= video
['title']
117 for category
in video
.get('genres', []) if 'name' in category
]
122 'description': video
.get('description'),
123 'thumbnail': video
.get('thumbnailUrl'),
124 'duration': int_or_none(video
.get('duration')),
125 'timestamp': parse_iso8601(video
.get('referenceDate')),
126 'categories': categories
,
127 'series': video
.get('showTitle') or video
.get('showName'),
128 'season': video
.get('seasonTitle'),
129 'season_number': int_or_none(video
.get('seasonNumber')),
130 'season_id': str_or_none(video
.get('seasonId')),
131 'episode_number': int_or_none(video
.get('number')),
132 'episode_id': video_id
,