]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/myspace.py
[ie/youtube] Suppress "Unavailable videos are hidden" warning (#10159)
[yt-dlp.git] / yt_dlp / extractor / myspace.py
CommitLineData
2563bcc8 1import re
2563bcc8
JMF
2
3from .common import InfoExtractor
6b820a23 4from ..utils import (
5 ExtractorError,
6 int_or_none,
7 parse_iso8601,
2563bcc8
JMF
8)
9
10
11class MySpaceIE(InfoExtractor):
3166b1f0
S
12 _VALID_URL = r'''(?x)
13 https?://
14 myspace\.com/[^/]+/
15 (?P<mediatype>
16 video/[^/]+/(?P<video_id>\d+)|
17 music/song/[^/?#&]+-(?P<song_id>\d+)-\d+(?:[/?#&]|$)
18 )
19 '''
efb1bb90 20
3166b1f0
S
21 _TESTS = [{
22 'url': 'https://myspace.com/fiveminutestothestage/video/little-big-town/109594919',
23 'md5': '9c1483c106f4a695c47d2911feed50a7',
24 'info_dict': {
25 'id': '109594919',
26 'ext': 'mp4',
27 'title': 'Little Big Town',
28 'description': 'This country quartet was all smiles while playing a sold out show at the Pacific Amphitheatre in Orange County, California.',
29 'uploader': 'Five Minutes to the Stage',
30 'uploader_id': 'fiveminutestothestage',
31 'timestamp': 1414108751,
32 'upload_date': '20141023',
2563bcc8 33 },
3166b1f0 34 }, {
a196a532 35 # songs
3166b1f0
S
36 'url': 'https://myspace.com/killsorrow/music/song/of-weakened-soul...-93388656-103880681',
37 'md5': '1d7ee4604a3da226dd69a123f748b262',
38 'info_dict': {
39 'id': '93388656',
40 'ext': 'm4a',
41 'title': 'Of weakened soul...',
42 'uploader': 'Killsorrow',
43 'uploader_id': 'killsorrow',
2563bcc8 44 },
3166b1f0
S
45 }, {
46 'url': 'https://myspace.com/starset2/music/song/first-light-95799905-106964426',
47 'only_matching': True,
48 }, {
49 'url': 'https://myspace.com/thelargemouthbassband/music/song/02-pure-eyes.mp3-94422330-105113388',
50 'only_matching': True,
51 }]
2563bcc8
JMF
52
53 def _real_extract(self, url):
5ad28e7f 54 mobj = self._match_valid_url(url)
3166b1f0 55 video_id = mobj.group('video_id') or mobj.group('song_id')
f65dba7c 56 is_song = mobj.group('mediatype').startswith('music/song')
2563bcc8 57 webpage = self._download_webpage(url, video_id)
f2b44a25 58 player_url = self._search_regex(
f65dba7c 59 r'videoSwf":"([^"?]*)', webpage, 'player URL', fatal=False)
efb1bb90 60
f65dba7c
RA
61 def formats_from_stream_urls(stream_url, hls_stream_url, http_stream_url, width=None, height=None):
62 formats = []
63 vcodec = 'none' if is_song else None
64 if hls_stream_url:
65 formats.append({
66 'format_id': 'hls',
67 'url': hls_stream_url,
68 'protocol': 'm3u8_native',
69 'ext': 'm4a' if is_song else 'mp4',
70 'vcodec': vcodec,
71 })
72 if stream_url and player_url:
73 rtmp_url, play_path = stream_url.split(';', 1)
74 formats.append({
75 'format_id': 'rtmp',
76 'url': rtmp_url,
77 'play_path': play_path,
78 'player_url': player_url,
79 'protocol': 'rtmp',
80 'ext': 'flv',
81 'width': width,
82 'height': height,
83 'vcodec': vcodec,
84 })
85 if http_stream_url:
86 formats.append({
87 'format_id': 'http',
88 'url': http_stream_url,
89 'width': width,
90 'height': height,
91 'vcodec': vcodec,
92 })
93 return formats
6b820a23 94
f65dba7c 95 if is_song:
efb1bb90 96 # songs don't store any useful info in the 'context' variable
1940fadd 97 song_data = self._search_regex(
add96eb9 98 rf'''<button.*data-song-id=(["\']){video_id}\1.*''',
1940fadd
TF
99 webpage, 'song_data', default=None, group=0)
100 if song_data is None:
954f36f8
JMF
101 # some songs in an album are not playable
102 self.report_warning(
add96eb9 103 f'{video_id}: No downloadable song on this page')
1940fadd 104 return
810fb84d 105
efb1bb90 106 def search_data(name):
b66e6998 107 return self._search_regex(
add96eb9 108 rf'''data-{name}=([\'"])(?P<data>.*?)\1''',
954f36f8 109 song_data, name, default='', group='data')
f65dba7c
RA
110 formats = formats_from_stream_urls(
111 search_data('stream-url'), search_data('hls-stream-url'),
112 search_data('http-stream-url'))
113 if not formats:
3266f0c6
TF
114 vevo_id = search_data('vevo-id')
115 youtube_id = search_data('youtube-id')
116 if vevo_id:
add96eb9 117 self.to_screen(f'Vevo video detected: {vevo_id}')
118 return self.url_result(f'vevo:{vevo_id}', ie='Vevo')
3266f0c6 119 elif youtube_id:
add96eb9 120 self.to_screen(f'Youtube video detected: {youtube_id}')
3266f0c6
TF
121 return self.url_result(youtube_id, ie='Youtube')
122 else:
123 raise ExtractorError(
124 'Found song but don\'t know how to download it')
6b820a23 125 return {
efb1bb90
JMF
126 'id': video_id,
127 'title': self._og_search_title(webpage),
03fd72d9 128 'uploader': search_data('artist-name'),
efb1bb90
JMF
129 'uploader_id': search_data('artist-username'),
130 'thumbnail': self._og_search_thumbnail(webpage),
6b820a23 131 'duration': int_or_none(search_data('duration')),
f65dba7c 132 'formats': formats,
efb1bb90
JMF
133 }
134 else:
6b820a23 135 video = self._parse_json(self._search_regex(
136 r'context = ({.*?});', webpage, 'context'),
137 video_id)['video']
f65dba7c
RA
138 formats = formats_from_stream_urls(
139 video.get('streamUrl'), video.get('hlsStreamUrl'),
140 video.get('mp4StreamUrl'), int_or_none(video.get('width')),
141 int_or_none(video.get('height')))
6b820a23 142 return {
143 'id': video_id,
efb1bb90 144 'title': video['title'],
6b820a23 145 'description': video.get('description'),
146 'thumbnail': video.get('imageUrl'),
147 'uploader': video.get('artistName'),
148 'uploader_id': video.get('artistUsername'),
149 'duration': int_or_none(video.get('duration')),
150 'timestamp': parse_iso8601(video.get('dateAdded')),
151 'formats': formats,
efb1bb90
JMF
152 }
153
95c673a1
TF
154
155class MySpaceAlbumIE(InfoExtractor):
156 IE_NAME = 'MySpace:album'
157 _VALID_URL = r'https?://myspace\.com/([^/]+)/music/album/(?P<title>.*-)(?P<id>\d+)'
158
159 _TESTS = [{
160 'url': 'https://myspace.com/starset2/music/album/transmissions-19455773',
161 'info_dict': {
162 'title': 'Transmissions',
163 'id': '19455773',
164 },
165 'playlist_count': 14,
166 'skip': 'this album is only available in some countries',
167 }, {
168 'url': 'https://myspace.com/killsorrow/music/album/the-demo-18596029',
169 'info_dict': {
170 'title': 'The Demo',
171 'id': '18596029',
172 },
173 'playlist_count': 5,
174 }]
175
176 def _real_extract(self, url):
5ad28e7f 177 mobj = self._match_valid_url(url)
95c673a1
TF
178 playlist_id = mobj.group('id')
179 display_id = mobj.group('title') + playlist_id
180 webpage = self._download_webpage(url, display_id)
181 tracks_paths = re.findall(r'"music:song" content="(.*?)"', webpage)
182 if not tracks_paths:
954f36f8 183 raise ExtractorError(
add96eb9 184 f'{display_id}: No songs found, try using proxy',
954f36f8 185 expected=True)
95c673a1
TF
186 entries = [
187 self.url_result(t_path, ie=MySpaceIE.ie_key())
188 for t_path in tracks_paths]
95c673a1
TF
189 return {
190 '_type': 'playlist',
191 'id': playlist_id,
192 'display_id': display_id,
954f36f8 193 'title': self._og_search_title(webpage),
95c673a1
TF
194 'entries': entries,
195 }