massengeschmacktv.py 2.6 KB

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