]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/vier.py
[extractor/common] Fix rtmp and rtsp formats' URLs in _extract_wowza_formats
[yt-dlp.git] / youtube_dl / extractor / vier.py
CommitLineData
9eb4f404
S
1# coding: utf-8
2from __future__ import unicode_literals
f58487b3
TV
3
4import re
cc1ac110 5import itertools
f58487b3 6
9eb4f404 7from .common import InfoExtractor
7073015a 8from ..utils import urlencode_postdata
9eb4f404
S
9
10
11class VierIE(InfoExtractor):
12 IE_NAME = 'vier'
e129fa08 13 IE_DESC = 'vier.be and vijf.be'
a3ba8a7a 14 _VALID_URL = r'https?://(?:www\.)?(?P<site>vier|vijf)\.be/(?:[^/]+/videos/(?P<display_id>[^/]+)(?:/(?P<id>\d+))?|video/v3/embed/(?P<embed_id>\d+))'
89fd0307 15 _NETRC_MACHINE = 'vier'
9eb4f404
S
16 _TESTS = [{
17 'url': 'http://www.vier.be/planb/videos/het-wordt-warm-de-moestuin/16129',
7073015a 18 'md5': 'e4ae2054a6b040ef1e289e20d111b46e',
9eb4f404
S
19 'info_dict': {
20 'id': '16129',
21 'display_id': 'het-wordt-warm-de-moestuin',
22 'ext': 'mp4',
23 'title': 'Het wordt warm in De Moestuin',
24 'description': 'De vele uren werk eisen hun tol. Wim droomt van assistentie...',
25 },
a3ba8a7a
LV
26 }, {
27 'url': 'http://www.vijf.be/temptationisland/videos/zo-grappig-temptation-island-hosts-moeten-kiezen-tussen-onmogelijke-dilemmas/2561614',
28 'info_dict': {
29 'id': '2561614',
30 'display_id': 'zo-grappig-temptation-island-hosts-moeten-kiezen-tussen-onmogelijke-dilemmas',
31 'ext': 'mp4',
7073015a
S
32 'title': 'md5:84f45fe48b8c1fa296a7f6d208d080a7',
33 'description': 'md5:0356d4981e58b8cbee19355cbd51a8fe',
a3ba8a7a
LV
34 },
35 'params': {
a3ba8a7a
LV
36 'skip_download': True,
37 },
89fd0307 38 }, {
39 'url': 'http://www.vier.be/janigaat/videos/jani-gaat-naar-tokio-aflevering-4/2674839',
40 'info_dict': {
41 'id': '2674839',
42 'display_id': 'jani-gaat-naar-tokio-aflevering-4',
43 'ext': 'mp4',
44 'title': 'Jani gaat naar Tokio - Aflevering 4',
7073015a 45 'description': 'md5:2d169e8186ae4247e50c99aaef97f7b2',
89fd0307 46 },
47 'params': {
89fd0307 48 'skip_download': True,
49 },
50 'skip': 'Requires account credentials',
51 }, {
7073015a
S
52 # Requires account credentials but bypassed extraction via v3/embed page
53 # without metadata
89fd0307 54 'url': 'http://www.vier.be/janigaat/videos/jani-gaat-naar-tokio-aflevering-4/2674839',
55 'info_dict': {
56 'id': '2674839',
57 'display_id': 'jani-gaat-naar-tokio-aflevering-4',
58 'ext': 'mp4',
59 'title': 'jani-gaat-naar-tokio-aflevering-4',
60 },
61 'params': {
89fd0307 62 'skip_download': True,
63 },
64 'expected_warnings': ['Log in to extract metadata'],
9eb4f404 65 }, {
7073015a
S
66 # Without video id in URL
67 'url': 'http://www.vier.be/planb/videos/dit-najaar-plan-b',
9eb4f404
S
68 'only_matching': True,
69 }, {
70 'url': 'http://www.vier.be/video/v3/embed/16129',
71 'only_matching': True,
72 }]
73
89fd0307 74 def _real_initialize(self):
75 self._logged_in = False
76
77 def _login(self, site):
78 username, password = self._get_login_info()
79 if username is None or password is None:
80 return
81
82 login_page = self._download_webpage(
83 'http://www.%s.be/user/login' % site,
84 None, note='Logging in', errnote='Unable to log in',
85 data=urlencode_postdata({
86 'form_id': 'user_login',
87 'name': username,
88 'pass': password,
89 }),
90 headers={'Content-Type': 'application/x-www-form-urlencoded'})
91
92 login_error = self._html_search_regex(
93 r'(?s)<div class="messages error">\s*<div>\s*<h2.+?</h2>(.+?)<',
94 login_page, 'login error', default=None)
95 if login_error:
96 self.report_warning('Unable to log in: %s' % login_error)
97 else:
98 self._logged_in = True
99
9eb4f404
S
100 def _real_extract(self, url):
101 mobj = re.match(self._VALID_URL, url)
102 embed_id = mobj.group('embed_id')
103 display_id = mobj.group('display_id') or embed_id
89fd0307 104 video_id = mobj.group('id') or embed_id
a3ba8a7a 105 site = mobj.group('site')
9eb4f404 106
89fd0307 107 if not self._logged_in:
108 self._login(site)
109
9eb4f404
S
110 webpage = self._download_webpage(url, display_id)
111
89fd0307 112 if r'id="user-login"' in webpage:
113 self.report_warning(
114 'Log in to extract metadata', video_id=display_id)
115 webpage = self._download_webpage(
116 'http://www.%s.be/video/v3/embed/%s' % (site, video_id),
117 display_id)
118
9eb4f404 119 video_id = self._search_regex(
484c9d2d 120 [r'data-nid="(\d+)"', r'"nid"\s*:\s*"(\d+)"'],
7073015a 121 webpage, 'video id', default=video_id or display_id)
9eb4f404 122 application = self._search_regex(
484c9d2d 123 [r'data-application="([^"]+)"', r'"application"\s*:\s*"([^"]+)"'],
a3ba8a7a 124 webpage, 'application', default=site + '_vod')
9eb4f404 125 filename = self._search_regex(
484c9d2d
S
126 [r'data-filename="([^"]+)"', r'"filename"\s*:\s*"([^"]+)"'],
127 webpage, 'filename')
9eb4f404 128
6ad02195 129 playlist_url = 'http://vod.streamcloud.be/%s/_definst_/mp4:%s.mp4/playlist.m3u8' % (application, filename)
0384932e 130 formats = self._extract_wowza_formats(playlist_url, display_id, skip_protocols=['dash'])
19dbaeec 131 self._sort_formats(formats)
9eb4f404
S
132
133 title = self._og_search_title(webpage, default=display_id)
134 description = self._og_search_description(webpage, default=None)
135 thumbnail = self._og_search_thumbnail(webpage, default=None)
136
137 return {
138 'id': video_id,
139 'display_id': display_id,
140 'title': title,
141 'description': description,
142 'thumbnail': thumbnail,
143 'formats': formats,
f58487b3 144 }
9eb4f404
S
145
146
147class VierVideosIE(InfoExtractor):
148 IE_NAME = 'vier:videos'
a3ba8a7a 149 _VALID_URL = r'https?://(?:www\.)?(?P<site>vier|vijf)\.be/(?P<program>[^/]+)/videos(?:\?.*\bpage=(?P<page>\d+)|$)'
9eb4f404
S
150 _TESTS = [{
151 'url': 'http://www.vier.be/demoestuin/videos',
152 'info_dict': {
153 'id': 'demoestuin',
154 },
155 'playlist_mincount': 153,
a3ba8a7a
LV
156 }, {
157 'url': 'http://www.vijf.be/temptationisland/videos',
158 'info_dict': {
159 'id': 'temptationisland',
160 },
161 'playlist_mincount': 159,
9eb4f404
S
162 }, {
163 'url': 'http://www.vier.be/demoestuin/videos?page=6',
164 'info_dict': {
165 'id': 'demoestuin-page6',
166 },
167 'playlist_mincount': 20,
168 }, {
169 'url': 'http://www.vier.be/demoestuin/videos?page=7',
170 'info_dict': {
171 'id': 'demoestuin-page7',
172 },
173 'playlist_mincount': 13,
174 }]
175
176 def _real_extract(self, url):
177 mobj = re.match(self._VALID_URL, url)
178 program = mobj.group('program')
a3ba8a7a 179 site = mobj.group('site')
9eb4f404 180
9eb4f404
S
181 page_id = mobj.group('page')
182 if page_id:
183 page_id = int(page_id)
184 start_page = page_id
9eb4f404
S
185 playlist_id = '%s-page%d' % (program, page_id)
186 else:
187 start_page = 0
9eb4f404
S
188 playlist_id = program
189
190 entries = []
cc1ac110 191 for current_page_id in itertools.count(start_page):
9eb4f404 192 current_page = self._download_webpage(
a3ba8a7a 193 'http://www.%s.be/%s/videos?page=%d' % (site, program, current_page_id),
9eb4f404 194 program,
cc1ac110 195 'Downloading page %d' % (current_page_id + 1))
9eb4f404 196 page_entries = [
a3ba8a7a 197 self.url_result('http://www.' + site + '.be' + video_url, 'Vier')
9eb4f404 198 for video_url in re.findall(
a3ba8a7a 199 r'<h[23]><a href="(/[^/]+/videos/[^/]+(?:/\d+)?)">', current_page)]
9eb4f404 200 entries.extend(page_entries)
cc1ac110
S
201 if page_id or '>Meer<' not in current_page:
202 break
9eb4f404
S
203
204 return self.playlist_result(entries, playlist_id)