aboutsummaryrefslogtreecommitdiffhomepage
path: root/youtube_dl/extractor/azmedien.py
blob: 68f26e2cad635bd8eb23a14ced3e1b90b2b320fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# coding: utf-8
from __future__ import unicode_literals

import re

from .common import InfoExtractor
from .kaltura import KalturaIE
from ..utils import (
    get_element_by_class,
    get_element_by_id,
    strip_or_none,
    urljoin,
)


class AZMedienBaseIE(InfoExtractor):
    def _kaltura_video(self, partner_id, entry_id):
        return self.url_result(
            'kaltura:%s:%s' % (partner_id, entry_id), ie=KalturaIE.ie_key(),
            video_id=entry_id)


class AZMedienIE(AZMedienBaseIE):
    IE_DESC = 'AZ Medien videos'
    _VALID_URL = r'''(?x)
                    https?://
                        (?:www\.)?
                        (?:
                            telezueri\.ch|
                            telebaern\.tv|
                            telem1\.ch
                        )/
                        [0-9]+-show-[^/\#]+
                        (?:
                            /[0-9]+-episode-[^/\#]+
                            (?:
                                /[0-9]+-segment-(?:[^/\#]+\#)?|
                                \#
                            )|
                            \#
                        )
                        (?P<id>[^\#]+)
                    '''

    _TESTS = [{
        # URL with 'segment'
        'url': 'http://www.telezueri.ch/62-show-zuerinews/13772-episode-sonntag-18-dezember-2016/32419-segment-massenabweisungen-beim-hiltl-club-wegen-pelzboom',
        'info_dict': {
            'id': '1_2444peh4',
            'ext': 'mp4',
            'title': 'Massenabweisungen beim Hiltl Club wegen Pelzboom',
            'description': 'md5:9ea9dd1b159ad65b36ddcf7f0d7c76a8',
            'uploader_id': 'TeleZ?ri',
            'upload_date': '20161218',
            'timestamp': 1482084490,
        },
        'params': {
            'skip_download': True,
        },
    }, {
        # URL with 'segment' and fragment:
        'url': 'http://www.telebaern.tv/118-show-news/14240-episode-dienstag-17-januar-2017/33666-segment-achtung-gefahr#zu-wenig-pflegerinnen-und-pfleger',
        'only_matching': True
    }, {
        # URL with 'episode' and fragment:
        'url': 'http://www.telem1.ch/47-show-sonntalk/13986-episode-soldaten-fuer-grenzschutz-energiestrategie-obama-bilanz#soldaten-fuer-grenzschutz-energiestrategie-obama-bilanz',
        'only_matching': True
    }, {
        # URL with 'show' and fragment:
        'url': 'http://www.telezueri.ch/66-show-sonntalk#burka-plakate-trump-putin-china-besuch',
        'only_matching': True
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)

        webpage = self._download_webpage(url, video_id)

        partner_id = self._search_regex(
            r'<script[^>]+src=["\'](?:https?:)?//(?:[^/]+\.)?kaltura\.com(?:/[^/]+)*/(?:p|partner_id)/([0-9]+)',
            webpage, 'kaltura partner id')
        entry_id = self._html_search_regex(
            r'<a[^>]+data-id=(["\'])(?P<id>(?:(?!\1).)+)\1[^>]+data-slug=["\']%s'
            % re.escape(video_id), webpage, 'kaltura entry id', group='id')

        return self._kaltura_video(partner_id, entry_id)


class AZMedienPlaylistIE(AZMedienBaseIE):
    IE_DESC = 'AZ Medien playlists'
    _VALID_URL = r'''(?x)
                    https?://
                        (?:www\.)?
                        (?:
                            telezueri\.ch|
                            telebaern\.tv|
                            telem1\.ch
                        )/
                        (?P<id>[0-9]+-
                            (?:
                                show|
                                topic|
                                themen
                            )-[^/\#]+
                            (?:
                                /[0-9]+-episode-[^/\#]+
                            )?
                        )$
                    '''

    _TESTS = [{
        # URL with 'episode'
        'url': 'http://www.telebaern.tv/118-show-news/13735-episode-donnerstag-15-dezember-2016',
        'info_dict': {
            'id': '118-show-news/13735-episode-donnerstag-15-dezember-2016',
            'title': 'News - Donnerstag, 15. Dezember 2016',
        },
        'playlist_count': 9,
    }, {
        # URL with 'themen'
        'url': 'http://www.telem1.ch/258-themen-tele-m1-classics',
        'info_dict': {
            'id': '258-themen-tele-m1-classics',
            'title': 'Tele M1 Classics',
        },
        'playlist_mincount': 15,
    }, {
        # URL with 'topic', contains nested playlists
        'url': 'http://www.telezueri.ch/219-topic-aera-trump-hat-offiziell-begonnen',
        'only_matching': True,
    }, {
        # URL with 'show' only
        'url': 'http://www.telezueri.ch/86-show-talktaeglich',
        'only_matching': True
    }]

    def _real_extract(self, url):
        show_id = self._match_id(url)
        webpage = self._download_webpage(url, show_id)

        entries = []

        partner_id = self._search_regex(
            r'src=["\'](?:https?:)?//(?:[^/]+\.)kaltura\.com/(?:[^/]+/)*(?:p|partner_id)/(\d+)',
            webpage, 'kaltura partner id', default=None)

        if partner_id:
            entries = [
                self._kaltura_video(partner_id, m.group('id'))
                for m in re.finditer(
                    r'data-id=(["\'])(?P<id>(?:(?!\1).)+)\1', webpage)]

        if not entries:
            entries = [
                self.url_result(m.group('url'), ie=AZMedienIE.ie_key())
                for m in re.finditer(
                    r'<a[^>]+data-real=(["\'])(?P<url>http.+?)\1', webpage)]

        if not entries:
            entries = [
                # May contain nested playlists (e.g. [1]) thus no explicit
                # ie_key
                # 1. http://www.telezueri.ch/219-topic-aera-trump-hat-offiziell-begonnen)
                self.url_result(urljoin(url, m.group('url')))
                for m in re.finditer(
                    r'<a[^>]+name=[^>]+href=(["\'])(?P<url>/.+?)\1', webpage)]

        title = self._search_regex(
            r'episodeShareTitle\s*=\s*(["\'])(?P<title>(?:(?!\1).)+)\1',
            webpage, 'title',
            default=strip_or_none(get_element_by_id(
                'video-title', webpage)), group='title')

        return self.playlist_result(entries, show_id, title)


class AZMedienShowPlaylistIE(AZMedienBaseIE):
    IE_DESC = 'AZ Medien show playlists'
    _VALID_URL = r'''(?x)
                    https?://
                        (?:www\.)?
                        (?:
                            telezueri\.ch|
                            telebaern\.tv|
                            telem1\.ch
                        )/
                        (?:
                            all-episodes|
                            alle-episoden
                        )/
                        (?P<id>[^/?#&]+)
                    '''

    _TEST = {
        'url': 'http://www.telezueri.ch/all-episodes/astrotalk',
        'info_dict': {
            'id': 'astrotalk',
            'title': 'TeleZüri: AstroTalk - alle episoden',
            'description': 'md5:4c0f7e7d741d906004266e295ceb4a26',
        },
        'playlist_mincount': 13,
    }

    def _real_extract(self, url):
        playlist_id = self._match_id(url)
        webpage = self._download_webpage(url, playlist_id)
        episodes = get_element_by_class('search-mobile-box', webpage)
        entries = [self.url_result(
            urljoin(url, m.group('url'))) for m in re.finditer(
                r'<a[^>]+href=(["\'])(?P<url>(?:(?!\1).)+)\1', episodes)]
        title = self._og_search_title(webpage, fatal=False)
        description = self._og_search_description(webpage)
        return self.playlist_result(entries, playlist_id, title, description)