voicerepublic.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import compat_urllib_request
  6. from ..utils import ExtractorError
  7. class VoiceRepublicIE(InfoExtractor):
  8. _VALID_URL = r'https?://voicerepublic\.com/talks/(?P<id>[0-9a-z-]+)'
  9. _TEST = {
  10. 'url': 'https://voicerepublic.com/talks/watching-the-watchers-building-a-sousveillance-state',
  11. 'md5': '0554a24d1657915aa8e8f84e15dc9353',
  12. 'info_dict': {
  13. 'id': '2296',
  14. 'ext': 'm4a',
  15. 'title': 'Watching the Watchers: Building a Sousveillance State',
  16. 'thumbnail': 'https://voicerepublic.com/system/flyer/2296.png',
  17. 'description': 'md5:715ba964958afa2398df615809cfecb1',
  18. }
  19. }
  20. def _real_extract(self, url):
  21. display_id = self._match_id(url)
  22. req = compat_urllib_request.Request(url)
  23. # Older versions of Firefox get redirected to an "upgrade browser" page
  24. req.add_header('User-Agent', 'youtube-dl')
  25. webpage = self._download_webpage(req, display_id)
  26. thumbnail = self._og_search_thumbnail(webpage)
  27. video_id = self._search_regex(r'/(\d+)\.png', thumbnail, 'id')
  28. if '<a>Queued for processing, please stand by...</a>' in webpage:
  29. raise ExtractorError('Audio is still queued for processing')
  30. formats = [{
  31. 'url': 'https://voicerepublic.com' + path,
  32. 'ext': ext,
  33. 'format_id': ext,
  34. 'vcodec': 'none',
  35. } for ext, path in re.findall(r"data-([^=]+)='(/[^']+\.\1)'", webpage)]
  36. self._sort_formats(formats)
  37. return {
  38. 'id': video_id,
  39. 'title': self._og_search_title(webpage),
  40. 'formats': formats,
  41. 'url': self._og_search_url(webpage),
  42. 'thumbnail': thumbnail,
  43. 'description': self._og_search_description(webpage),
  44. }