noz.py 3.4 KB

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