]>
Commit | Line | Data |
---|---|---|
a1de83e5 O |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
4 | from .common import InfoExtractor | |
85cbcede S |
5 | from ..utils import ( |
6 | determine_ext, | |
c82f051d | 7 | parse_duration, |
8 | traverse_obj, | |
85cbcede S |
9 | unified_timestamp, |
10 | ) | |
a1de83e5 O |
11 | |
12 | ||
13 | class RuvIE(InfoExtractor): | |
85cbcede S |
14 | _VALID_URL = r'https?://(?:www\.)?ruv\.is/(?:sarpurinn/[^/]+|node)/(?P<id>[^/]+(?:/\d+)?)' |
15 | _TESTS = [{ | |
16 | # m3u8 | |
17 | 'url': 'http://ruv.is/sarpurinn/ruv-aukaras/fh-valur/20170516', | |
18 | 'md5': '66347652f4e13e71936817102acc1724', | |
a1de83e5 | 19 | 'info_dict': { |
85cbcede S |
20 | 'id': '1144499', |
21 | 'display_id': 'fh-valur/20170516', | |
a1de83e5 | 22 | 'ext': 'mp4', |
85cbcede S |
23 | 'title': 'FH - Valur', |
24 | 'description': 'Bein útsending frá 3. leik FH og Vals í úrslitum Olísdeildar karla í handbolta.', | |
25 | 'timestamp': 1494963600, | |
26 | 'upload_date': '20170516', | |
27 | }, | |
28 | }, { | |
29 | # mp3 | |
30 | 'url': 'http://ruv.is/sarpurinn/ras-2/morgunutvarpid/20170619', | |
31 | 'md5': '395ea250c8a13e5fdb39d4670ef85378', | |
32 | 'info_dict': { | |
33 | 'id': '1153630', | |
34 | 'display_id': 'morgunutvarpid/20170619', | |
35 | 'ext': 'mp3', | |
36 | 'title': 'Morgunútvarpið', | |
37 | 'description': 'md5:a4cf1202c0a1645ca096b06525915418', | |
38 | 'timestamp': 1497855000, | |
39 | 'upload_date': '20170619', | |
40 | }, | |
41 | }, { | |
42 | 'url': 'http://ruv.is/sarpurinn/ruv/frettir/20170614', | |
43 | 'only_matching': True, | |
44 | }, { | |
45 | 'url': 'http://www.ruv.is/node/1151854', | |
46 | 'only_matching': True, | |
47 | }, { | |
48 | 'url': 'http://ruv.is/sarpurinn/klippa/secret-soltice-hefst-a-morgun', | |
49 | 'only_matching': True, | |
50 | }, { | |
51 | 'url': 'http://ruv.is/sarpurinn/ras-1/morgunvaktin/20170619', | |
52 | 'only_matching': True, | |
53 | }] | |
a1de83e5 O |
54 | |
55 | def _real_extract(self, url): | |
85cbcede S |
56 | display_id = self._match_id(url) |
57 | ||
58 | webpage = self._download_webpage(url, display_id) | |
a1de83e5 O |
59 | |
60 | title = self._og_search_title(webpage) | |
85cbcede S |
61 | |
62 | FIELD_RE = r'video\.%s\s*=\s*(["\'])(?P<url>(?:(?!\1).)+)\1' | |
63 | ||
64 | media_url = self._html_search_regex( | |
65 | FIELD_RE % 'src', webpage, 'video URL', group='url') | |
66 | ||
67 | video_id = self._search_regex( | |
68 | r'<link\b[^>]+\bhref=["\']https?://www\.ruv\.is/node/(\d+)', | |
69 | webpage, 'video id', default=display_id) | |
70 | ||
71 | ext = determine_ext(media_url) | |
72 | ||
73 | if ext == 'm3u8': | |
74 | formats = self._extract_m3u8_formats( | |
75 | media_url, video_id, 'mp4', entry_protocol='m3u8_native', | |
76 | m3u8_id='hls') | |
77 | elif ext == 'mp3': | |
78 | formats = [{ | |
79 | 'format_id': 'mp3', | |
80 | 'url': media_url, | |
81 | 'vcodec': 'none', | |
82 | }] | |
83 | else: | |
84 | formats = [{ | |
85 | 'url': media_url, | |
86 | }] | |
87 | ||
88 | description = self._og_search_description(webpage, default=None) | |
89 | thumbnail = self._og_search_thumbnail( | |
90 | webpage, default=None) or self._search_regex( | |
91 | FIELD_RE % 'poster', webpage, 'thumbnail', fatal=False) | |
92 | timestamp = unified_timestamp(self._html_search_meta( | |
93 | 'article:published_time', webpage, 'timestamp', fatal=False)) | |
a1de83e5 O |
94 | |
95 | return { | |
96 | 'id': video_id, | |
85cbcede | 97 | 'display_id': display_id, |
a1de83e5 | 98 | 'title': title, |
85cbcede S |
99 | 'description': description, |
100 | 'thumbnail': thumbnail, | |
101 | 'timestamp': timestamp, | |
102 | 'formats': formats, | |
a1de83e5 | 103 | } |
c82f051d | 104 | |
105 | ||
106 | class RuvSpilaIE(InfoExtractor): | |
107 | IE_NAME = 'ruv.is:spila' | |
108 | _VALID_URL = r'https?://(?:www\.)?ruv\.is/(?:(?:sjon|ut)varp|(?:krakka|ung)ruv)/spila/.+/(?P<series_id>[0-9]+)/(?P<id>[a-z0-9]+)' | |
109 | _TESTS = [{ | |
110 | 'url': 'https://www.ruv.is/sjonvarp/spila/ithrottir/30657/9jcnd4', | |
111 | 'info_dict': { | |
112 | 'id': '9jcnd4', | |
113 | 'ext': 'mp4', | |
114 | 'title': '01.02.2022', | |
115 | 'chapters': 'count:4', | |
116 | 'timestamp': 1643743500, | |
117 | 'upload_date': '20220201', | |
118 | 'thumbnail': 'https://d38kdhuogyllre.cloudfront.net/fit-in/1960x/filters:quality(65)/hd_posters/94boog-iti3jg.jpg', | |
119 | 'description': 'Íþróttafréttir.', | |
120 | 'age_limit': 0, | |
121 | }, | |
122 | }, { | |
123 | 'url': 'https://www.ruv.is/utvarp/spila/i-ljosi-sogunnar/23795/7hqkre', | |
124 | 'info_dict': { | |
125 | 'id': '7hqkre', | |
126 | 'ext': 'mp3', | |
127 | 'thumbnail': 'https://d38kdhuogyllre.cloudfront.net/fit-in/1960x/filters:quality(65)/hd_posters/7hqkre-7uepao.jpg', | |
128 | 'description': 'md5:8d7046549daff35e9a3190dc9901a120', | |
129 | 'chapters': [], | |
130 | 'upload_date': '20220204', | |
131 | 'timestamp': 1643965500, | |
132 | 'title': 'Nellie Bly II', | |
133 | 'age_limit': 0, | |
134 | }, | |
135 | }, { | |
136 | 'url': 'https://www.ruv.is/ungruv/spila/ungruv/28046/8beuph', | |
137 | 'only_matching': True | |
138 | }, { | |
139 | 'url': 'https://www.ruv.is/krakkaruv/spila/krakkafrettir/30712/9jbgb0', | |
140 | 'only_matching': True | |
141 | }] | |
142 | ||
143 | def _real_extract(self, url): | |
144 | display_id, series_id = self._match_valid_url(url).group('id', 'series_id') | |
145 | program = self._download_json( | |
146 | 'https://www.ruv.is/gql/', display_id, query={'query': '''{ | |
147 | Program(id: %s){ | |
148 | title image description short_description | |
149 | episodes(id: {value: "%s"}) { | |
150 | rating title duration file image firstrun description | |
151 | clips { | |
152 | time text | |
153 | } | |
154 | subtitles { | |
155 | name value | |
156 | } | |
157 | } | |
158 | } | |
159 | }''' % (series_id, display_id)})['data']['Program'] | |
160 | episode = program['episodes'][0] | |
161 | ||
162 | subs = {} | |
163 | for trk in episode.get('subtitles'): | |
164 | if trk.get('name') and trk.get('value'): | |
165 | subs.setdefault(trk['name'], []).append({'url': trk['value'], 'ext': 'vtt'}) | |
166 | ||
167 | media_url = episode['file'] | |
168 | if determine_ext(media_url) == 'm3u8': | |
169 | formats = self._extract_m3u8_formats(media_url, display_id) | |
170 | else: | |
171 | formats = [{'url': media_url}] | |
172 | ||
173 | clips = [ | |
174 | {'start_time': parse_duration(c.get('time')), 'title': c.get('text')} | |
175 | for c in episode.get('clips') or []] | |
176 | ||
177 | return { | |
178 | 'id': display_id, | |
179 | 'title': traverse_obj(program, ('episodes', 0, 'title'), 'title'), | |
180 | 'description': traverse_obj( | |
181 | program, ('episodes', 0, 'description'), 'description', 'short_description', | |
182 | expected_type=lambda x: x or None), | |
183 | 'subtitles': subs, | |
184 | 'thumbnail': episode.get('image', '').replace('$$IMAGESIZE$$', '1960') or None, | |
185 | 'timestamp': unified_timestamp(episode.get('firstrun')), | |
186 | 'formats': formats, | |
187 | 'age_limit': episode.get('rating'), | |
188 | 'chapters': clips | |
189 | } |