]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/dcn.py
15a1c40f7a07c36136a0142148af3f7f44f49733
   2 from __future__ 
import unicode_literals
 
   7 from .common 
import InfoExtractor
 
  21 class DCNIE(InfoExtractor
): 
  22     _VALID_URL 
= r
'https?://(?:www\.)?dcndigital\.ae/(?:#/)?show/(?P<show_id>\d+)/[^/]+(?:/(?P<video_id>\d+)/(?P<season_id>\d+))?' 
  24     def _real_extract(self
, url
): 
  25         show_id
, video_id
, season_id 
= re
.match(self
._VALID
_URL
, url
).groups() 
  26         if video_id 
and int(video_id
) > 0: 
  27             return self
.url_result( 
  28                 'http://www.dcndigital.ae/media/%s' % video_id
, 'DCNVideo') 
  29         elif season_id 
and int(season_id
) > 0: 
  30             return self
.url_result(smuggle_url( 
  31                 'http://www.dcndigital.ae/program/season/%s' % season_id
, 
  32                 {'show_id': show_id
}), 'DCNSeason') 
  34             return self
.url_result( 
  35                 'http://www.dcndigital.ae/program/%s' % show_id
, 'DCNSeason') 
  38 class DCNBaseIE(InfoExtractor
): 
  39     def _extract_video_info(self
, video_data
, video_id
, is_live
): 
  40         title 
= video_data
.get('title_en') or video_data
['title_ar'] 
  41         img 
= video_data
.get('img') 
  42         thumbnail 
= 'http://admin.mangomolo.com/analytics/%s' % img 
if img 
else None 
  43         duration 
= int_or_none(video_data
.get('duration')) 
  44         description 
= video_data
.get('description_en') or video_data
.get('description_ar') 
  45         timestamp 
= parse_iso8601(video_data
.get('create_time'), ' ') 
  49             'title': self
._live
_title
(title
) if is_live 
else title
, 
  50             'description': description
, 
  51             'thumbnail': thumbnail
, 
  53             'timestamp': timestamp
, 
  57     def _extract_video_formats(self
, webpage
, video_id
, entry_protocol
): 
  59         m3u8_url 
= self
._html
_search
_regex
( 
  60             r
'file\s*:\s*"([^"]+)', webpage
, 'm3u8 url', fatal
=False) 
  62             formats
.extend(self
._extract
_m
3u8_formats
( 
  63                 m3u8_url
, video_id
, 'mp4', entry_protocol
, m3u8_id
='hls', fatal
=None)) 
  65         rtsp_url 
= self
._search
_regex
( 
  66             r
'<a[^>]+href="(rtsp://[^"]+)"', webpage
, 'rtsp url', fatal
=False) 
  73         self
._sort
_formats
(formats
) 
  77 class DCNVideoIE(DCNBaseIE
): 
  79     _VALID_URL 
= r
'https?://(?:www\.)?dcndigital\.ae/(?:#/)?(?:video/[^/]+|media|catchup/[^/]+/[^/]+)/(?P<id>\d+)' 
  81         'url': 'http://www.dcndigital.ae/#/video/%D8%B1%D8%AD%D9%84%D8%A9-%D8%A7%D9%84%D8%B9%D9%85%D8%B1-%D8%A7%D9%84%D8%AD%D9%84%D9%82%D8%A9-1/17375', 
  86             'title': 'رحلة العمر : الحلقة 1', 
  87             'description': 'md5:0156e935d870acb8ef0a66d24070c6d6', 
  89             'timestamp': 1227504126, 
  90             'upload_date': '20081124', 
  94             'skip_download': True, 
  98     def _real_extract(self
, url
): 
  99         video_id 
= self
._match
_id
(url
) 
 101         request 
= sanitized_Request( 
 102             'http://admin.mangomolo.com/analytics/index.php/plus/video?id=%s' % video_id
, 
 103             headers
={'Origin': 'http://www.dcndigital.ae'}) 
 104         video_data 
= self
._download
_json
(request
, video_id
) 
 105         info 
= self
._extract
_video
_info
(video_data
, video_id
, False) 
 107         webpage 
= self
._download
_webpage
( 
 108             'http://admin.mangomolo.com/analytics/index.php/customers/embed/video?' + 
 109             compat_urllib_parse
.urlencode({ 
 110                 'id': video_data
['id'], 
 111                 'user_id': video_data
['user_id'], 
 112                 'signature': video_data
['signature'], 
 116         info
['formats'] = self
._extract
_video
_formats
(webpage
, video_id
, 'm3u8_native') 
 120 class DCNLiveIE(DCNBaseIE
): 
 122     _VALID_URL 
= r
'https?://(?:www\.)?dcndigital\.ae/(?:#/)?live/(?P<id>\d+)' 
 124     def _real_extract(self
, url
): 
 125         channel_id 
= self
._match
_id
(url
) 
 127         request 
= sanitized_Request( 
 128             'http://admin.mangomolo.com/analytics/index.php/plus/getchanneldetails?channel_id=%s' % channel_id
, 
 129             headers
={'Origin': 'http://www.dcndigital.ae'}) 
 131         channel_data 
= self
._download
_json
(request
, channel_id
) 
 132         info 
= self
._extract
_video
_info
(channel_data
, channel_id
, True) 
 134         webpage 
= self
._download
_webpage
( 
 135             'http://admin.mangomolo.com/analytics/index.php/customers/embed/index?' + 
 136             compat_urllib_parse
.urlencode({ 
 137                 'id': base64
.b64encode(channel_data
['user_id'].encode()).decode(), 
 138                 'channelid': base64
.b64encode(channel_data
['id'].encode()).decode(), 
 139                 'signature': channel_data
['signature'], 
 143         info
['formats'] = self
._extract
_video
_formats
(webpage
, channel_id
, 'm3u8') 
 147 class DCNSeasonIE(InfoExtractor
): 
 148     IE_NAME 
= 'dcn:season' 
 149     _VALID_URL 
= r
'https?://(?:www\.)?dcndigital\.ae/(?:#/)?program/(?:(?P<show_id>\d+)|season/(?P<season_id>\d+))' 
 151         'url': 'http://dcndigital.ae/#/program/205024/%D9%85%D8%AD%D8%A7%D8%B6%D8%B1%D8%A7%D8%AA-%D8%A7%D9%84%D8%B4%D9%8A%D8%AE-%D8%A7%D9%84%D8%B4%D8%B9%D8%B1%D8%A7%D9%88%D9%8A', 
 155             'title': 'محاضرات الشيخ الشعراوي', 
 157         'playlist_mincount': 27, 
 160     def _real_extract(self
, url
): 
 161         url
, smuggled_data 
= unsmuggle_url(url
, {}) 
 162         show_id
, season_id 
= re
.match(self
._VALID
_URL
, url
).groups() 
 166             data
['season'] = season_id
 
 167             show_id 
= smuggled_data
.get('show_id') 
 169                 request 
= sanitized_Request( 
 170                     'http://admin.mangomolo.com/analytics/index.php/plus/season_info?id=%s' % season_id
, 
 171                     headers
={'Origin': 'http://www.dcndigital.ae'}) 
 172                 season 
= self
._download
_json
(request
, season_id
) 
 173                 show_id 
= season
['id'] 
 174         data
['show_id'] = show_id
 
 175         request 
= sanitized_Request( 
 176             'http://admin.mangomolo.com/analytics/index.php/plus/show', 
 177             compat_urllib_parse
.urlencode(data
), 
 179                 'Origin': 'http://www.dcndigital.ae', 
 180                 'Content-Type': 'application/x-www-form-urlencoded' 
 183         show 
= self
._download
_json
(request
, show_id
) 
 185             season_id 
= show
['default_season'] 
 186         for season 
in show
['seasons']: 
 187             if season
['id'] == season_id
: 
 188                 title 
= season
.get('title_en') or season
['title_ar'] 
 191                 for video 
in show
['videos']: 
 192                     video_id 
= compat_str(video
['id']) 
 193                     entries
.append(self
.url_result( 
 194                         'http://www.dcndigital.ae/media/%s' % video_id
, 'DCNVideo', video_id
)) 
 196                 return self
.playlist_result(entries
, season_id
, title
)