logo

youtube-dl

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

cultureunplugged.py (2508B)


  1. from __future__ import unicode_literals
  2. import re
  3. import time
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. int_or_none,
  7. HEADRequest,
  8. )
  9. class CultureUnpluggedIE(InfoExtractor):
  10. _VALID_URL = r'https?://(?:www\.)?cultureunplugged\.com/documentary/watch-online/play/(?P<id>\d+)(?:/(?P<display_id>[^/]+))?'
  11. _TESTS = [{
  12. 'url': 'http://www.cultureunplugged.com/documentary/watch-online/play/53662/The-Next--Best-West',
  13. 'md5': 'ac6c093b089f7d05e79934dcb3d228fc',
  14. 'info_dict': {
  15. 'id': '53662',
  16. 'display_id': 'The-Next--Best-West',
  17. 'ext': 'mp4',
  18. 'title': 'The Next, Best West',
  19. 'description': 'md5:0423cd00833dea1519cf014e9d0903b1',
  20. 'thumbnail': r're:^https?://.*\.jpg$',
  21. 'creator': 'Coldstream Creative',
  22. 'duration': 2203,
  23. 'view_count': int,
  24. }
  25. }, {
  26. 'url': 'http://www.cultureunplugged.com/documentary/watch-online/play/53662',
  27. 'only_matching': True,
  28. }]
  29. def _real_extract(self, url):
  30. mobj = re.match(self._VALID_URL, url)
  31. video_id = mobj.group('id')
  32. display_id = mobj.group('display_id') or video_id
  33. # request setClientTimezone.php to get PHPSESSID cookie which is need to get valid json data in the next request
  34. self._request_webpage(HEADRequest(
  35. 'http://www.cultureunplugged.com/setClientTimezone.php?timeOffset=%d' % -(time.timezone / 3600)), display_id)
  36. movie_data = self._download_json(
  37. 'http://www.cultureunplugged.com/movie-data/cu-%s.json' % video_id, display_id)
  38. video_url = movie_data['url']
  39. title = movie_data['title']
  40. description = movie_data.get('synopsis')
  41. creator = movie_data.get('producer')
  42. duration = int_or_none(movie_data.get('duration'))
  43. view_count = int_or_none(movie_data.get('views'))
  44. thumbnails = [{
  45. 'url': movie_data['%s_thumb' % size],
  46. 'id': size,
  47. 'preference': preference,
  48. } for preference, size in enumerate((
  49. 'small', 'large')) if movie_data.get('%s_thumb' % size)]
  50. return {
  51. 'id': video_id,
  52. 'display_id': display_id,
  53. 'url': video_url,
  54. 'title': title,
  55. 'description': description,
  56. 'creator': creator,
  57. 'duration': duration,
  58. 'view_count': view_count,
  59. 'thumbnails': thumbnails,
  60. }