]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/webofstories.py
[ie/youtube] Suppress "Unavailable videos are hidden" warning (#10159)
[yt-dlp.git] / yt_dlp / extractor / webofstories.py
1 import re
2
3 from .common import InfoExtractor
4 from ..utils import (
5 int_or_none,
6 orderedSet,
7 )
8
9
10 class WebOfStoriesIE(InfoExtractor):
11 _VALID_URL = r'https?://(?:www\.)?webofstories\.com/play/(?:[^/]+/)?(?P<id>[0-9]+)'
12 _VIDEO_DOMAIN = 'http://eu-mobile.webofstories.com/'
13 _GREAT_LIFE_STREAMER = 'rtmp://eu-cdn1.webofstories.com/cfx/st/'
14 _USER_STREAMER = 'rtmp://eu-users.webofstories.com/cfx/st/'
15 _TESTS = [{
16 'url': 'http://www.webofstories.com/play/hans.bethe/71',
17 'md5': '373e4dd915f60cfe3116322642ddf364',
18 'info_dict': {
19 'id': '4536',
20 'ext': 'mp4',
21 'title': 'The temperature of the sun',
22 'thumbnail': r're:^https?://.*\.jpg$',
23 'description': 'Hans Bethe talks about calculating the temperature of the sun',
24 'duration': 238,
25 },
26 }, {
27 'url': 'http://www.webofstories.com/play/55908',
28 'md5': '2985a698e1fe3211022422c4b5ed962c',
29 'info_dict': {
30 'id': '55908',
31 'ext': 'mp4',
32 'title': 'The story of Gemmata obscuriglobus',
33 'thumbnail': r're:^https?://.*\.jpg$',
34 'description': 'Planctomycete talks about The story of Gemmata obscuriglobus',
35 'duration': 169,
36 },
37 'skip': 'notfound',
38 }, {
39 # malformed og:title meta
40 'url': 'http://www.webofstories.com/play/54215?o=MS',
41 'info_dict': {
42 'id': '54215',
43 'ext': 'mp4',
44 'title': '"A Leg to Stand On"',
45 'thumbnail': r're:^https?://.*\.jpg$',
46 'description': 'Oliver Sacks talks about the death and resurrection of a limb',
47 'duration': 97,
48 },
49 'params': {
50 'skip_download': True,
51 },
52 }]
53
54 def _real_extract(self, url):
55 video_id = self._match_id(url)
56
57 webpage = self._download_webpage(url, video_id)
58 # Sometimes og:title meta is malformed
59 title = self._og_search_title(webpage, default=None) or self._html_search_regex(
60 r'(?s)<strong>Title:\s*</strong>(.+?)<', webpage, 'title')
61 description = self._html_search_meta('description', webpage)
62 thumbnail = self._og_search_thumbnail(webpage)
63
64 embed_params = [s.strip(" \r\n\t'") for s in self._search_regex(
65 r'(?s)\$\("#embedCode"\).html\(getEmbedCode\((.*?)\)',
66 webpage, 'embed params').split(',')]
67
68 (
69 _, speaker_id, story_id, story_duration,
70 speaker_type, great_life, _thumbnail, _has_subtitles,
71 story_filename, _story_order) = embed_params
72
73 is_great_life_series = great_life == 'true'
74 duration = int_or_none(story_duration)
75
76 # URL building, see: http://www.webofstories.com/scripts/player.js
77 ms_prefix = ''
78 if speaker_type.lower() == 'ms':
79 ms_prefix = 'mini_sites/'
80
81 if is_great_life_series:
82 mp4_url = f'{self._VIDEO_DOMAIN}lives/{speaker_id}/{story_filename}.mp4'
83 rtmp_ext = 'flv'
84 streamer = self._GREAT_LIFE_STREAMER
85 play_path = f'stories/{speaker_id}/{story_filename}'
86 else:
87 mp4_url = f'{self._VIDEO_DOMAIN}{ms_prefix}{speaker_id}/{story_filename}.mp4'
88 rtmp_ext = 'mp4'
89 streamer = self._USER_STREAMER
90 play_path = f'mp4:{ms_prefix}{speaker_id}/{story_filename}.mp4'
91
92 formats = [{
93 'format_id': 'mp4_sd',
94 'url': mp4_url,
95 }, {
96 'format_id': 'rtmp_sd',
97 'page_url': url,
98 'url': streamer,
99 'ext': rtmp_ext,
100 'play_path': play_path,
101 }]
102
103 return {
104 'id': story_id,
105 'title': title,
106 'formats': formats,
107 'thumbnail': thumbnail,
108 'description': description,
109 'duration': duration,
110 }
111
112
113 class WebOfStoriesPlaylistIE(InfoExtractor):
114 _VALID_URL = r'https?://(?:www\.)?webofstories\.com/playAll/(?P<id>[^/]+)'
115 _TEST = {
116 'url': 'http://www.webofstories.com/playAll/donald.knuth',
117 'info_dict': {
118 'id': 'donald.knuth',
119 'title': 'Donald Knuth (Scientist)',
120 },
121 'playlist_mincount': 97,
122 }
123
124 def _real_extract(self, url):
125 playlist_id = self._match_id(url)
126
127 webpage = self._download_webpage(url, playlist_id)
128
129 entries = [
130 self.url_result(
131 f'http://www.webofstories.com/play/{video_id}',
132 'WebOfStories', video_id=video_id)
133 for video_id in orderedSet(re.findall(r'\bid=["\']td_(\d+)', webpage))
134 ]
135
136 title = self._search_regex(
137 r'<div id="speakerName">\s*<span>([^<]+)</span>',
138 webpage, 'speaker', default=None)
139 if title:
140 field = self._search_regex(
141 r'<span id="primaryField">([^<]+)</span>',
142 webpage, 'field', default=None)
143 if field:
144 title += f' ({field})'
145
146 if not title:
147 title = self._search_regex(
148 r'<title>Play\s+all\s+stories\s*-\s*([^<]+)\s*-\s*Web\s+of\s+Stories</title>',
149 webpage, 'title')
150
151 return self.playlist_result(entries, playlist_id, title)