logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

libsyn.py (3637B)


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