logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

massengeschmacktv.py (2688B)


  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. clean_html,
  6. determine_ext,
  7. int_or_none,
  8. js_to_json,
  9. mimetype2ext,
  10. parse_filesize,
  11. )
  12. class MassengeschmackTVIE(InfoExtractor):
  13. IE_NAME = 'massengeschmack.tv'
  14. _VALID_URL = r'https?://(?:www\.)?massengeschmack\.tv/play/(?P<id>[^?&#]+)'
  15. _TEST = {
  16. 'url': 'https://massengeschmack.tv/play/fktv202',
  17. 'md5': 'a9e054db9c2b5a08f0a0527cc201e8d3',
  18. 'info_dict': {
  19. 'id': 'fktv202',
  20. 'ext': 'mp4',
  21. 'title': 'Fernsehkritik-TV - Folge 202',
  22. },
  23. }
  24. def _real_extract(self, url):
  25. episode = self._match_id(url)
  26. webpage = self._download_webpage(url, episode)
  27. title = clean_html(self._html_search_regex(
  28. '<h3>([^<]+)</h3>', webpage, 'title'))
  29. thumbnail = self._search_regex(r'POSTER\s*=\s*"([^"]+)', webpage, 'thumbnail', fatal=False)
  30. sources = self._parse_json(self._search_regex(r'(?s)MEDIA\s*=\s*(\[.+?\]);', webpage, 'media'), episode, js_to_json)
  31. formats = []
  32. for source in sources:
  33. furl = source.get('src')
  34. if not furl:
  35. continue
  36. furl = self._proto_relative_url(furl)
  37. ext = determine_ext(furl) or mimetype2ext(source.get('type'))
  38. if ext == 'm3u8':
  39. formats.extend(self._extract_m3u8_formats(
  40. furl, episode, 'mp4', 'm3u8_native',
  41. m3u8_id='hls', fatal=False))
  42. else:
  43. formats.append({
  44. 'url': furl,
  45. 'format_id': determine_ext(furl),
  46. })
  47. for (durl, format_id, width, height, filesize) in re.findall(r'''(?x)
  48. <a[^>]+?href="(?P<url>(?:https:)?//[^"]+)".*?
  49. <strong>(?P<format_id>.+?)</strong>.*?
  50. <small>(?:(?P<width>\d+)x(?P<height>\d+))?\s+?\((?P<filesize>[\d,]+\s*[GM]iB)\)</small>
  51. ''', webpage):
  52. formats.append({
  53. 'url': durl,
  54. 'format_id': format_id,
  55. 'width': int_or_none(width),
  56. 'height': int_or_none(height),
  57. 'filesize': parse_filesize(filesize),
  58. 'vcodec': 'none' if format_id.startswith('Audio') else None,
  59. })
  60. self._sort_formats(formats, ('width', 'height', 'filesize', 'tbr'))
  61. return {
  62. 'id': episode,
  63. 'title': title,
  64. 'formats': formats,
  65. 'thumbnail': thumbnail,
  66. }