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.

63 lines
2.1 KiB

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