]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/netzkino.py
Tidy the changelog.
[youtubedl] / youtube_dl / extractor / netzkino.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import (
8 clean_html,
9 int_or_none,
10 js_to_json,
11 parse_iso8601,
12 )
13
14
15 class NetzkinoIE(InfoExtractor):
16 _VALID_URL = r'https?://(?:www\.)?netzkino\.de/\#!/(?P<category>[^/]+)/(?P<id>[^/]+)'
17
18 _TEST = {
19 'url': 'http://www.netzkino.de/#!/scifikino/rakete-zum-mond',
20 'md5': '92a3f8b76f8d7220acce5377ea5d4873',
21 'info_dict': {
22 'id': 'rakete-zum-mond',
23 'ext': 'mp4',
24 'title': 'Rakete zum Mond (Endstation Mond, Destination Moon)',
25 'comments': 'mincount:3',
26 'description': 'md5:1eddeacc7e62d5a25a2d1a7290c64a28',
27 'upload_date': '20120813',
28 'thumbnail': 're:https?://.*\.jpg$',
29 'timestamp': 1344858571,
30 'age_limit': 12,
31 },
32 }
33
34 def _real_extract(self, url):
35 mobj = re.match(self._VALID_URL, url)
36 category_id = mobj.group('category')
37 video_id = mobj.group('id')
38
39 api_url = 'http://api.netzkino.de.simplecache.net/capi-2.0a/categories/%s.json?d=www' % category_id
40 api_info = self._download_json(api_url, video_id)
41 info = next(
42 p for p in api_info['posts'] if p['slug'] == video_id)
43 custom_fields = info['custom_fields']
44
45 production_js = self._download_webpage(
46 'http://www.netzkino.de/beta/dist/production.min.js', video_id,
47 note='Downloading player code')
48 avo_js = self._search_regex(
49 r'window\.avoCore\s*=.*?urlTemplate:\s*(\{.*?"\})',
50 production_js, 'URL templates')
51 templates = self._parse_json(
52 avo_js, video_id, transform_source=js_to_json)
53
54 suffix = {
55 'hds': '.mp4/manifest.f4m',
56 'hls': '.mp4/master.m3u8',
57 'pmd': '.mp4',
58 }
59 film_fn = custom_fields['Streaming'][0]
60 formats = [{
61 'format_id': key,
62 'ext': 'mp4',
63 'url': tpl.replace('{}', film_fn) + suffix[key],
64 } for key, tpl in templates.items()]
65 self._sort_formats(formats)
66
67 comments = [{
68 'timestamp': parse_iso8601(c.get('date'), delimiter=' '),
69 'id': c['id'],
70 'author': c['name'],
71 'html': c['content'],
72 'parent': 'root' if c.get('parent', 0) == 0 else c['parent'],
73 } for c in info.get('comments', [])]
74
75 return {
76 'id': video_id,
77 'formats': formats,
78 'comments': comments,
79 'title': info['title'],
80 'age_limit': int_or_none(custom_fields.get('FSK')[0]),
81 'timestamp': parse_iso8601(info.get('date'), delimiter=' '),
82 'description': clean_html(info.get('content')),
83 'thumbnail': info.get('thumbnail'),
84 'playlist_title': api_info.get('title'),
85 'playlist_id': category_id,
86 }