noz.py 3.4 KB

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