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.

51 lines
1.8 KiB

  1. # encoding: utf-8
  2. from __future__ import unicode_literals
  3. import time
  4. from .common import InfoExtractor
  5. from ..utils import int_or_none
  6. class DPlayIE(InfoExtractor):
  7. _VALID_URL = r'http://www\.dplay\.se/[^/]+/(?P<id>[^/?#]+)'
  8. _TEST = {
  9. 'url': 'http://www.dplay.se/nugammalt-77-handelser-som-format-sverige/season-1-svensken-lar-sig-njuta-av-livet/',
  10. 'info_dict': {
  11. 'id': '3172',
  12. 'ext': 'mp4',
  13. 'display_id': 'season-1-svensken-lar-sig-njuta-av-livet',
  14. 'title': 'Svensken lär sig njuta av livet',
  15. 'duration': 2650,
  16. },
  17. }
  18. def _real_extract(self, url):
  19. display_id = self._match_id(url)
  20. webpage = self._download_webpage(url, display_id)
  21. video_id = self._search_regex(
  22. r'data-video-id="(\d+)"', webpage, 'video id')
  23. info = self._download_json(
  24. 'http://www.dplay.se/api/v2/ajax/videos?video_id=' + video_id,
  25. video_id)['data'][0]
  26. self._set_cookie(
  27. 'secure.dplay.se', 'dsc-geo',
  28. '{"countryCode":"NL","expiry":%d}' % ((time.time() + 20 * 60) * 1000))
  29. # TODO: consider adding support for 'stream_type=hds', it seems to
  30. # require setting some cookies
  31. manifest_url = self._download_json(
  32. 'https://secure.dplay.se/secure/api/v2/user/authorization/stream/%s?stream_type=hls' % video_id,
  33. video_id, 'Getting manifest url for hls stream')['hls']
  34. formats = self._extract_m3u8_formats(
  35. manifest_url, video_id, ext='mp4', entry_protocol='m3u8_native')
  36. return {
  37. 'id': video_id,
  38. 'display_id': display_id,
  39. 'title': info['title'],
  40. 'formats': formats,
  41. 'duration': int_or_none(info.get('video_metadata_length'), scale=1000),
  42. }