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