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.

71 lines
3.0 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import unified_timestamp
  5. class URPlayIE(InfoExtractor):
  6. _VALID_URL = r'https?://(?:www\.)?ur(?:play|skola)\.se/(?:program|Produkter)/(?P<id>[0-9]+)'
  7. _TESTS = [{
  8. 'url': 'https://urplay.se/program/203704-ur-samtiden-livet-universum-och-rymdens-markliga-musik-om-vetenskap-kritiskt-tankande-och-motstand',
  9. 'md5': 'ff5b0c89928f8083c74bbd5099c9292d',
  10. 'info_dict': {
  11. 'id': '203704',
  12. 'ext': 'mp4',
  13. 'title': 'UR Samtiden - Livet, universum och rymdens märkliga musik : Om vetenskap, kritiskt tänkande och motstånd',
  14. 'description': 'md5:5344508a52aa78c1ced6c1b8b9e44e9a',
  15. 'timestamp': 1513512768,
  16. 'upload_date': '20171217',
  17. },
  18. }, {
  19. 'url': 'https://urskola.se/Produkter/190031-Tripp-Trapp-Trad-Sovkudde',
  20. 'info_dict': {
  21. 'id': '190031',
  22. 'ext': 'mp4',
  23. 'title': 'Tripp, Trapp, Träd : Sovkudde',
  24. 'description': 'md5:b86bffdae04a7e9379d1d7e5947df1d1',
  25. 'timestamp': 1440093600,
  26. 'upload_date': '20150820',
  27. },
  28. }, {
  29. 'url': 'http://urskola.se/Produkter/155794-Smasagor-meankieli-Grodan-i-vida-varlden',
  30. 'only_matching': True,
  31. }]
  32. def _real_extract(self, url):
  33. video_id = self._match_id(url)
  34. webpage = self._download_webpage(url, video_id)
  35. urplayer_data = self._parse_json(self._search_regex(
  36. r'urPlayer\.init\(({.+?})\);', webpage, 'urplayer data'), video_id)
  37. host = self._download_json('http://streaming-loadbalancer.ur.se/loadbalancer.json', video_id)['redirect']
  38. formats = []
  39. for quality_attr, quality, preference in (('', 'sd', 0), ('_hd', 'hd', 1)):
  40. file_http = urplayer_data.get('file_http' + quality_attr) or urplayer_data.get('file_http_sub' + quality_attr)
  41. if file_http:
  42. formats.extend(self._extract_wowza_formats(
  43. 'http://%s/%splaylist.m3u8' % (host, file_http), video_id, skip_protocols=['rtmp', 'rtsp']))
  44. self._sort_formats(formats)
  45. subtitles = {}
  46. for subtitle in urplayer_data.get('subtitles', []):
  47. subtitle_url = subtitle.get('file')
  48. kind = subtitle.get('kind')
  49. if not subtitle_url or (kind and kind != 'captions'):
  50. continue
  51. subtitles.setdefault(subtitle.get('label', 'Svenska'), []).append({
  52. 'url': subtitle_url,
  53. })
  54. return {
  55. 'id': video_id,
  56. 'title': urplayer_data['title'],
  57. 'description': self._og_search_description(webpage),
  58. 'thumbnail': urplayer_data.get('image'),
  59. 'timestamp': unified_timestamp(self._html_search_meta(('uploadDate', 'schema:uploadDate'), webpage, 'timestamp')),
  60. 'series': urplayer_data.get('series_title'),
  61. 'subtitles': subtitles,
  62. 'formats': formats,
  63. }