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
3.5 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..compat import compat_urllib_parse_unquote
  5. from ..utils import (
  6. int_or_none,
  7. find_xpath_attr,
  8. xpath_text,
  9. update_url_query,
  10. )
  11. class NozIE(InfoExtractor):
  12. _VALID_URL = r'https?://(?:www\.)?noz\.de/video/(?P<id>[0-9]+)/'
  13. _TESTS = [{
  14. 'url': 'http://www.noz.de/video/25151/32-Deutschland-gewinnt-Badminton-Lnderspiel-in-Melle',
  15. 'info_dict': {
  16. 'id': '25151',
  17. 'ext': 'mp4',
  18. 'duration': 215,
  19. 'title': '3:2 - Deutschland gewinnt Badminton-Länderspiel in Melle',
  20. 'description': 'Vor rund 370 Zuschauern gewinnt die deutsche Badminton-Nationalmannschaft am Donnerstag ein EM-Vorbereitungsspiel gegen Frankreich in Melle. Video Moritz Frankenberg.',
  21. 'thumbnail': 're:^http://.*\.jpg',
  22. },
  23. }]
  24. def _real_extract(self, url):
  25. video_id = self._match_id(url)
  26. webpage = self._download_webpage(url, video_id)
  27. description = self._og_search_description(webpage)
  28. edge_url = self._html_search_regex(
  29. r'<script\s+(?:type="text/javascript"\s+)?src="(.*?/videojs_.*?)"',
  30. webpage, 'edge URL')
  31. edge_content = self._download_webpage(edge_url, 'meta configuration')
  32. config_url_encoded = self._search_regex(
  33. r'so\.addVariable\("config_url","[^,]*,(.*?)"',
  34. edge_content, 'config URL'
  35. )
  36. config_url = compat_urllib_parse_unquote(config_url_encoded)
  37. doc = self._download_xml(config_url, 'video configuration')
  38. title = xpath_text(doc, './/title')
  39. thumbnail = xpath_text(doc, './/article/thumbnail/url')
  40. duration = int_or_none(xpath_text(
  41. doc, './/article/movie/file/duration'))
  42. formats = []
  43. for qnode in doc.findall('.//article/movie/file/qualities/qual'):
  44. http_url_ele = find_xpath_attr(
  45. qnode, './html_urls/video_url', 'format', 'video/mp4')
  46. http_url = http_url_ele.text if http_url_ele is not None else None
  47. if http_url:
  48. formats.append({
  49. 'url': http_url,
  50. 'format_name': xpath_text(qnode, './name'),
  51. 'format_id': '%s-%s' % ('http', xpath_text(qnode, './id')),
  52. 'height': int_or_none(xpath_text(qnode, './height')),
  53. 'width': int_or_none(xpath_text(qnode, './width')),
  54. 'tbr': int_or_none(xpath_text(qnode, './bitrate'), scale=1000),
  55. })
  56. else:
  57. f4m_url = xpath_text(qnode, 'url_hd2')
  58. if f4m_url:
  59. formats.extend(self._extract_f4m_formats(
  60. update_url_query(f4m_url, {'hdcore': '3.4.0'}),
  61. video_id, f4m_id='hds', fatal=False))
  62. m3u8_url_ele = find_xpath_attr(
  63. qnode, './html_urls/video_url',
  64. 'format', 'application/vnd.apple.mpegurl')
  65. m3u8_url = m3u8_url_ele.text if m3u8_url_ele is not None else None
  66. if m3u8_url:
  67. formats.extend(self._extract_m3u8_formats(
  68. m3u8_url, video_id, 'mp4', 'm3u8_native',
  69. m3u8_id='hls', fatal=False))
  70. self._sort_formats(formats)
  71. return {
  72. 'id': video_id,
  73. 'formats': formats,
  74. 'title': title,
  75. 'duration': duration,
  76. 'description': description,
  77. 'thumbnail': thumbnail,
  78. }