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.

87 lines
3.2 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import json
  4. import re
  5. from .common import InfoExtractor
  6. from ..utils import (
  7. parse_duration,
  8. unified_strdate,
  9. )
  10. class LibsynIE(InfoExtractor):
  11. _VALID_URL = r'(?P<mainurl>https?://html5-player\.libsyn\.com/embed/episode/id/(?P<id>[0-9]+))'
  12. _TESTS = [{
  13. 'url': 'http://html5-player.libsyn.com/embed/episode/id/6385796/',
  14. 'md5': '2a55e75496c790cdeb058e7e6c087746',
  15. 'info_dict': {
  16. 'id': '6385796',
  17. 'ext': 'mp3',
  18. 'title': "Champion Minded - Developing a Growth Mindset",
  19. 'description': 'In this episode, Allistair talks about the importance of developing a growth mindset, not only in sports, but in life too.',
  20. 'upload_date': '20180320',
  21. 'thumbnail': 're:^https?://.*',
  22. },
  23. }, {
  24. '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/',
  25. 'md5': '6c5cb21acd622d754d3b1a92b582ce42',
  26. 'info_dict': {
  27. 'id': '3727166',
  28. 'ext': 'mp3',
  29. 'title': 'Clients From Hell Podcast - How a Sex Toy Company Kickstarted my Freelance Career',
  30. 'upload_date': '20150818',
  31. 'thumbnail': 're:^https?://.*',
  32. }
  33. }]
  34. def _real_extract(self, url):
  35. m = re.match(self._VALID_URL, url)
  36. video_id = m.group('id')
  37. url = m.group('mainurl')
  38. webpage = self._download_webpage(url, video_id)
  39. podcast_title = self._search_regex(
  40. r'<h3>([^<]+)</h3>', webpage, 'podcast title', default=None)
  41. if podcast_title:
  42. podcast_title = podcast_title.strip()
  43. episode_title = self._search_regex(
  44. r'(?:<div class="episode-title">|<h4>)([^<]+)</', webpage, 'episode title')
  45. if episode_title:
  46. episode_title = episode_title.strip()
  47. title = '%s - %s' % (podcast_title, episode_title) if podcast_title else episode_title
  48. description = self._html_search_regex(
  49. r'<p\s+id="info_text_body">(.+?)</p>', webpage,
  50. 'description', default=None)
  51. if description:
  52. # Strip non-breaking and normal spaces
  53. description = description.replace('\u00A0', ' ').strip()
  54. release_date = unified_strdate(self._search_regex(
  55. r'<div class="release_date">Released: ([^<]+)<', webpage, 'release date', fatal=False))
  56. data_json = self._search_regex(r'var\s+playlistItem\s*=\s*(\{.*?\});\n', webpage, 'JSON data block')
  57. data = json.loads(data_json)
  58. formats = [{
  59. 'url': data['media_url'],
  60. 'format_id': 'main',
  61. }, {
  62. 'url': data['media_url_libsyn'],
  63. 'format_id': 'libsyn',
  64. }]
  65. thumbnail = data.get('thumbnail_url')
  66. duration = parse_duration(data.get('duration'))
  67. return {
  68. 'id': video_id,
  69. 'title': title,
  70. 'description': description,
  71. 'thumbnail': thumbnail,
  72. 'upload_date': release_date,
  73. 'duration': duration,
  74. 'formats': formats,
  75. }