dplay.py 1.8 KB

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