You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.1 KiB

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