]>
Commit | Line | Data |
---|---|---|
e9ea0bf1 S |
1 | # encoding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
4 | import re | |
5 | ||
6 | from .common import InfoExtractor | |
c1ed1f70 S |
7 | from ..utils import ( |
8 | ExtractorError, | |
9 | int_or_none, | |
77541837 | 10 | qualities, |
1934f3a0 | 11 | parse_duration, |
c1ed1f70 | 12 | ) |
e9ea0bf1 S |
13 | |
14 | ||
1934f3a0 | 15 | class NDRBaseIE(InfoExtractor): |
e9ea0bf1 S |
16 | def _real_extract(self, url): |
17 | mobj = re.match(self._VALID_URL, url) | |
18 | video_id = mobj.group('id') | |
19 | ||
20 | page = self._download_webpage(url, video_id, 'Downloading page') | |
21 | ||
c1ed1f70 | 22 | title = self._og_search_title(page).strip() |
e9ea0bf1 | 23 | description = self._og_search_description(page) |
c1ed1f70 S |
24 | if description: |
25 | description = description.strip() | |
e9ea0bf1 | 26 | |
1934f3a0 YCH |
27 | duration = int_or_none(self._html_search_regex(r'duration: (\d+),\n', page, 'duration', default=None)) |
28 | if not duration: | |
29 | duration = parse_duration(self._html_search_regex( | |
30 | r'(<span class="min">\d+</span>:<span class="sec">\d+</span>)', | |
31 | page, 'duration', default=None)) | |
e9ea0bf1 S |
32 | |
33 | formats = [] | |
34 | ||
77541837 | 35 | mp3_url = re.search(r'''\{src:'(?P<audio>[^']+)', type:"audio/mp3"},''', page) |
e9ea0bf1 S |
36 | if mp3_url: |
37 | formats.append({ | |
38 | 'url': mp3_url.group('audio'), | |
39 | 'format_id': 'mp3', | |
40 | }) | |
41 | ||
42 | thumbnail = None | |
43 | ||
a6dae6c0 | 44 | video_url = re.search(r'''3: \{src:'(?P<video>.+?)\.(lo|hi|hq)\.mp4', type:"video/mp4"},''', page) |
e9ea0bf1 | 45 | if video_url: |
77541837 | 46 | thumbnails = re.findall(r'''\d+: \{src: "([^"]+)"(?: \|\| '[^']+')?, quality: '([^']+)'}''', page) |
1514f749 | 47 | if thumbnails: |
77541837 | 48 | quality_key = qualities(['xs', 's', 'm', 'l', 'xl']) |
49 | largest = max(thumbnails, key=lambda thumb: quality_key(thumb[1])) | |
50 | thumbnail = 'http://www.ndr.de' + largest[0] | |
1514f749 | 51 | |
77541837 | 52 | for format_id in 'lo', 'hi', 'hq': |
e9ea0bf1 S |
53 | formats.append({ |
54 | 'url': '%s.%s.mp4' % (video_url.group('video'), format_id), | |
55 | 'format_id': format_id, | |
56 | }) | |
57 | ||
58 | if not formats: | |
59 | raise ExtractorError('No media links available for %s' % video_id) | |
60 | ||
61 | return { | |
62 | 'id': video_id, | |
63 | 'title': title, | |
64 | 'description': description, | |
65 | 'thumbnail': thumbnail, | |
66 | 'duration': duration, | |
67 | 'formats': formats, | |
5f6a1245 | 68 | } |
1934f3a0 YCH |
69 | |
70 | ||
71 | class NDRIE(NDRBaseIE): | |
72 | IE_NAME = 'ndr' | |
73 | IE_DESC = 'NDR.de - Mediathek' | |
74 | _VALID_URL = r'https?://www\.ndr\.de/.+?(?P<id>\d+)\.html' | |
75 | ||
76 | _TESTS = [ | |
77 | { | |
78 | 'url': 'http://www.ndr.de/fernsehen/sendungen/nordmagazin/Kartoffeltage-in-der-Lewitz,nordmagazin25866.html', | |
79 | 'md5': '5bc5f5b92c82c0f8b26cddca34f8bb2c', | |
80 | 'note': 'Video file', | |
81 | 'info_dict': { | |
82 | 'id': '25866', | |
83 | 'ext': 'mp4', | |
84 | 'title': 'Kartoffeltage in der Lewitz', | |
85 | 'description': 'md5:48c4c04dde604c8a9971b3d4e3b9eaa8', | |
86 | 'duration': 166, | |
63cbd19f YCH |
87 | }, |
88 | 'skip': '404 Not found', | |
89 | }, | |
90 | { | |
91 | 'url': 'http://www.ndr.de/fernsehen/Party-Poette-und-Parade,hafengeburtstag988.html', | |
92 | 'md5': 'dadc003c55ae12a5d2f6bd436cd73f59', | |
93 | 'info_dict': { | |
94 | 'id': '988', | |
95 | 'ext': 'mp4', | |
96 | 'title': 'Party, Pötte und Parade', | |
97 | 'description': 'Hunderttausende feiern zwischen Speicherstadt und St. Pauli den 826. Hafengeburtstag. Die NDR Sondersendung zeigt die schönsten und spektakulärsten Bilder vom Auftakt.', | |
98 | 'duration': 3498, | |
99 | }, | |
1934f3a0 YCH |
100 | }, |
101 | { | |
102 | 'url': 'http://www.ndr.de/info/audio51535.html', | |
103 | 'md5': 'bb3cd38e24fbcc866d13b50ca59307b8', | |
104 | 'note': 'Audio file', | |
105 | 'info_dict': { | |
106 | 'id': '51535', | |
107 | 'ext': 'mp3', | |
108 | 'title': 'La Valette entgeht der Hinrichtung', | |
109 | 'description': 'md5:22f9541913a40fe50091d5cdd7c9f536', | |
110 | 'duration': 884, | |
111 | } | |
112 | } | |
113 | ] | |
114 | ||
115 | ||
116 | class NJoyIE(NDRBaseIE): | |
117 | IE_NAME = 'N-JOY' | |
118 | _VALID_URL = r'https?://www\.n-joy\.de/.+?(?P<id>\d+)\.html' | |
119 | ||
120 | _TEST = { | |
121 | 'url': 'http://www.n-joy.de/entertainment/comedy/comedy_contest/Benaissa-beim-NDR-Comedy-Contest,comedycontest2480.html', | |
122 | 'md5': 'cb63be60cd6f9dd75218803146d8dc67', | |
123 | 'info_dict': { | |
124 | 'id': '2480', | |
125 | 'ext': 'mp4', | |
126 | 'title': 'Benaissa beim NDR Comedy Contest', | |
127 | 'description': 'Von seinem sehr "behaarten" Leben lässt sich Benaissa trotz aller Schwierigkeiten nicht unterkriegen.', | |
128 | 'duration': 654, | |
129 | } | |
130 | } |