voicerepublic.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. from .common import InfoExtractor
  2. from ..compat import compat_str
  3. from ..utils import (
  4. ExtractorError,
  5. determine_ext,
  6. int_or_none,
  7. urljoin,
  8. )
  9. class VoiceRepublicIE(InfoExtractor):
  10. _VALID_URL = r'https?://voicerepublic\.com/(?:talks|embed)/(?P<id>[0-9a-z-]+)'
  11. _TESTS = [{
  12. 'url': 'http://voicerepublic.com/talks/watching-the-watchers-building-a-sousveillance-state',
  13. 'md5': 'b9174d651323f17783000876347116e3',
  14. 'info_dict': {
  15. 'id': '2296',
  16. 'display_id': 'watching-the-watchers-building-a-sousveillance-state',
  17. 'ext': 'm4a',
  18. 'title': 'Watching the Watchers: Building a Sousveillance State',
  19. 'description': 'Secret surveillance programs have metadata too. The people and companies that operate secret surveillance programs can be surveilled.',
  20. 'duration': 1556,
  21. 'view_count': int,
  22. }
  23. }, {
  24. 'url': 'http://voicerepublic.com/embed/watching-the-watchers-building-a-sousveillance-state',
  25. 'only_matching': True,
  26. }]
  27. def _real_extract(self, url):
  28. display_id = self._match_id(url)
  29. webpage = self._download_webpage(url, display_id)
  30. if '>Queued for processing, please stand by...<' in webpage:
  31. raise ExtractorError(
  32. 'Audio is still queued for processing', expected=True)
  33. talk = self._parse_json(self._search_regex(
  34. r'initialSnapshot\s*=\s*({.+?});',
  35. webpage, 'talk'), display_id)['talk']
  36. title = talk['title']
  37. formats = [{
  38. 'url': urljoin(url, talk_url),
  39. 'format_id': format_id,
  40. 'ext': determine_ext(talk_url) or format_id,
  41. 'vcodec': 'none',
  42. } for format_id, talk_url in talk['media_links'].items()]
  43. return {
  44. 'id': compat_str(talk.get('id') or display_id),
  45. 'display_id': display_id,
  46. 'title': title,
  47. 'description': talk.get('teaser'),
  48. 'thumbnail': talk.get('image_url'),
  49. 'duration': int_or_none(talk.get('archived_duration')),
  50. 'view_count': int_or_none(talk.get('play_count')),
  51. 'formats': formats,
  52. }