2015-03-16 19:05:02 +00:00
|
|
|
from .common import InfoExtractor
|
2018-03-20 22:07:11 +00:00
|
|
|
from ..utils import (
|
2019-03-03 05:18:15 +00:00
|
|
|
clean_html,
|
|
|
|
get_element_by_class,
|
2018-03-20 22:07:11 +00:00
|
|
|
parse_duration,
|
2019-03-03 05:18:15 +00:00
|
|
|
strip_or_none,
|
2018-03-20 22:07:11 +00:00
|
|
|
unified_strdate,
|
|
|
|
)
|
2015-03-22 02:11:10 +00:00
|
|
|
|
2015-03-16 19:05:02 +00:00
|
|
|
|
|
|
|
class LibsynIE(InfoExtractor):
|
2015-08-18 11:02:41 +00:00
|
|
|
_VALID_URL = r'(?P<mainurl>https?://html5-player\.libsyn\.com/embed/episode/id/(?P<id>[0-9]+))'
|
2022-08-01 01:23:25 +00:00
|
|
|
_EMBED_REGEX = [r'<iframe[^>]+src=(["\'])(?P<url>(?:https?:)?//html5-player\.libsyn\.com/embed/.+?)\1']
|
2015-03-22 02:11:10 +00:00
|
|
|
|
2015-08-18 11:02:41 +00:00
|
|
|
_TESTS = [{
|
2018-03-20 22:07:11 +00:00
|
|
|
'url': 'http://html5-player.libsyn.com/embed/episode/id/6385796/',
|
|
|
|
'md5': '2a55e75496c790cdeb058e7e6c087746',
|
2015-03-17 17:54:36 +00:00
|
|
|
'info_dict': {
|
2018-03-20 22:07:11 +00:00
|
|
|
'id': '6385796',
|
2015-03-22 02:11:10 +00:00
|
|
|
'ext': 'mp3',
|
2018-03-20 22:07:11 +00:00
|
|
|
'title': "Champion Minded - Developing a Growth Mindset",
|
2019-03-03 05:18:15 +00:00
|
|
|
# description fetched using another request:
|
|
|
|
# http://html5-player.libsyn.com/embed/getitemdetails?item_id=6385796
|
|
|
|
# 'description': 'In this episode, Allistair talks about the importance of developing a growth mindset, not only in sports, but in life too.',
|
2018-03-20 22:07:11 +00:00
|
|
|
'upload_date': '20180320',
|
2015-08-18 11:02:41 +00:00
|
|
|
'thumbnail': 're:^https?://.*',
|
2015-03-17 17:54:36 +00:00
|
|
|
},
|
2015-08-18 11:02:41 +00:00
|
|
|
}, {
|
|
|
|
'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/',
|
|
|
|
'md5': '6c5cb21acd622d754d3b1a92b582ce42',
|
|
|
|
'info_dict': {
|
|
|
|
'id': '3727166',
|
|
|
|
'ext': 'mp3',
|
|
|
|
'title': 'Clients From Hell Podcast - How a Sex Toy Company Kickstarted my Freelance Career',
|
|
|
|
'upload_date': '20150818',
|
|
|
|
'thumbnail': 're:^https?://.*',
|
|
|
|
}
|
|
|
|
}]
|
2015-03-16 19:05:02 +00:00
|
|
|
|
|
|
|
def _real_extract(self, url):
|
2021-08-19 01:41:24 +00:00
|
|
|
url, video_id = self._match_valid_url(url).groups()
|
2015-03-22 02:11:10 +00:00
|
|
|
webpage = self._download_webpage(url, video_id)
|
|
|
|
|
2019-03-03 05:18:15 +00:00
|
|
|
data = self._parse_json(self._search_regex(
|
|
|
|
r'var\s+playlistItem\s*=\s*({.+?});',
|
|
|
|
webpage, 'JSON data block'), video_id)
|
|
|
|
|
|
|
|
episode_title = data.get('item_title') or get_element_by_class('episode-title', webpage)
|
|
|
|
if not episode_title:
|
|
|
|
self._search_regex(
|
|
|
|
[r'data-title="([^"]+)"', r'<title>(.+?)</title>'],
|
|
|
|
webpage, 'episode title')
|
|
|
|
episode_title = episode_title.strip()
|
|
|
|
|
|
|
|
podcast_title = strip_or_none(clean_html(self._search_regex(
|
|
|
|
r'<h3>([^<]+)</h3>', webpage, 'podcast title',
|
|
|
|
default=None) or get_element_by_class('podcast-title', webpage)))
|
2015-03-22 02:11:10 +00:00
|
|
|
|
2015-03-22 10:03:52 +00:00
|
|
|
title = '%s - %s' % (podcast_title, episode_title) if podcast_title else episode_title
|
2015-03-22 02:11:10 +00:00
|
|
|
|
2019-03-03 05:18:15 +00:00
|
|
|
formats = []
|
|
|
|
for k, format_id in (('media_url_libsyn', 'libsyn'), ('media_url', 'main'), ('download_link', 'download')):
|
|
|
|
f_url = data.get(k)
|
|
|
|
if not f_url:
|
|
|
|
continue
|
|
|
|
formats.append({
|
|
|
|
'url': f_url,
|
|
|
|
'format_id': format_id,
|
|
|
|
})
|
|
|
|
|
2015-03-22 02:11:10 +00:00
|
|
|
description = self._html_search_regex(
|
2018-03-20 22:07:11 +00:00
|
|
|
r'<p\s+id="info_text_body">(.+?)</p>', webpage,
|
2015-08-18 11:02:41 +00:00
|
|
|
'description', default=None)
|
2018-03-20 22:07:11 +00:00
|
|
|
if description:
|
|
|
|
# Strip non-breaking and normal spaces
|
|
|
|
description = description.replace('\u00A0', ' ').strip()
|
2015-03-22 02:11:10 +00:00
|
|
|
release_date = unified_strdate(self._search_regex(
|
2019-03-03 05:18:15 +00:00
|
|
|
r'<div class="release_date">Released: ([^<]+)<',
|
|
|
|
webpage, 'release date', default=None) or data.get('release_date'))
|
2018-03-20 22:07:11 +00:00
|
|
|
|
2015-03-16 19:05:02 +00:00
|
|
|
return {
|
2015-03-22 02:11:10 +00:00
|
|
|
'id': video_id,
|
|
|
|
'title': title,
|
|
|
|
'description': description,
|
2019-03-03 05:18:15 +00:00
|
|
|
'thumbnail': data.get('thumbnail_url'),
|
2015-03-22 02:11:10 +00:00
|
|
|
'upload_date': release_date,
|
2019-03-03 05:18:15 +00:00
|
|
|
'duration': parse_duration(data.get('duration')),
|
2015-03-16 19:05:02 +00:00
|
|
|
'formats': formats,
|
|
|
|
}
|