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.

69 lines
2.6 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import unified_strdate
  6. class LibsynIE(InfoExtractor):
  7. _VALID_URL = r'(?P<mainurl>https?://html5-player\.libsyn\.com/embed/episode/id/(?P<id>[0-9]+))'
  8. _TESTS = [{
  9. 'url': 'http://html5-player.libsyn.com/embed/episode/id/3377616/',
  10. 'md5': '443360ee1b58007bc3dcf09b41d093bb',
  11. 'info_dict': {
  12. 'id': '3377616',
  13. 'ext': 'mp3',
  14. 'title': "The Daily Show Podcast without Jon Stewart - Episode 12: Bassem Youssef: Egypt's Jon Stewart",
  15. 'description': 'md5:601cb790edd05908957dae8aaa866465',
  16. 'upload_date': '20150220',
  17. 'thumbnail': 're:^https?://.*',
  18. },
  19. }, {
  20. 'url': 'https://html5-player.libsyn.com/embed/episode/id/3727166/height/75/width/200/theme/standard/direction/no/autoplay/no/autonext/no/thumbnail/no/preload/no/no_addthis/no/',
  21. 'md5': '6c5cb21acd622d754d3b1a92b582ce42',
  22. 'info_dict': {
  23. 'id': '3727166',
  24. 'ext': 'mp3',
  25. 'title': 'Clients From Hell Podcast - How a Sex Toy Company Kickstarted my Freelance Career',
  26. 'upload_date': '20150818',
  27. 'thumbnail': 're:^https?://.*',
  28. }
  29. }]
  30. def _real_extract(self, url):
  31. m = re.match(self._VALID_URL, url)
  32. video_id = m.group('id')
  33. url = m.group('mainurl')
  34. webpage = self._download_webpage(url, video_id)
  35. formats = [{
  36. 'url': media_url,
  37. } for media_url in set(re.findall('var\s+mediaURL(?:Libsyn)?\s*=\s*"([^"]+)"', webpage))]
  38. podcast_title = self._search_regex(
  39. r'<h2>([^<]+)</h2>', webpage, 'podcast title', default=None)
  40. episode_title = self._search_regex(
  41. r'(?:<div class="episode-title">|<h3>)([^<]+)</', webpage, 'episode title')
  42. title = '%s - %s' % (podcast_title, episode_title) if podcast_title else episode_title
  43. description = self._html_search_regex(
  44. r'<div id="info_text_body">(.+?)</div>', webpage,
  45. 'description', default=None)
  46. thumbnail = self._search_regex(
  47. r'<img[^>]+class="info-show-icon"[^>]+src="([^"]+)"',
  48. webpage, 'thumbnail', fatal=False)
  49. release_date = unified_strdate(self._search_regex(
  50. r'<div class="release_date">Released: ([^<]+)<', webpage, 'release date', fatal=False))
  51. return {
  52. 'id': video_id,
  53. 'title': title,
  54. 'description': description,
  55. 'thumbnail': thumbnail,
  56. 'upload_date': release_date,
  57. 'formats': formats,
  58. }