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.6 KiB

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