]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/azmedien.py
Update changelog.
[youtubedl] / youtube_dl / extractor / azmedien.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from .kaltura import KalturaIE
8 from ..utils import (
9 get_element_by_class,
10 get_element_by_id,
11 strip_or_none,
12 urljoin,
13 )
14
15
16 class AZMedienBaseIE(InfoExtractor):
17 def _kaltura_video(self, partner_id, entry_id):
18 return self.url_result(
19 'kaltura:%s:%s' % (partner_id, entry_id), ie=KalturaIE.ie_key(),
20 video_id=entry_id)
21
22
23 class AZMedienIE(AZMedienBaseIE):
24 IE_DESC = 'AZ Medien videos'
25 _VALID_URL = r'''(?x)
26 https?://
27 (?:www\.)?
28 (?:
29 telezueri\.ch|
30 telebaern\.tv|
31 telem1\.ch
32 )/
33 [0-9]+-show-[^/\#]+
34 (?:
35 /[0-9]+-episode-[^/\#]+
36 (?:
37 /[0-9]+-segment-(?:[^/\#]+\#)?|
38 \#
39 )|
40 \#
41 )
42 (?P<id>[^\#]+)
43 '''
44
45 _TESTS = [{
46 # URL with 'segment'
47 'url': 'http://www.telezueri.ch/62-show-zuerinews/13772-episode-sonntag-18-dezember-2016/32419-segment-massenabweisungen-beim-hiltl-club-wegen-pelzboom',
48 'info_dict': {
49 'id': '1_2444peh4',
50 'ext': 'mp4',
51 'title': 'Massenabweisungen beim Hiltl Club wegen Pelzboom',
52 'description': 'md5:9ea9dd1b159ad65b36ddcf7f0d7c76a8',
53 'uploader_id': 'TeleZ?ri',
54 'upload_date': '20161218',
55 'timestamp': 1482084490,
56 },
57 'params': {
58 'skip_download': True,
59 },
60 }, {
61 # URL with 'segment' and fragment:
62 'url': 'http://www.telebaern.tv/118-show-news/14240-episode-dienstag-17-januar-2017/33666-segment-achtung-gefahr#zu-wenig-pflegerinnen-und-pfleger',
63 'only_matching': True
64 }, {
65 # URL with 'episode' and fragment:
66 'url': 'http://www.telem1.ch/47-show-sonntalk/13986-episode-soldaten-fuer-grenzschutz-energiestrategie-obama-bilanz#soldaten-fuer-grenzschutz-energiestrategie-obama-bilanz',
67 'only_matching': True
68 }, {
69 # URL with 'show' and fragment:
70 'url': 'http://www.telezueri.ch/66-show-sonntalk#burka-plakate-trump-putin-china-besuch',
71 'only_matching': True
72 }]
73
74 def _real_extract(self, url):
75 video_id = self._match_id(url)
76
77 webpage = self._download_webpage(url, video_id)
78
79 partner_id = self._search_regex(
80 r'<script[^>]+src=["\'](?:https?:)?//(?:[^/]+\.)?kaltura\.com(?:/[^/]+)*/(?:p|partner_id)/([0-9]+)',
81 webpage, 'kaltura partner id')
82 entry_id = self._html_search_regex(
83 r'<a[^>]+data-id=(["\'])(?P<id>(?:(?!\1).)+)\1[^>]+data-slug=["\']%s'
84 % re.escape(video_id), webpage, 'kaltura entry id', group='id')
85
86 return self._kaltura_video(partner_id, entry_id)
87
88
89 class AZMedienPlaylistIE(AZMedienBaseIE):
90 IE_DESC = 'AZ Medien playlists'
91 _VALID_URL = r'''(?x)
92 https?://
93 (?:www\.)?
94 (?:
95 telezueri\.ch|
96 telebaern\.tv|
97 telem1\.ch
98 )/
99 (?P<id>[0-9]+-
100 (?:
101 show|
102 topic|
103 themen
104 )-[^/\#]+
105 (?:
106 /[0-9]+-episode-[^/\#]+
107 )?
108 )$
109 '''
110
111 _TESTS = [{
112 # URL with 'episode'
113 'url': 'http://www.telebaern.tv/118-show-news/13735-episode-donnerstag-15-dezember-2016',
114 'info_dict': {
115 'id': '118-show-news/13735-episode-donnerstag-15-dezember-2016',
116 'title': 'News - Donnerstag, 15. Dezember 2016',
117 },
118 'playlist_count': 9,
119 }, {
120 # URL with 'themen'
121 'url': 'http://www.telem1.ch/258-themen-tele-m1-classics',
122 'info_dict': {
123 'id': '258-themen-tele-m1-classics',
124 'title': 'Tele M1 Classics',
125 },
126 'playlist_mincount': 15,
127 }, {
128 # URL with 'topic', contains nested playlists
129 'url': 'http://www.telezueri.ch/219-topic-aera-trump-hat-offiziell-begonnen',
130 'only_matching': True,
131 }, {
132 # URL with 'show' only
133 'url': 'http://www.telezueri.ch/86-show-talktaeglich',
134 'only_matching': True
135 }]
136
137 def _real_extract(self, url):
138 show_id = self._match_id(url)
139 webpage = self._download_webpage(url, show_id)
140
141 entries = []
142
143 partner_id = self._search_regex(
144 r'src=["\'](?:https?:)?//(?:[^/]+\.)kaltura\.com/(?:[^/]+/)*(?:p|partner_id)/(\d+)',
145 webpage, 'kaltura partner id', default=None)
146
147 if partner_id:
148 entries = [
149 self._kaltura_video(partner_id, m.group('id'))
150 for m in re.finditer(
151 r'data-id=(["\'])(?P<id>(?:(?!\1).)+)\1', webpage)]
152
153 if not entries:
154 entries = [
155 self.url_result(m.group('url'), ie=AZMedienIE.ie_key())
156 for m in re.finditer(
157 r'<a[^>]+data-real=(["\'])(?P<url>http.+?)\1', webpage)]
158
159 if not entries:
160 entries = [
161 # May contain nested playlists (e.g. [1]) thus no explicit
162 # ie_key
163 # 1. http://www.telezueri.ch/219-topic-aera-trump-hat-offiziell-begonnen)
164 self.url_result(urljoin(url, m.group('url')))
165 for m in re.finditer(
166 r'<a[^>]+name=[^>]+href=(["\'])(?P<url>/.+?)\1', webpage)]
167
168 title = self._search_regex(
169 r'episodeShareTitle\s*=\s*(["\'])(?P<title>(?:(?!\1).)+)\1',
170 webpage, 'title',
171 default=strip_or_none(get_element_by_id(
172 'video-title', webpage)), group='title')
173
174 return self.playlist_result(entries, show_id, title)
175
176
177 class AZMedienShowPlaylistIE(AZMedienBaseIE):
178 IE_DESC = 'AZ Medien show playlists'
179 _VALID_URL = r'''(?x)
180 https?://
181 (?:www\.)?
182 (?:
183 telezueri\.ch|
184 telebaern\.tv|
185 telem1\.ch
186 )/
187 (?:
188 all-episodes|
189 alle-episoden
190 )/
191 (?P<id>[^/?#&]+)
192 '''
193
194 _TEST = {
195 'url': 'http://www.telezueri.ch/all-episodes/astrotalk',
196 'info_dict': {
197 'id': 'astrotalk',
198 'title': 'TeleZüri: AstroTalk - alle episoden',
199 'description': 'md5:4c0f7e7d741d906004266e295ceb4a26',
200 },
201 'playlist_mincount': 13,
202 }
203
204 def _real_extract(self, url):
205 playlist_id = self._match_id(url)
206 webpage = self._download_webpage(url, playlist_id)
207 episodes = get_element_by_class('search-mobile-box', webpage)
208 entries = [self.url_result(
209 urljoin(url, m.group('url'))) for m in re.finditer(
210 r'<a[^>]+href=(["\'])(?P<url>(?:(?!\1).)+)\1', episodes)]
211 title = self._og_search_title(webpage, fatal=False)
212 description = self._og_search_description(webpage)
213 return self.playlist_result(entries, playlist_id, title, description)