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.

67 lines
2.7 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. class URPlayIE(InfoExtractor):
  5. _VALID_URL = r'https?://(?:www\.)?urplay\.se/program/(?P<id>[0-9]+)'
  6. _TEST = {
  7. 'url': 'http://urplay.se/program/190031-tripp-trapp-trad-sovkudde',
  8. 'md5': '15ca67b63fd8fb320ac2bcd854bad7b6',
  9. 'info_dict': {
  10. 'id': '190031',
  11. 'ext': 'mp4',
  12. 'title': 'Tripp, Trapp, Träd : Sovkudde',
  13. 'description': 'md5:b86bffdae04a7e9379d1d7e5947df1d1',
  14. }
  15. }
  16. def _real_extract(self, url):
  17. video_id = self._match_id(url)
  18. webpage = self._download_webpage(url, video_id)
  19. urplayer_data = self._parse_json(self._search_regex(
  20. r'urPlayer\.init\(({.+?})\);', webpage, 'urplayer data'), video_id)
  21. host = self._download_json('http://streaming-loadbalancer.ur.se/loadbalancer.json', video_id)['redirect']
  22. formats = []
  23. for quality_attr, quality, preference in (('', 'sd', 0), ('_hd', 'hd', 1)):
  24. file_rtmp = urplayer_data.get('file_rtmp' + quality_attr)
  25. if file_rtmp:
  26. formats.append({
  27. 'url': 'rtmp://%s/urplay/mp4:%s' % (host, file_rtmp),
  28. 'format_id': quality + '-rtmp',
  29. 'ext': 'flv',
  30. 'preference': preference,
  31. })
  32. file_http = urplayer_data.get('file_http' + quality_attr) or urplayer_data.get('file_http_sub' + quality_attr)
  33. if file_http:
  34. file_http_base_url = 'http://%s/%s' % (host, file_http)
  35. formats.extend(self._extract_f4m_formats(
  36. file_http_base_url + 'manifest.f4m', video_id,
  37. preference, '%s-hds' % quality, fatal=False))
  38. formats.extend(self._extract_m3u8_formats(
  39. file_http_base_url + 'playlist.m3u8', video_id, 'mp4',
  40. 'm3u8_native', preference, '%s-hls' % quality, fatal=False))
  41. self._sort_formats(formats)
  42. subtitles = {}
  43. for subtitle in urplayer_data.get('subtitles', []):
  44. subtitle_url = subtitle.get('file')
  45. kind = subtitle.get('kind')
  46. if subtitle_url or kind and kind != 'captions':
  47. continue
  48. subtitles.setdefault(subtitle.get('label', 'Svenska'), []).append({
  49. 'url': subtitle_url,
  50. })
  51. return {
  52. 'id': video_id,
  53. 'title': urplayer_data['title'],
  54. 'description': self._og_search_description(webpage),
  55. 'thumbnail': urplayer_data.get('image'),
  56. 'series': urplayer_data.get('series_title'),
  57. 'subtitles': subtitles,
  58. 'formats': formats,
  59. }