muenchentv.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import json
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. determine_ext,
  5. int_or_none,
  6. js_to_json,
  7. )
  8. class MuenchenTVIE(InfoExtractor):
  9. _WORKING = False
  10. _VALID_URL = r'https?://(?:www\.)?muenchen\.tv/livestream'
  11. IE_DESC = 'münchen.tv'
  12. _TEST = {
  13. 'url': 'http://www.muenchen.tv/livestream/',
  14. 'info_dict': {
  15. 'id': '5334',
  16. 'display_id': 'live',
  17. 'ext': 'mp4',
  18. 'title': 're:^münchen.tv-Livestream [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
  19. 'is_live': True,
  20. 'thumbnail': r're:^https?://.*\.jpg$',
  21. },
  22. 'params': {
  23. 'skip_download': True,
  24. },
  25. }
  26. def _real_extract(self, url):
  27. display_id = 'live'
  28. webpage = self._download_webpage(url, display_id)
  29. title = self._og_search_title(webpage)
  30. data_js = self._search_regex(
  31. r'(?s)\nplaylist:\s*(\[.*?}\]),',
  32. webpage, 'playlist configuration')
  33. data_json = js_to_json(data_js)
  34. data = json.loads(data_json)[0]
  35. video_id = data['mediaid']
  36. thumbnail = data.get('image')
  37. formats = []
  38. for format_num, s in enumerate(data['sources']):
  39. ext = determine_ext(s['file'], None)
  40. label_str = s.get('label')
  41. if label_str is None:
  42. label_str = f'_{format_num}'
  43. if ext is None:
  44. format_id = label_str
  45. else:
  46. format_id = f'{ext}-{label_str}'
  47. formats.append({
  48. 'url': s['file'],
  49. 'tbr': int_or_none(s.get('label')),
  50. 'ext': 'mp4',
  51. 'format_id': format_id,
  52. 'preference': -100 if '.smil' in s['file'] else 0, # Strictly inferior than all other formats?
  53. })
  54. return {
  55. 'id': video_id,
  56. 'display_id': display_id,
  57. 'title': title,
  58. 'formats': formats,
  59. 'is_live': True,
  60. 'thumbnail': thumbnail,
  61. }