2015-03-22 08:11:10 +06:00
|
|
|
# coding: utf-8
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
import re
|
|
|
|
|
2015-03-16 20:05:02 +01:00
|
|
|
from .common import InfoExtractor
|
2015-03-22 08:11:10 +06:00
|
|
|
from ..utils import unified_strdate
|
|
|
|
|
2015-03-16 20:05:02 +01:00
|
|
|
|
|
|
|
class LibsynIE(InfoExtractor):
|
2015-08-18 13:02:41 +02:00
|
|
|
_VALID_URL = r'(?P<mainurl>https?://html5-player\.libsyn\.com/embed/episode/id/(?P<id>[0-9]+))'
|
2015-03-22 08:11:10 +06:00
|
|
|
|
2015-08-18 13:02:41 +02:00
|
|
|
_TESTS = [{
|
2018-03-17 21:18:18 +01:00
|
|
|
'url': 'http://html5-player.libsyn.com/embed/episode/id/6324076/',
|
|
|
|
'md5': '5b497505660690028d482f9a28431cca',
|
2015-03-17 18:54:36 +01:00
|
|
|
'info_dict': {
|
2018-03-17 21:18:18 +01:00
|
|
|
'id': '6324076',
|
2015-03-22 08:11:10 +06:00
|
|
|
'ext': 'mp3',
|
2018-03-17 21:18:18 +01:00
|
|
|
'title': "Verily, Octopi Sing - Pandas are not smallpox",
|
|
|
|
'description': 'md5:0d20ad472ae296f22a0c9df23a6d78f1',
|
|
|
|
'upload_date': '20180303',
|
2015-08-18 13:02:41 +02:00
|
|
|
'thumbnail': 're:^https?://.*',
|
2015-03-17 18:54:36 +01:00
|
|
|
},
|
2015-08-18 13:02:41 +02: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',
|
2018-03-17 21:18:18 +01:00
|
|
|
'description': 'md5:996a28b4f829ed4ffb8302a53d825704',
|
2015-08-18 13:02:41 +02:00
|
|
|
'upload_date': '20150818',
|
|
|
|
'thumbnail': 're:^https?://.*',
|
|
|
|
}
|
|
|
|
}]
|
2015-03-16 20:05:02 +01:00
|
|
|
|
|
|
|
def _real_extract(self, url):
|
2015-08-18 13:02:41 +02:00
|
|
|
m = re.match(self._VALID_URL, url)
|
|
|
|
video_id = m.group('id')
|
|
|
|
url = m.group('mainurl')
|
2015-03-22 08:11:10 +06:00
|
|
|
webpage = self._download_webpage(url, video_id)
|
|
|
|
|
2018-03-17 21:18:18 +01:00
|
|
|
media_url_json = self._search_regex(r'"media_url(?:_libsyn)?"\s*:\s*("(\\"|[^"])+")', webpage, 'media_url')
|
|
|
|
media_url = self._parse_json(media_url_json, video_id)
|
2015-03-22 08:11:10 +06:00
|
|
|
|
2018-03-17 21:18:18 +01:00
|
|
|
podcast_title = self._html_search_regex( r'<h3\b[^>]*>([^<]+)</h3>', webpage, 'podcast title', default=None)
|
|
|
|
episode_title_json = self._search_regex(r'"item_title"\s*:\s*("(\\"|[^"])+")', webpage, 'episode title', default=None)
|
|
|
|
episode_title = self._parse_json(episode_title_json, video_id, fatal=False)
|
|
|
|
if episode_title is None:
|
|
|
|
# Fallback: scrape from page
|
|
|
|
episode_title = self._html_search_regex(r'<h4\b[^>]*>([^<]+)', webpage, 'episode title')
|
2015-03-22 11:03:52 +01:00
|
|
|
title = '%s - %s' % (podcast_title, episode_title) if podcast_title else episode_title
|
2015-03-22 08:11:10 +06:00
|
|
|
|
|
|
|
description = self._html_search_regex(
|
2018-03-17 21:18:18 +01:00
|
|
|
r'<(\w+)\b[^>]*id="info_text_body"[^>]*>(?P<description>.+?)<\/\1>',
|
|
|
|
webpage, 'description', default=None, group='description')
|
|
|
|
|
|
|
|
thumbnail_json = self._search_regex(r'"thumbnail_url"\s*:\s*("(\\"|[^"])+")', webpage, 'thumbnail')
|
|
|
|
thumbnail = self._parse_json(thumbnail_json, video_id, fatal=False)
|
|
|
|
|
|
|
|
release_date_json = self._search_regex(r'"release_date"\s*:\s*("(\\"|[^"])+")', webpage, 'release date')
|
|
|
|
release_date = unified_strdate(self._parse_json(release_date_json, video_id, fatal=False))
|
|
|
|
if release_date is None:
|
|
|
|
# Fallback: scrape from page
|
|
|
|
release_date = unified_strdate(self._search_regex(
|
|
|
|
r'<div class="release_date">Released: ([^<]+)<', webpage, 'release date', fatal=False))
|
2015-03-16 20:05:02 +01:00
|
|
|
|
|
|
|
return {
|
2015-03-22 08:11:10 +06:00
|
|
|
'id': video_id,
|
|
|
|
'title': title,
|
|
|
|
'description': description,
|
|
|
|
'thumbnail': thumbnail,
|
|
|
|
'upload_date': release_date,
|
2018-03-17 21:18:18 +01:00
|
|
|
'url': media_url,
|
2015-03-16 20:05:02 +01:00
|
|
|
}
|