]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/drtv.py
2 from __future__
import unicode_literals
4 from .common
import InfoExtractor
16 class DRTVIE(InfoExtractor
):
17 _VALID_URL
= r
'https?://(?:www\.)?dr\.dk/(?:tv/se|nyheder|radio/ondemand)/(?:[^/]+/)*(?P<id>[\da-z-]+)(?:[/#?]|$)'
20 'url': 'https://www.dr.dk/tv/se/boern/ultra/klassen-ultra/klassen-darlig-taber-10',
21 'md5': '25e659cccc9a2ed956110a299fdf5983',
23 'id': 'klassen-darlig-taber-10',
25 'title': 'Klassen - Dårlig taber (10)',
26 'description': 'md5:815fe1b7fa656ed80580f31e8b3c79aa',
27 'timestamp': 1471991907,
28 'upload_date': '20160823',
32 'skip_download': True,
35 'url': 'https://www.dr.dk/nyheder/indland/live-christianias-rydning-af-pusher-street-er-i-gang',
36 'md5': '2c37175c718155930f939ef59952474a',
38 'id': 'christiania-pusher-street-ryddes-drdkrjpo',
40 'title': 'LIVE Christianias rydning af Pusher Street er i gang',
41 'description': '- Det er det fedeste, der er sket i 20 år, fortæller christianit til DR Nyheder.',
42 'timestamp': 1472800279,
43 'upload_date': '20160902',
48 def _real_extract(self
, url
):
49 video_id
= self
._match
_id
(url
)
51 webpage
= self
._download
_webpage
(url
, video_id
)
53 if '>Programmet er ikke længere tilgængeligt' in webpage
:
55 'Video %s is not available' % video_id
, expected
=True)
57 video_id
= self
._search
_regex
(
58 (r
'data-(?:material-identifier|episode-slug)="([^"]+)"',
59 r
'data-resource="[^>"]+mu/programcard/expanded/([^"]+)"'),
62 programcard
= self
._download
_json
(
63 'http://www.dr.dk/mu/programcard/expanded/%s' % video_id
,
64 video_id
, 'Downloading video JSON')
65 data
= programcard
['Data'][0]
67 title
= remove_end(self
._og
_search
_title
(
68 webpage
, default
=None), ' | TV | DR') or data
['Title']
69 description
= self
._og
_search
_description
(
70 webpage
, default
=None) or data
.get('Description')
72 timestamp
= parse_iso8601(data
.get('CreatedTime'))
77 restricted_to_denmark
= False
82 for asset
in data
['Assets']:
83 kind
= asset
.get('Kind')
85 thumbnail
= asset
.get('Uri')
86 elif kind
in ('VideoResource', 'AudioResource'):
87 duration
= float_or_none(asset
.get('DurationInMilliseconds'), 1000)
88 restricted_to_denmark
= asset
.get('RestrictedToDenmark')
89 spoken_subtitles
= asset
.get('Target') == 'SpokenSubtitles'
90 for link
in asset
.get('Links', []):
94 target
= link
.get('Target')
95 format_id
= target
or ''
99 format_id
+= '-spoken-subtitles'
101 f4m_formats
= self
._extract
_f
4m
_formats
(
102 uri
+ '?hdcore=3.3.0&plugin=aasp-3.3.0.99.43',
103 video_id
, preference
, f4m_id
=format_id
)
104 if kind
== 'AudioResource':
105 for f
in f4m_formats
:
107 formats
.extend(f4m_formats
)
108 elif target
== 'HLS':
109 formats
.extend(self
._extract
_m
3u8_formats
(
110 uri
, video_id
, 'mp4', entry_protocol
='m3u8_native',
111 preference
=preference
, m3u8_id
=format_id
))
113 bitrate
= link
.get('Bitrate')
115 format_id
+= '-%s' % bitrate
118 'format_id': format_id
,
119 'tbr': int_or_none(bitrate
),
120 'ext': link
.get('FileFormat'),
121 'vcodec': 'none' if kind
== 'AudioResource' else None,
123 subtitles_list
= asset
.get('SubtitlesList')
124 if isinstance(subtitles_list
, list):
128 for subs
in subtitles_list
:
129 if not subs
.get('Uri'):
131 lang
= subs
.get('Language') or 'da'
132 subtitles
.setdefault(LANGS
.get(lang
, lang
), []).append({
134 'ext': mimetype2ext(subs
.get('MimeType')) or 'vtt'
137 if not formats
and restricted_to_denmark
:
138 self
.raise_geo_restricted(
139 'Unfortunately, DR is not allowed to show this program outside Denmark.',
142 self
._sort
_formats
(formats
)
147 'description': description
,
148 'thumbnail': thumbnail
,
149 'timestamp': timestamp
,
150 'duration': duration
,
152 'subtitles': subtitles
,
156 class DRTVLiveIE(InfoExtractor
):
157 IE_NAME
= 'drtv:live'
158 _VALID_URL
= r
'https?://(?:www\.)?dr\.dk/(?:tv|TV)/live/(?P<id>[\da-z-]+)'
160 'url': 'https://www.dr.dk/tv/live/dr1',
164 'title': 're:^DR1 [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
168 'skip_download': True,
172 def _real_extract(self
, url
):
173 channel_id
= self
._match
_id
(url
)
174 channel_data
= self
._download
_json
(
175 'https://www.dr.dk/mu-online/api/1.0/channel/' + channel_id
,
177 title
= self
._live
_title
(channel_data
['Title'])
180 for streaming_server
in channel_data
.get('StreamingServers', []):
181 server
= streaming_server
.get('Server')
184 link_type
= streaming_server
.get('LinkType')
185 for quality
in streaming_server
.get('Qualities', []):
186 for stream
in quality
.get('Streams', []):
187 stream_path
= stream
.get('Stream')
190 stream_url
= update_url_query(
191 '%s/%s' % (server
, stream_path
), {'b': ''})
192 if link_type
== 'HLS':
193 formats
.extend(self
._extract
_m
3u8_formats
(
194 stream_url
, channel_id
, 'mp4',
195 m3u8_id
=link_type
, fatal
=False, live
=True))
196 elif link_type
== 'HDS':
197 formats
.extend(self
._extract
_f
4m
_formats
(update_url_query(
198 '%s/%s' % (server
, stream_path
), {'hdcore': '3.7.0'}),
199 channel_id
, f4m_id
=link_type
, fatal
=False))
200 self
._sort
_formats
(formats
)
205 'thumbnail': channel_data
.get('PrimaryImageUri'),