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