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.

62 lines
2.2 KiB

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