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.

77 lines
2.1 KiB

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