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