You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.9 KiB

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