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.

89 lines
3.0 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. 'params': {
  28. 'skip_download': 'Download only works from Germany',
  29. }
  30. }
  31. def _real_extract(self, url):
  32. mobj = re.match(self._VALID_URL, url)
  33. category_id = mobj.group('category')
  34. video_id = mobj.group('id')
  35. api_url = 'http://api.netzkino.de.simplecache.net/capi-2.0a/categories/%s.json?d=www' % category_id
  36. api_info = self._download_json(api_url, video_id)
  37. info = next(
  38. p for p in api_info['posts'] if p['slug'] == video_id)
  39. custom_fields = info['custom_fields']
  40. production_js = self._download_webpage(
  41. 'http://www.netzkino.de/beta/dist/production.min.js', video_id,
  42. note='Downloading player code')
  43. avo_js = self._search_regex(
  44. r'var urlTemplate=(\{.*?"\})',
  45. production_js, 'URL templates')
  46. templates = self._parse_json(
  47. avo_js, video_id, transform_source=js_to_json)
  48. suffix = {
  49. 'hds': '.mp4/manifest.f4m',
  50. 'hls': '.mp4/master.m3u8',
  51. 'pmd': '.mp4',
  52. }
  53. film_fn = custom_fields['Streaming'][0]
  54. formats = [{
  55. 'format_id': key,
  56. 'ext': 'mp4',
  57. 'url': tpl.replace('{}', film_fn) + suffix[key],
  58. } for key, tpl in templates.items()]
  59. self._sort_formats(formats)
  60. comments = [{
  61. 'timestamp': parse_iso8601(c.get('date'), delimiter=' '),
  62. 'id': c['id'],
  63. 'author': c['name'],
  64. 'html': c['content'],
  65. 'parent': 'root' if c.get('parent', 0) == 0 else c['parent'],
  66. } for c in info.get('comments', [])]
  67. return {
  68. 'id': video_id,
  69. 'formats': formats,
  70. 'comments': comments,
  71. 'title': info['title'],
  72. 'age_limit': int_or_none(custom_fields.get('FSK')[0]),
  73. 'timestamp': parse_iso8601(info.get('date'), delimiter=' '),
  74. 'description': clean_html(info.get('content')),
  75. 'thumbnail': info.get('thumbnail'),
  76. 'playlist_title': api_info.get('title'),
  77. 'playlist_id': category_id,
  78. }