2 from __future__ 
import unicode_literals
 
   7 from .common 
import InfoExtractor
 
   9     compat_urllib_parse_urlencode
, 
  21 class AWAANIE(InfoExtractor
): 
  22     _VALID_URL 
= r
'https?://(?:www\.)?(?:awaan|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://awaan.ae/media/%s' % video_id
, 'AWAANVideo') 
  29         elif season_id 
and int(season_id
) > 0: 
  30             return self
.url_result(smuggle_url( 
  31                 'http://awaan.ae/program/season/%s' % season_id
, 
  32                 {'show_id': show_id
}), 'AWAANSeason') 
  34             return self
.url_result( 
  35                 'http://awaan.ae/program/%s' % show_id
, 'AWAANSeason') 
  38 class AWAANBaseIE(InfoExtractor
): 
  39     def _parse_video_data(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') 
  45             'title': self
._live
_title
(title
) if is_live 
else title
, 
  46             'description': video_data
.get('description_en') or video_data
.get('description_ar'), 
  47             'thumbnail': 'http://admin.mangomolo.com/analytics/%s' % img 
if img 
else None, 
  48             'duration': int_or_none(video_data
.get('duration')), 
  49             'timestamp': parse_iso8601(video_data
.get('create_time'), ' '), 
  54 class AWAANVideoIE(AWAANBaseIE
): 
  55     IE_NAME 
= 'awaan:video' 
  56     _VALID_URL 
= r
'https?://(?:www\.)?(?:awaan|dcndigital)\.ae/(?:#/)?(?:video(?:/[^/]+)?|media|catchup/[^/]+/[^/]+)/(?P<id>\d+)' 
  58         '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', 
  59         'md5': '5f61c33bfc7794315c671a62d43116aa', 
  64             'title': 'رحلة العمر : الحلقة 1', 
  65             'description': 'md5:0156e935d870acb8ef0a66d24070c6d6', 
  67             'timestamp': 1227504126, 
  68             'upload_date': '20081124', 
  72         'url': 'http://awaan.ae/video/26723981/%D8%AF%D8%A7%D8%B1-%D8%A7%D9%84%D8%B3%D9%84%D8%A7%D9%85:-%D8%AE%D9%8A%D8%B1-%D8%AF%D9%88%D8%B1-%D8%A7%D9%84%D8%A3%D9%86%D8%B5%D8%A7%D8%B1', 
  73         'only_matching': True, 
  76     def _real_extract(self
, url
): 
  77         video_id 
= self
._match
_id
(url
) 
  79         video_data 
= self
._download
_json
( 
  80             'http://admin.mangomolo.com/analytics/index.php/plus/video?id=%s' % video_id
, 
  81             video_id
, headers
={'Origin': 'http://awaan.ae'}) 
  82         info 
= self
._parse
_video
_data
(video_data
, video_id
, False) 
  84         embed_url 
= 'http://admin.mangomolo.com/analytics/index.php/customers/embed/video?' + compat_urllib_parse_urlencode({ 
  85             'id': video_data
['id'], 
  86             'user_id': video_data
['user_id'], 
  87             'signature': video_data
['signature'], 
  92             '_type': 'url_transparent', 
  94             'ie_key': 'MangomoloVideo', 
  99 class AWAANLiveIE(AWAANBaseIE
): 
 100     IE_NAME 
= 'awaan:live' 
 101     _VALID_URL 
= r
'https?://(?:www\.)?(?:awaan|dcndigital)\.ae/(?:#/)?live/(?P<id>\d+)' 
 103         'url': 'http://awaan.ae/live/6/dubai-tv', 
 107             'title': 're:Dubai Al Oula [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$', 
 108             'upload_date': '20150107', 
 109             'timestamp': 1420588800, 
 113             'skip_download': True, 
 117     def _real_extract(self
, url
): 
 118         channel_id 
= self
._match
_id
(url
) 
 120         channel_data 
= self
._download
_json
( 
 121             'http://admin.mangomolo.com/analytics/index.php/plus/getchanneldetails?channel_id=%s' % channel_id
, 
 122             channel_id
, headers
={'Origin': 'http://awaan.ae'}) 
 123         info 
= self
._parse
_video
_data
(channel_data
, channel_id
, True) 
 125         embed_url 
= 'http://admin.mangomolo.com/analytics/index.php/customers/embed/index?' + compat_urllib_parse_urlencode({ 
 126             'id': base64
.b64encode(channel_data
['user_id'].encode()).decode(), 
 127             'channelid': base64
.b64encode(channel_data
['id'].encode()).decode(), 
 128             'signature': channel_data
['signature'], 
 133             '_type': 'url_transparent', 
 135             'ie_key': 'MangomoloLive', 
 140 class AWAANSeasonIE(InfoExtractor
): 
 141     IE_NAME 
= 'awaan:season' 
 142     _VALID_URL 
= r
'https?://(?:www\.)?(?:awaan|dcndigital)\.ae/(?:#/)?program/(?:(?P<show_id>\d+)|season/(?P<season_id>\d+))' 
 144         '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', 
 148             'title': 'محاضرات الشيخ الشعراوي', 
 150         'playlist_mincount': 27, 
 153     def _real_extract(self
, url
): 
 154         url
, smuggled_data 
= unsmuggle_url(url
, {}) 
 155         show_id
, season_id 
= re
.match(self
._VALID
_URL
, url
).groups() 
 159             data
['season'] = season_id
 
 160             show_id 
= smuggled_data
.get('show_id') 
 162                 season 
= self
._download
_json
( 
 163                     'http://admin.mangomolo.com/analytics/index.php/plus/season_info?id=%s' % season_id
, 
 164                     season_id
, headers
={'Origin': 'http://awaan.ae'}) 
 165                 show_id 
= season
['id'] 
 166         data
['show_id'] = show_id
 
 167         show 
= self
._download
_json
( 
 168             'http://admin.mangomolo.com/analytics/index.php/plus/show', 
 169             show_id
, data
=urlencode_postdata(data
), headers
={ 
 170                 'Origin': 'http://awaan.ae', 
 171                 'Content-Type': 'application/x-www-form-urlencoded' 
 174             season_id 
= show
['default_season'] 
 175         for season 
in show
['seasons']: 
 176             if season
['id'] == season_id
: 
 177                 title 
= season
.get('title_en') or season
['title_ar'] 
 180                 for video 
in show
['videos']: 
 181                     video_id 
= compat_str(video
['id']) 
 182                     entries
.append(self
.url_result( 
 183                         'http://awaan.ae/media/%s' % video_id
, 'AWAANVideo', video_id
)) 
 185                 return self
.playlist_result(entries
, season_id
, title
)