mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-10 03:10:38 +00:00
libsyn: adapt to new page structure and replace testcase
This commit is contained in:
parent
a66d1d079a
commit
3395958d2b
@ -1,24 +1,28 @@
|
|||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import json
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
from ..utils import unified_strdate
|
from ..utils import (
|
||||||
|
parse_duration,
|
||||||
|
unified_strdate,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class LibsynIE(InfoExtractor):
|
class LibsynIE(InfoExtractor):
|
||||||
_VALID_URL = r'(?P<mainurl>https?://html5-player\.libsyn\.com/embed/episode/id/(?P<id>[0-9]+))'
|
_VALID_URL = r'(?P<mainurl>https?://html5-player\.libsyn\.com/embed/episode/id/(?P<id>[0-9]+))'
|
||||||
|
|
||||||
_TESTS = [{
|
_TESTS = [{
|
||||||
'url': 'http://html5-player.libsyn.com/embed/episode/id/3377616/',
|
'url': 'http://html5-player.libsyn.com/embed/episode/id/6385796/',
|
||||||
'md5': '443360ee1b58007bc3dcf09b41d093bb',
|
'md5': '2a55e75496c790cdeb058e7e6c087746',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '3377616',
|
'id': '6385796',
|
||||||
'ext': 'mp3',
|
'ext': 'mp3',
|
||||||
'title': "The Daily Show Podcast without Jon Stewart - Episode 12: Bassem Youssef: Egypt's Jon Stewart",
|
'title': "Champion Minded - Developing a Growth Mindset",
|
||||||
'description': 'md5:601cb790edd05908957dae8aaa866465',
|
'description': 'In this episode, Allistair talks about the importance of developing a growth mindset, not only in sports, but in life too.',
|
||||||
'upload_date': '20150220',
|
'upload_date': '20180320',
|
||||||
'thumbnail': 're:^https?://.*',
|
'thumbnail': 're:^https?://.*',
|
||||||
},
|
},
|
||||||
}, {
|
}, {
|
||||||
@ -39,31 +43,45 @@ class LibsynIE(InfoExtractor):
|
|||||||
url = m.group('mainurl')
|
url = m.group('mainurl')
|
||||||
webpage = self._download_webpage(url, video_id)
|
webpage = self._download_webpage(url, video_id)
|
||||||
|
|
||||||
formats = [{
|
|
||||||
'url': media_url,
|
|
||||||
} for media_url in set(re.findall(r'var\s+mediaURL(?:Libsyn)?\s*=\s*"([^"]+)"', webpage))]
|
|
||||||
|
|
||||||
podcast_title = self._search_regex(
|
podcast_title = self._search_regex(
|
||||||
r'<h2>([^<]+)</h2>', webpage, 'podcast title', default=None)
|
r'<h3>([^<]+)</h3>', webpage, 'podcast title', default=None)
|
||||||
|
if podcast_title:
|
||||||
|
podcast_title = podcast_title.strip()
|
||||||
episode_title = self._search_regex(
|
episode_title = self._search_regex(
|
||||||
r'(?:<div class="episode-title">|<h3>)([^<]+)</', webpage, 'episode title')
|
r'(?:<div class="episode-title">|<h4>)([^<]+)</', webpage, 'episode title')
|
||||||
|
if episode_title:
|
||||||
|
episode_title = episode_title.strip()
|
||||||
|
|
||||||
title = '%s - %s' % (podcast_title, episode_title) if podcast_title else episode_title
|
title = '%s - %s' % (podcast_title, episode_title) if podcast_title else episode_title
|
||||||
|
|
||||||
description = self._html_search_regex(
|
description = self._html_search_regex(
|
||||||
r'<div id="info_text_body">(.+?)</div>', webpage,
|
r'<p\s+id="info_text_body">(.+?)</p>', webpage,
|
||||||
'description', default=None)
|
'description', default=None)
|
||||||
thumbnail = self._search_regex(
|
if description:
|
||||||
r'<img[^>]+class="info-show-icon"[^>]+src="([^"]+)"',
|
# Strip non-breaking and normal spaces
|
||||||
webpage, 'thumbnail', fatal=False)
|
description = description.replace('\u00A0', ' ').strip()
|
||||||
release_date = unified_strdate(self._search_regex(
|
release_date = unified_strdate(self._search_regex(
|
||||||
r'<div class="release_date">Released: ([^<]+)<', webpage, 'release date', fatal=False))
|
r'<div class="release_date">Released: ([^<]+)<', webpage, 'release date', fatal=False))
|
||||||
|
|
||||||
|
data_json = self._search_regex(r'var\s+playlistItem\s*=\s*(\{.*?\});\n', webpage, 'JSON data block')
|
||||||
|
data = json.loads(data_json)
|
||||||
|
|
||||||
|
formats = [{
|
||||||
|
'url': data['media_url'],
|
||||||
|
'format_id': 'main',
|
||||||
|
}, {
|
||||||
|
'url': data['media_url_libsyn'],
|
||||||
|
'format_id': 'libsyn',
|
||||||
|
}]
|
||||||
|
thumbnail = data.get('thumbnail_url')
|
||||||
|
duration = parse_duration(data.get('duration'))
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'id': video_id,
|
'id': video_id,
|
||||||
'title': title,
|
'title': title,
|
||||||
'description': description,
|
'description': description,
|
||||||
'thumbnail': thumbnail,
|
'thumbnail': thumbnail,
|
||||||
'upload_date': release_date,
|
'upload_date': release_date,
|
||||||
|
'duration': duration,
|
||||||
'formats': formats,
|
'formats': formats,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user