c209eb04f35cb48070122b9bf91d57d44a8bafd6
[ytdl] / youtube_dl / extractor / tele5.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from .jwplatform import JWPlatformIE
8 from .nexx import NexxIE
9 from ..compat import compat_urlparse
10 from ..utils import NO_DEFAULT
11
12
13 class Tele5IE(InfoExtractor):
14     _VALID_URL = r'https?://(?:www\.)?tele5\.de/(?:[^/]+/)*(?P<id>[^/?#&]+)'
15     _TESTS = [{
16         'url': 'https://www.tele5.de/mediathek/filme-online/videos?vid=1549416',
17         'info_dict': {
18             'id': '1549416',
19             'ext': 'mp4',
20             'upload_date': '20180814',
21             'timestamp': 1534290623,
22             'title': 'Pandorum',
23         },
24         'params': {
25             'skip_download': True,
26         },
27     }, {
28         # jwplatform, nexx unavailable
29         'url': 'https://www.tele5.de/filme/ghoul-das-geheimnis-des-friedhofmonsters/',
30         'info_dict': {
31             'id': 'WJuiOlUp',
32             'ext': 'mp4',
33             'upload_date': '20200603',
34             'timestamp': 1591214400,
35             'title': 'Ghoul - Das Geheimnis des Friedhofmonsters',
36             'description': 'md5:42002af1d887ff3d5b2b3ca1f8137d97',
37         },
38         'params': {
39             'skip_download': True,
40         },
41         'add_ie': [JWPlatformIE.ie_key()],
42     }, {
43         'url': 'https://www.tele5.de/kalkofes-mattscheibe/video-clips/politik-und-gesellschaft?ve_id=1551191',
44         'only_matching': True,
45     }, {
46         'url': 'https://www.tele5.de/video-clip/?ve_id=1609440',
47         'only_matching': True,
48     }, {
49         'url': 'https://www.tele5.de/filme/schlefaz-dragon-crusaders/',
50         'only_matching': True,
51     }, {
52         'url': 'https://www.tele5.de/filme/making-of/avengers-endgame/',
53         'only_matching': True,
54     }, {
55         'url': 'https://www.tele5.de/star-trek/raumschiff-voyager/ganze-folge/das-vinculum/',
56         'only_matching': True,
57     }, {
58         'url': 'https://www.tele5.de/anders-ist-sevda/',
59         'only_matching': True,
60     }]
61
62     def _real_extract(self, url):
63         qs = compat_urlparse.parse_qs(compat_urlparse.urlparse(url).query)
64         video_id = (qs.get('vid') or qs.get('ve_id') or [None])[0]
65
66         NEXX_ID_RE = r'\d{6,}'
67         JWPLATFORM_ID_RE = r'[a-zA-Z0-9]{8}'
68
69         def nexx_result(nexx_id):
70             return self.url_result(
71                 'https://api.nexx.cloud/v3/759/videos/byid/%s' % nexx_id,
72                 ie=NexxIE.ie_key(), video_id=nexx_id)
73
74         nexx_id = jwplatform_id = None
75
76         if video_id:
77             if re.match(NEXX_ID_RE, video_id):
78                 return nexx_result(video_id)
79             elif re.match(JWPLATFORM_ID_RE, video_id):
80                 jwplatform_id = video_id
81
82         if not nexx_id:
83             display_id = self._match_id(url)
84             webpage = self._download_webpage(url, display_id)
85
86             def extract_id(pattern, name, default=NO_DEFAULT):
87                 return self._html_search_regex(
88                     (r'id\s*=\s*["\']video-player["\'][^>]+data-id\s*=\s*["\'](%s)' % pattern,
89                      r'\s+id\s*=\s*["\']player_(%s)' % pattern,
90                      r'\bdata-id\s*=\s*["\'](%s)' % pattern), webpage, name,
91                     default=default)
92
93             nexx_id = extract_id(NEXX_ID_RE, 'nexx id', default=None)
94             if nexx_id:
95                 return nexx_result(nexx_id)
96
97             if not jwplatform_id:
98                 jwplatform_id = extract_id(JWPLATFORM_ID_RE, 'jwplatform id')
99
100         return self.url_result(
101             'jwplatform:%s' % jwplatform_id, ie=JWPlatformIE.ie_key(),
102             video_id=jwplatform_id)