digg.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. from .common import InfoExtractor
  2. from ..utils import js_to_json
  3. class DiggIE(InfoExtractor):
  4. _VALID_URL = r'https?://(?:www\.)?digg\.com/video/(?P<id>[^/?#&]+)'
  5. _TESTS = [{
  6. # JWPlatform via provider
  7. 'url': 'http://digg.com/video/sci-fi-short-jonah-daniel-kaluuya-get-out',
  8. 'info_dict': {
  9. 'id': 'LcqvmS0b',
  10. 'ext': 'mp4',
  11. 'title': "'Get Out' Star Daniel Kaluuya Goes On 'Moby Dick'-Like Journey In Sci-Fi Short 'Jonah'",
  12. 'description': 'md5:541bb847648b6ee3d6514bc84b82efda',
  13. 'upload_date': '20180109',
  14. 'timestamp': 1515530551,
  15. },
  16. 'params': {
  17. 'skip_download': True,
  18. },
  19. }, {
  20. # Youtube via provider
  21. 'url': 'http://digg.com/video/dog-boat-seal-play',
  22. 'only_matching': True,
  23. }, {
  24. # vimeo as regular embed
  25. 'url': 'http://digg.com/video/dream-girl-short-film',
  26. 'only_matching': True,
  27. }]
  28. def _real_extract(self, url):
  29. display_id = self._match_id(url)
  30. webpage = self._download_webpage(url, display_id)
  31. info = self._parse_json(
  32. self._search_regex(
  33. r'(?s)video_info\s*=\s*({.+?});\n', webpage, 'video info',
  34. default='{}'), display_id, transform_source=js_to_json,
  35. fatal=False)
  36. video_id = info.get('video_id')
  37. if video_id:
  38. provider = info.get('provider_name')
  39. if provider == 'youtube':
  40. return self.url_result(
  41. video_id, ie='Youtube', video_id=video_id)
  42. elif provider == 'jwplayer':
  43. return self.url_result(
  44. 'jwplatform:%s' % video_id, ie='JWPlatform',
  45. video_id=video_id)
  46. return self.url_result(url, 'Generic')