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