voicerepublic.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..compat import (
  5. compat_urllib_request,
  6. )
  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. 'creator': 'M. C. McGrath',
  19. }
  20. }
  21. def _real_extract(self, url):
  22. display_id = self._match_id(url)
  23. req = compat_urllib_request.Request(url)
  24. # Older versions of Firefox get redirected to an "upgrade browser" page
  25. req.add_header('User-Agent', 'youtube-dl')
  26. webpage = self._download_webpage(req, display_id)
  27. thumbnail = self._og_search_thumbnail(webpage)
  28. video_id = self._search_regex(r'/(\d+)\.png', thumbnail, 'id')
  29. if '<div class=\'vr-player jp-jplayer\'' in webpage:
  30. formats = [{
  31. 'url': 'https://voicerepublic.com/vrmedia/{}-clean.{}'.format(video_id, ext),
  32. 'ext': ext,
  33. 'format_id': ext,
  34. 'vcodec': 'none',
  35. } for ext in ['m4a', 'mp3', 'ogg']]
  36. self._sort_formats(formats)
  37. else:
  38. # Audio is still queued for processing
  39. formats = []
  40. return {
  41. 'id': video_id,
  42. 'title': self._og_search_title(webpage),
  43. 'formats': formats,
  44. 'url': self._og_search_url(webpage),
  45. 'thumbnail': thumbnail,
  46. 'description': self._og_search_description(webpage),
  47. 'creator': self._search_regex(r'<meta content=\'([^\']*?)\' name=\'author\'>', webpage, 'author', fatal=False),
  48. }