massengeschmacktv.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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': 'a9e054db9c2b5a08f0a0527cc201e8d3',
  17. 'info_dict': {
  18. 'id': 'fktv202',
  19. 'ext': 'mp4',
  20. 'title': 'Fernsehkritik-TV - Folge 202',
  21. },
  22. }
  23. def _real_extract(self, url):
  24. episode = self._match_id(url)
  25. webpage = self._download_webpage(url, episode)
  26. title = clean_html(self._html_search_regex(
  27. '<h3>([^<]+)</h3>', webpage, 'title'))
  28. thumbnail = self._search_regex(r'POSTER\s*=\s*"([^"]+)', webpage, 'thumbnail', fatal=False)
  29. sources = self._parse_json(self._search_regex(r'(?s)MEDIA\s*=\s*(\[.+?\]);', webpage, 'media'), episode, js_to_json)
  30. formats = []
  31. for source in sources:
  32. furl = source.get('src')
  33. if not furl:
  34. continue
  35. furl = self._proto_relative_url(furl)
  36. ext = determine_ext(furl) or mimetype2ext(source.get('type'))
  37. if ext == 'm3u8':
  38. formats.extend(self._extract_m3u8_formats(
  39. furl, episode, 'mp4', 'm3u8_native',
  40. m3u8_id='hls', fatal=False))
  41. else:
  42. formats.append({
  43. 'url': furl,
  44. 'format_id': determine_ext(furl),
  45. })
  46. for (durl, format_id, width, height, filesize) in re.findall(r'''(?x)
  47. <a[^>]+?href="(?P<url>(?:https:)?//[^"]+)".*?
  48. <strong>(?P<format_id>.+?)</strong>.*?
  49. <small>(?:(?P<width>\d+)x(?P<height>\d+))?\s+?\((?P<filesize>[\d,]+\s*[GM]iB)\)</small>
  50. ''', webpage):
  51. formats.append({
  52. 'url': durl,
  53. 'format_id': format_id,
  54. 'width': int_or_none(width),
  55. 'height': int_or_none(height),
  56. 'filesize': parse_filesize(filesize),
  57. 'vcodec': 'none' if format_id.startswith('Audio') else None,
  58. })
  59. return {
  60. 'id': episode,
  61. 'title': title,
  62. 'formats': formats,
  63. 'thumbnail': thumbnail,
  64. }