heise.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. get_meta_content,
  6. parse_iso8601,
  7. )
  8. class HeiseIE(InfoExtractor):
  9. _VALID_URL = r'''(?x)
  10. https?://(?:www\.)?heise\.de/video/artikel/
  11. .+?(?P<id>[0-9]+)\.html(?:$|[?#])
  12. '''
  13. _TEST = {
  14. 'url': (
  15. 'http://www.heise.de/video/artikel/Podcast-c-t-uplink-3-3-Owncloud-Tastaturen-Peilsender-Smartphone-2404147.html'
  16. ),
  17. 'md5': 'ffed432483e922e88545ad9f2f15d30e',
  18. 'info_dict': {
  19. 'id': '2404147',
  20. 'ext': 'mp4',
  21. 'title': (
  22. "Podcast: c't uplink 3.3 – Owncloud / Tastaturen / Peilsender Smartphone"
  23. ),
  24. 'format_id': 'mp4_720',
  25. 'timestamp': 1411812600,
  26. 'upload_date': '20140927',
  27. }
  28. }
  29. def _real_extract(self, url):
  30. video_id = self._match_id(url)
  31. webpage = self._download_webpage(url, video_id)
  32. json_url = self._search_regex(
  33. r'json_url:\s*"([^"]+)"', webpage, 'json URL')
  34. config = self._download_json(json_url, video_id)
  35. info = {
  36. 'id': video_id,
  37. 'thumbnail': config.get('poster'),
  38. 'timestamp': parse_iso8601(get_meta_content('date', webpage)),
  39. }
  40. title = get_meta_content('fulltitle', webpage)
  41. if title:
  42. info['title'] = title
  43. elif config.get('title'):
  44. info['title'] = config['title']
  45. else:
  46. info['title'] = self._og_search_title(webpage)
  47. formats = []
  48. for t, rs in config['formats'].items():
  49. if not rs or not hasattr(rs, 'items'):
  50. self._downloader.report_warning(
  51. 'formats: {0}: no resolutions'.format(t))
  52. continue
  53. for height_str, obj in rs.items():
  54. format_id = '{0}_{1}'.format(t, height_str)
  55. if not obj or not obj.get('url'):
  56. self._downloader.report_warning(
  57. 'formats: {0}: no url'.format(format_id))
  58. continue
  59. formats.append({
  60. 'url': obj['url'],
  61. 'format_id': format_id,
  62. 'height': self._int(height_str, 'height'),
  63. })
  64. self._sort_formats(formats)
  65. info['formats'] = formats
  66. return info