mirror of https://github.com/yt-dlp/yt-dlp.git
[stitcher] Merge from youtube-dl (#175)
This cherry-picks the commits:a563c97c5c (diff-cc37718b18689c1c0588c4c74518853ef43ab020bbd674f3c04d4eae037798d2)
8522bcd97c (diff-cc37718b18689c1c0588c4c74518853ef43ab020bbd674f3c04d4eae037798d2)
Authored by: nixxo
This commit is contained in:
parent
18c1f04362
commit
605d299f83
|
@ -1179,7 +1179,10 @@ from .spike import (
|
||||||
BellatorIE,
|
BellatorIE,
|
||||||
ParamountNetworkIE,
|
ParamountNetworkIE,
|
||||||
)
|
)
|
||||||
from .stitcher import StitcherIE
|
from .stitcher import (
|
||||||
|
StitcherIE,
|
||||||
|
StitcherShowIE,
|
||||||
|
)
|
||||||
from .sport5 import Sport5IE
|
from .sport5 import Sport5IE
|
||||||
from .sportbox import SportBoxIE
|
from .sportbox import SportBoxIE
|
||||||
from .sportdeutschland import SportDeutschlandIE
|
from .sportdeutschland import SportDeutschlandIE
|
||||||
|
|
|
@ -1,19 +1,61 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import re
|
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
|
from ..compat import compat_str
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
clean_html,
|
clean_html,
|
||||||
|
clean_podcast_url,
|
||||||
ExtractorError,
|
ExtractorError,
|
||||||
int_or_none,
|
int_or_none,
|
||||||
str_or_none,
|
str_or_none,
|
||||||
try_get,
|
try_get,
|
||||||
|
url_or_none,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class StitcherIE(InfoExtractor):
|
class StitcherBaseIE(InfoExtractor):
|
||||||
_VALID_URL = r'https?://(?:www\.)?stitcher\.com/(?:podcast|show)/(?:[^/]+/)+e(?:pisode)?/(?:(?P<display_id>[^/#?&]+?)-)?(?P<id>\d+)(?:[/#?&]|$)'
|
_VALID_URL_BASE = r'https?://(?:www\.)?stitcher\.com/(?:podcast|show)/'
|
||||||
|
|
||||||
|
def _call_api(self, path, video_id, query):
|
||||||
|
resp = self._download_json(
|
||||||
|
'https://api.prod.stitcher.com/' + path,
|
||||||
|
video_id, query=query)
|
||||||
|
error_massage = try_get(resp, lambda x: x['errors'][0]['message'])
|
||||||
|
if error_massage:
|
||||||
|
raise ExtractorError(error_massage, expected=True)
|
||||||
|
return resp['data']
|
||||||
|
|
||||||
|
def _extract_description(self, data):
|
||||||
|
return clean_html(data.get('html_description') or data.get('description'))
|
||||||
|
|
||||||
|
def _extract_audio_url(self, episode):
|
||||||
|
return url_or_none(episode.get('audio_url') or episode.get('guid'))
|
||||||
|
|
||||||
|
def _extract_show_info(self, show):
|
||||||
|
return {
|
||||||
|
'thumbnail': show.get('image_base_url'),
|
||||||
|
'series': show.get('title'),
|
||||||
|
}
|
||||||
|
|
||||||
|
def _extract_episode(self, episode, audio_url, show_info):
|
||||||
|
info = {
|
||||||
|
'id': compat_str(episode['id']),
|
||||||
|
'display_id': episode.get('slug'),
|
||||||
|
'title': episode['title'].strip(),
|
||||||
|
'description': self._extract_description(episode),
|
||||||
|
'duration': int_or_none(episode.get('duration')),
|
||||||
|
'url': clean_podcast_url(audio_url),
|
||||||
|
'vcodec': 'none',
|
||||||
|
'timestamp': int_or_none(episode.get('date_published')),
|
||||||
|
'season_number': int_or_none(episode.get('season')),
|
||||||
|
'season_id': str_or_none(episode.get('season_id')),
|
||||||
|
}
|
||||||
|
info.update(show_info)
|
||||||
|
return info
|
||||||
|
|
||||||
|
|
||||||
|
class StitcherIE(StitcherBaseIE):
|
||||||
|
_VALID_URL = StitcherBaseIE._VALID_URL_BASE + r'(?:[^/]+/)+e(?:pisode)?/(?:[^/#?&]+-)?(?P<id>\d+)'
|
||||||
_TESTS = [{
|
_TESTS = [{
|
||||||
'url': 'http://www.stitcher.com/podcast/the-talking-machines/e/40789481?autoplay=true',
|
'url': 'http://www.stitcher.com/podcast/the-talking-machines/e/40789481?autoplay=true',
|
||||||
'md5': 'e9635098e0da10b21a0e2b85585530f6',
|
'md5': 'e9635098e0da10b21a0e2b85585530f6',
|
||||||
|
@ -24,8 +66,9 @@ class StitcherIE(InfoExtractor):
|
||||||
'description': 'md5:547adb4081864be114ae3831b4c2b42f',
|
'description': 'md5:547adb4081864be114ae3831b4c2b42f',
|
||||||
'duration': 1604,
|
'duration': 1604,
|
||||||
'thumbnail': r're:^https?://.*\.jpg',
|
'thumbnail': r're:^https?://.*\.jpg',
|
||||||
'upload_date': '20180126',
|
'upload_date': '20151008',
|
||||||
'timestamp': 1516989316,
|
'timestamp': 1444285800,
|
||||||
|
'series': 'Talking Machines',
|
||||||
},
|
},
|
||||||
}, {
|
}, {
|
||||||
'url': 'http://www.stitcher.com/podcast/panoply/vulture-tv/e/the-rare-hourlong-comedy-plus-40846275?autoplay=true',
|
'url': 'http://www.stitcher.com/podcast/panoply/vulture-tv/e/the-rare-hourlong-comedy-plus-40846275?autoplay=true',
|
||||||
|
@ -55,33 +98,47 @@ class StitcherIE(InfoExtractor):
|
||||||
}]
|
}]
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
display_id, audio_id = re.match(self._VALID_URL, url).groups()
|
audio_id = self._match_id(url)
|
||||||
|
data = self._call_api(
|
||||||
|
'shows/episodes', audio_id, {'episode_ids': audio_id})
|
||||||
|
episode = data['episodes'][0]
|
||||||
|
audio_url = self._extract_audio_url(episode)
|
||||||
|
if not audio_url:
|
||||||
|
self.raise_login_required()
|
||||||
|
show = try_get(data, lambda x: x['shows'][0], dict) or {}
|
||||||
|
return self._extract_episode(
|
||||||
|
episode, audio_url, self._extract_show_info(show))
|
||||||
|
|
||||||
resp = self._download_json(
|
|
||||||
'https://api.prod.stitcher.com/episode/' + audio_id,
|
|
||||||
display_id or audio_id)
|
|
||||||
episode = try_get(resp, lambda x: x['data']['episodes'][0], dict)
|
|
||||||
if not episode:
|
|
||||||
raise ExtractorError(resp['errors'][0]['message'], expected=True)
|
|
||||||
|
|
||||||
title = episode['title'].strip()
|
class StitcherShowIE(StitcherBaseIE):
|
||||||
audio_url = episode['audio_url']
|
_VALID_URL = StitcherBaseIE._VALID_URL_BASE + r'(?P<id>[^/#?&]+)/?(?:[?#&]|$)'
|
||||||
|
_TESTS = [{
|
||||||
|
'url': 'http://www.stitcher.com/podcast/the-talking-machines',
|
||||||
|
'info_dict': {
|
||||||
|
'id': 'the-talking-machines',
|
||||||
|
'title': 'Talking Machines',
|
||||||
|
'description': 'md5:831f0995e40f26c10231af39cf1ebf0b',
|
||||||
|
},
|
||||||
|
'playlist_mincount': 106,
|
||||||
|
}, {
|
||||||
|
'url': 'https://www.stitcher.com/show/the-talking-machines',
|
||||||
|
'only_matching': True,
|
||||||
|
}]
|
||||||
|
|
||||||
thumbnail = None
|
def _real_extract(self, url):
|
||||||
show_id = episode.get('show_id')
|
show_slug = self._match_id(url)
|
||||||
if show_id and episode.get('classic_id') != -1:
|
data = self._call_api(
|
||||||
thumbnail = 'https://stitcher-classic.imgix.net/feedimages/%s.jpg' % show_id
|
'search/show/%s/allEpisodes' % show_slug, show_slug, {'count': 10000})
|
||||||
|
show = try_get(data, lambda x: x['shows'][0], dict) or {}
|
||||||
|
show_info = self._extract_show_info(show)
|
||||||
|
|
||||||
return {
|
entries = []
|
||||||
'id': audio_id,
|
for episode in (data.get('episodes') or []):
|
||||||
'display_id': display_id,
|
audio_url = self._extract_audio_url(episode)
|
||||||
'title': title,
|
if not audio_url:
|
||||||
'description': clean_html(episode.get('html_description') or episode.get('description')),
|
continue
|
||||||
'duration': int_or_none(episode.get('duration')),
|
entries.append(self._extract_episode(episode, audio_url, show_info))
|
||||||
'thumbnail': thumbnail,
|
|
||||||
'url': audio_url,
|
return self.playlist_result(
|
||||||
'vcodec': 'none',
|
entries, show_slug, show.get('title'),
|
||||||
'timestamp': int_or_none(episode.get('date_created')),
|
self._extract_description(show))
|
||||||
'season_number': int_or_none(episode.get('season')),
|
|
||||||
'season_id': str_or_none(episode.get('season_id')),
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue