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.

107 lines
3.6 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. float_or_none,
  6. int_or_none,
  7. )
  8. class KonserthusetPlayIE(InfoExtractor):
  9. _VALID_URL = r'https?://(?:www\.)?konserthusetplay\.se/\?.*\bm=(?P<id>[^&]+)'
  10. _TEST = {
  11. 'url': 'http://www.konserthusetplay.se/?m=CKDDnlCY-dhWAAqiMERd-A',
  12. 'info_dict': {
  13. 'id': 'CKDDnlCY-dhWAAqiMERd-A',
  14. 'ext': 'flv',
  15. 'title': 'Orkesterns instrument: Valthornen',
  16. 'description': 'md5:f10e1f0030202020396a4d712d2fa827',
  17. 'thumbnail': 're:^https?://.*$',
  18. 'duration': 398.8,
  19. },
  20. 'params': {
  21. # rtmp download
  22. 'skip_download': True,
  23. },
  24. }
  25. def _real_extract(self, url):
  26. video_id = self._match_id(url)
  27. webpage = self._download_webpage(url, video_id)
  28. e = self._search_regex(
  29. r'https?://csp\.picsearch\.com/rest\?.*\be=(.+?)[&"\']', webpage, 'e')
  30. rest = self._download_json(
  31. 'http://csp.picsearch.com/rest?e=%s&containerId=mediaplayer&i=object' % e,
  32. video_id, transform_source=lambda s: s[s.index('{'):s.rindex('}') + 1])
  33. media = rest['media']
  34. player_config = media['playerconfig']
  35. playlist = player_config['playlist']
  36. source = next(f for f in playlist if f.get('bitrates'))
  37. FORMAT_ID_REGEX = r'_([^_]+)_h264m\.mp4'
  38. formats = []
  39. fallback_url = source.get('fallbackUrl')
  40. fallback_format_id = None
  41. if fallback_url:
  42. fallback_format_id = self._search_regex(
  43. FORMAT_ID_REGEX, fallback_url, 'format id', default=None)
  44. connection_url = (player_config.get('rtmp', {}).get(
  45. 'netConnectionUrl') or player_config.get(
  46. 'plugins', {}).get('bwcheck', {}).get('netConnectionUrl'))
  47. if connection_url:
  48. for f in source['bitrates']:
  49. video_url = f.get('url')
  50. if not video_url:
  51. continue
  52. format_id = self._search_regex(
  53. FORMAT_ID_REGEX, video_url, 'format id', default=None)
  54. f_common = {
  55. 'vbr': int_or_none(f.get('bitrate')),
  56. 'width': int_or_none(f.get('width')),
  57. 'height': int_or_none(f.get('height')),
  58. }
  59. f = f_common.copy()
  60. f.update({
  61. 'url': connection_url,
  62. 'play_path': video_url,
  63. 'format_id': 'rtmp-%s' % format_id if format_id else 'rtmp',
  64. 'ext': 'flv',
  65. })
  66. formats.append(f)
  67. if format_id and format_id == fallback_format_id:
  68. f = f_common.copy()
  69. f.update({
  70. 'url': fallback_url,
  71. 'format_id': 'http-%s' % format_id if format_id else 'http',
  72. })
  73. formats.append(f)
  74. if not formats and fallback_url:
  75. formats.append({
  76. 'url': fallback_url,
  77. })
  78. self._sort_formats(formats)
  79. title = player_config.get('title') or media['title']
  80. description = player_config.get('mediaInfo', {}).get('description')
  81. thumbnail = media.get('image')
  82. duration = float_or_none(media.get('duration'), 1000)
  83. return {
  84. 'id': video_id,
  85. 'title': title,
  86. 'description': description,
  87. 'thumbnail': thumbnail,
  88. 'duration': duration,
  89. 'formats': formats,
  90. }