[tunein] add support for tunein topic,clip and program(fixes #7348)
[youtube-dl] / youtube_dl / extractor / dcn.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..compat import compat_urllib_parse
6 from ..utils import (
7     int_or_none,
8     parse_iso8601,
9     sanitized_Request,
10 )
11
12
13 class DCNIE(InfoExtractor):
14     _VALID_URL = r'https?://(?:www\.)?dcndigital\.ae/(?:#/)?(?:video/.+|show/\d+/.+?)/(?P<id>\d+)'
15     _TEST = {
16         'url': 'http://www.dcndigital.ae/#/show/199074/%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/6887',
17         'info_dict':
18         {
19             'id': '17375',
20             'ext': 'mp4',
21             'title': 'رحلة العمر : الحلقة 1',
22             'description': 'md5:0156e935d870acb8ef0a66d24070c6d6',
23             'thumbnail': 're:^https?://.*\.jpg$',
24             'duration': 2041,
25             'timestamp': 1227504126,
26             'upload_date': '20081124',
27         },
28         'params': {
29             # m3u8 download
30             'skip_download': True,
31         },
32     }
33
34     def _real_extract(self, url):
35         video_id = self._match_id(url)
36
37         request = sanitized_Request(
38             'http://admin.mangomolo.com/analytics/index.php/plus/video?id=%s' % video_id,
39             headers={'Origin': 'http://www.dcndigital.ae'})
40
41         video = self._download_json(request, video_id)
42         title = video.get('title_en') or video['title_ar']
43
44         webpage = self._download_webpage(
45             'http://admin.mangomolo.com/analytics/index.php/customers/embed/video?' +
46             compat_urllib_parse.urlencode({
47                 'id': video['id'],
48                 'user_id': video['user_id'],
49                 'signature': video['signature'],
50                 'countries': 'Q0M=',
51                 'filter': 'DENY',
52             }), video_id)
53
54         m3u8_url = self._html_search_regex(r'file:\s*"([^"]+)', webpage, 'm3u8 url')
55         formats = self._extract_m3u8_formats(
56             m3u8_url, video_id, 'mp4', entry_protocol='m3u8_native', m3u8_id='hls')
57
58         rtsp_url = self._search_regex(
59             r'<a[^>]+href="(rtsp://[^"]+)"', webpage, 'rtsp url', fatal=False)
60         if rtsp_url:
61             formats.append({
62                 'url': rtsp_url,
63                 'format_id': 'rtsp',
64             })
65
66         self._sort_formats(formats)
67
68         img = video.get('img')
69         thumbnail = 'http://admin.mangomolo.com/analytics/%s' % img if img else None
70         duration = int_or_none(video.get('duration'))
71         description = video.get('description_en') or video.get('description_ar')
72         timestamp = parse_iso8601(video.get('create_time') or video.get('update_time'), ' ')
73
74         return {
75             'id': video_id,
76             'title': title,
77             'description': description,
78             'thumbnail': thumbnail,
79             'duration': duration,
80             'timestamp': timestamp,
81             'formats': formats,
82         }