]> git.bitcoin.ninja Git - youtube-dl/blob - youtube_dl/extractor/vier.py
Added flag for 'allow_audio_only' format in Twitch queries
[youtube-dl] / youtube_dl / extractor / vier.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5 import itertools
6
7 from .common import InfoExtractor
8
9
10 class VierIE(InfoExtractor):
11     IE_NAME = 'vier'
12     _VALID_URL = r'https?://(?:www\.)?vier\.be/(?:[^/]+/videos/(?P<display_id>[^/]+)(?:/(?P<id>\d+))?|video/v3/embed/(?P<embed_id>\d+))'
13     _TESTS = [{
14         'url': 'http://www.vier.be/planb/videos/het-wordt-warm-de-moestuin/16129',
15         'info_dict': {
16             'id': '16129',
17             'display_id': 'het-wordt-warm-de-moestuin',
18             'ext': 'mp4',
19             'title': 'Het wordt warm in De Moestuin',
20             'description': 'De vele uren werk eisen hun tol. Wim droomt van assistentie...',
21         },
22         'params': {
23             # m3u8 download
24             'skip_download': True,
25         },
26     }, {
27         'url': 'http://www.vier.be/planb/videos/mieren-herders-van-de-bladluizen',
28         'only_matching': True,
29     }, {
30         'url': 'http://www.vier.be/video/v3/embed/16129',
31         'only_matching': True,
32     }]
33
34     def _real_extract(self, url):
35         mobj = re.match(self._VALID_URL, url)
36         embed_id = mobj.group('embed_id')
37         display_id = mobj.group('display_id') or embed_id
38
39         webpage = self._download_webpage(url, display_id)
40
41         video_id = self._search_regex(
42             [r'data-nid="(\d+)"', r'"nid"\s*:\s*"(\d+)"'],
43             webpage, 'video id')
44         application = self._search_regex(
45             [r'data-application="([^"]+)"', r'"application"\s*:\s*"([^"]+)"'],
46             webpage, 'application', default='vier_vod')
47         filename = self._search_regex(
48             [r'data-filename="([^"]+)"', r'"filename"\s*:\s*"([^"]+)"'],
49             webpage, 'filename')
50
51         playlist_url = 'http://vod.streamcloud.be/%s/mp4:_definst_/%s.mp4/playlist.m3u8' % (application, filename)
52         formats = self._extract_m3u8_formats(playlist_url, display_id, 'mp4')
53
54         title = self._og_search_title(webpage, default=display_id)
55         description = self._og_search_description(webpage, default=None)
56         thumbnail = self._og_search_thumbnail(webpage, default=None)
57
58         return {
59             'id': video_id,
60             'display_id': display_id,
61             'title': title,
62             'description': description,
63             'thumbnail': thumbnail,
64             'formats': formats,
65         }
66
67
68 class VierVideosIE(InfoExtractor):
69     IE_NAME = 'vier:videos'
70     _VALID_URL = r'https?://(?:www\.)?vier\.be/(?P<program>[^/]+)/videos(?:\?.*\bpage=(?P<page>\d+)|$)'
71     _TESTS = [{
72         'url': 'http://www.vier.be/demoestuin/videos',
73         'info_dict': {
74             'id': 'demoestuin',
75         },
76         'playlist_mincount': 153,
77     }, {
78         'url': 'http://www.vier.be/demoestuin/videos?page=6',
79         'info_dict': {
80             'id': 'demoestuin-page6',
81         },
82         'playlist_mincount': 20,
83     }, {
84         'url': 'http://www.vier.be/demoestuin/videos?page=7',
85         'info_dict': {
86             'id': 'demoestuin-page7',
87         },
88         'playlist_mincount': 13,
89     }]
90
91     def _real_extract(self, url):
92         mobj = re.match(self._VALID_URL, url)
93         program = mobj.group('program')
94
95         page_id = mobj.group('page')
96         if page_id:
97             page_id = int(page_id)
98             start_page = page_id
99             playlist_id = '%s-page%d' % (program, page_id)
100         else:
101             start_page = 0
102             playlist_id = program
103
104         entries = []
105         for current_page_id in itertools.count(start_page):
106             current_page = self._download_webpage(
107                 'http://www.vier.be/%s/videos?page=%d' % (program, current_page_id),
108                 program,
109                 'Downloading page %d' % (current_page_id + 1))
110             page_entries = [
111                 self.url_result('http://www.vier.be' + video_url, 'Vier')
112                 for video_url in re.findall(
113                     r'<h3><a href="(/[^/]+/videos/[^/]+(?:/\d+)?)">', current_page)]
114             entries.extend(page_entries)
115             if page_id or '>Meer<' not in current_page:
116                 break
117
118         return self.playlist_result(entries, playlist_id)