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.

57 lines
2.3 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\.)?ur(?:play|skola)\.se/(?:program|Produkter)/(?P<id>[0-9]+)'
  6. _TESTS = [{
  7. 'url': 'http://urplay.se/program/190031-tripp-trapp-trad-sovkudde',
  8. 'md5': 'ad5f0de86f16ca4c8062cd103959a9eb',
  9. 'info_dict': {
  10. 'id': '190031',
  11. 'ext': 'mp4',
  12. 'title': 'Tripp, Trapp, Träd : Sovkudde',
  13. 'description': 'md5:b86bffdae04a7e9379d1d7e5947df1d1',
  14. },
  15. }, {
  16. 'url': 'http://urskola.se/Produkter/155794-Smasagor-meankieli-Grodan-i-vida-varlden',
  17. 'only_matching': True,
  18. }]
  19. def _real_extract(self, url):
  20. video_id = self._match_id(url)
  21. webpage = self._download_webpage(url, video_id)
  22. urplayer_data = self._parse_json(self._search_regex(
  23. r'urPlayer\.init\(({.+?})\);', webpage, 'urplayer data'), video_id)
  24. host = self._download_json('http://streaming-loadbalancer.ur.se/loadbalancer.json', video_id)['redirect']
  25. formats = []
  26. for quality_attr, quality, preference in (('', 'sd', 0), ('_hd', 'hd', 1)):
  27. file_http = urplayer_data.get('file_http' + quality_attr) or urplayer_data.get('file_http_sub' + quality_attr)
  28. if file_http:
  29. formats.extend(self._extract_wowza_formats(
  30. 'http://%s/%splaylist.m3u8' % (host, file_http), video_id, skip_protocols=['rtmp', 'rtsp']))
  31. self._sort_formats(formats)
  32. subtitles = {}
  33. for subtitle in urplayer_data.get('subtitles', []):
  34. subtitle_url = subtitle.get('file')
  35. kind = subtitle.get('kind')
  36. if not subtitle_url or (kind and kind != 'captions'):
  37. continue
  38. subtitles.setdefault(subtitle.get('label', 'Svenska'), []).append({
  39. 'url': subtitle_url,
  40. })
  41. return {
  42. 'id': video_id,
  43. 'title': urplayer_data['title'],
  44. 'description': self._og_search_description(webpage),
  45. 'thumbnail': urplayer_data.get('image'),
  46. 'series': urplayer_data.get('series_title'),
  47. 'subtitles': subtitles,
  48. 'formats': formats,
  49. }