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