logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

discoveryvr.py (2129B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import parse_duration
  5. class DiscoveryVRIE(InfoExtractor):
  6. _VALID_URL = r'https?://(?:www\.)?discoveryvr\.com/watch/(?P<id>[^/?#]+)'
  7. _TEST = {
  8. 'url': 'http://www.discoveryvr.com/watch/discovery-vr-an-introduction',
  9. 'md5': '32b1929798c464a54356378b7912eca4',
  10. 'info_dict': {
  11. 'id': 'discovery-vr-an-introduction',
  12. 'ext': 'mp4',
  13. 'title': 'Discovery VR - An Introduction',
  14. 'description': 'md5:80d418a10efb8899d9403e61d8790f06',
  15. }
  16. }
  17. def _real_extract(self, url):
  18. display_id = self._match_id(url)
  19. webpage = self._download_webpage(url, display_id)
  20. bootstrap_data = self._search_regex(
  21. r'root\.DVR\.bootstrapData\s+=\s+"({.+?})";',
  22. webpage, 'bootstrap data')
  23. bootstrap_data = self._parse_json(
  24. bootstrap_data.encode('utf-8').decode('unicode_escape'),
  25. display_id)
  26. videos = self._parse_json(bootstrap_data['videos'], display_id)['allVideos']
  27. video_data = next(video for video in videos if video.get('slug') == display_id)
  28. series = video_data.get('showTitle')
  29. title = episode = video_data.get('title') or series
  30. if series and series != title:
  31. title = '%s - %s' % (series, title)
  32. formats = []
  33. for f, format_id in (('cdnUriM3U8', 'mobi'), ('webVideoUrlSd', 'sd'), ('webVideoUrlHd', 'hd')):
  34. f_url = video_data.get(f)
  35. if not f_url:
  36. continue
  37. formats.append({
  38. 'format_id': format_id,
  39. 'url': f_url,
  40. })
  41. return {
  42. 'id': display_id,
  43. 'display_id': display_id,
  44. 'title': title,
  45. 'description': video_data.get('description'),
  46. 'thumbnail': video_data.get('thumbnail'),
  47. 'duration': parse_duration(video_data.get('runTime')),
  48. 'formats': formats,
  49. 'episode': episode,
  50. 'series': series,
  51. }