]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/netzkino.py
[generic] Extract m3u8 formats from JSON-LD
[yt-dlp.git] / yt_dlp / extractor / netzkino.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4
5 from .common import InfoExtractor
6 from ..utils import (
7 clean_html,
8 int_or_none,
9 js_to_json,
10 parse_iso8601,
11 )
12
13
14 class NetzkinoIE(InfoExtractor):
15 _VALID_URL = r'https?://(?:www\.)?netzkino\.de/\#!/[^/]+/(?P<id>[^/]+)'
16
17 _TESTS = [{
18 'url': 'https://www.netzkino.de/#!/scifikino/rakete-zum-mond',
19 'md5': '92a3f8b76f8d7220acce5377ea5d4873',
20 'info_dict': {
21 'id': 'rakete-zum-mond',
22 'ext': 'mp4',
23 'title': 'Rakete zum Mond \u2013 Jules Verne',
24 'description': 'md5:f0a8024479618ddbfa450ff48ffa6c60',
25 'upload_date': '20120813',
26 'thumbnail': r're:https?://.*\.jpg$',
27 'timestamp': 1344858571,
28 'age_limit': 12,
29 },
30 'params': {
31 'skip_download': 'Download only works from Germany',
32 }
33 }, {
34 'url': 'https://www.netzkino.de/#!/filme/dr-jekyll-mrs-hyde-2',
35 'md5': 'c7728b2dadd04ff6727814847a51ef03',
36 'info_dict': {
37 'id': 'dr-jekyll-mrs-hyde-2',
38 'ext': 'mp4',
39 'title': 'Dr. Jekyll & Mrs. Hyde 2',
40 'description': 'md5:c2e9626ebd02de0a794b95407045d186',
41 'upload_date': '20190130',
42 'thumbnail': r're:https?://.*\.jpg$',
43 'timestamp': 1548849437,
44 'age_limit': 18,
45 },
46 'params': {
47 'skip_download': 'Download only works from Germany',
48 }
49 }]
50
51 def _real_extract(self, url):
52 mobj = self._match_valid_url(url)
53 video_id = mobj.group('id')
54
55 api_url = 'https://api.netzkino.de.simplecache.net/capi-2.0a/movies/%s.json?d=www' % video_id
56 info = self._download_json(api_url, video_id)
57 custom_fields = info['custom_fields']
58
59 production_js = self._download_webpage(
60 'http://www.netzkino.de/beta/dist/production.min.js', video_id,
61 note='Downloading player code')
62 avo_js = self._search_regex(
63 r'var urlTemplate=(\{.*?"\})',
64 production_js, 'URL templates')
65 templates = self._parse_json(
66 avo_js, video_id, transform_source=js_to_json)
67
68 suffix = {
69 'hds': '.mp4/manifest.f4m',
70 'hls': '.mp4/master.m3u8',
71 'pmd': '.mp4',
72 }
73 film_fn = custom_fields['Streaming'][0]
74 formats = [{
75 'format_id': key,
76 'ext': 'mp4',
77 'url': tpl.replace('{}', film_fn) + suffix[key],
78 } for key, tpl in templates.items()]
79 self._sort_formats(formats)
80
81 return {
82 'id': video_id,
83 'formats': formats,
84 'title': info['title'],
85 'age_limit': int_or_none(custom_fields.get('FSK')[0]),
86 'timestamp': parse_iso8601(info.get('date'), delimiter=' '),
87 'description': clean_html(info.get('content')),
88 'thumbnail': info.get('thumbnail'),
89 }