]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/myspace.py
Merge remote-tracking branch 'lenaten/8tracks'
[yt-dlp.git] / youtube_dl / extractor / myspace.py
CommitLineData
19e92770 1# encoding: utf-8
efb1bb90
JMF
2from __future__ import unicode_literals
3
2563bcc8
JMF
4import re
5import json
6
7from .common import InfoExtractor
b66e6998 8from ..compat import (
2563bcc8
JMF
9 compat_str,
10)
3266f0c6 11from ..utils import ExtractorError
2563bcc8
JMF
12
13
14class 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',
efb1bb90
JMF
27 },
28 'params': {
29 # rtmp download
30 'skip_download': True,
31 },
2563bcc8 32 },
a196a532 33 # songs
efb1bb90 34 {
a196a532 35 'url': 'https://myspace.com/killsorrow/music/song/of-weakened-soul...-93388656-103880681',
efb1bb90 36 'info_dict': {
a196a532 37 'id': '93388656',
efb1bb90 38 'ext': 'flv',
a196a532
TF
39 'title': 'Of weakened soul...',
40 'uploader': 'Killsorrow',
41 'uploader_id': 'killsorrow',
efb1bb90
JMF
42 },
43 'params': {
44 # rtmp download
45 'skip_download': True,
46 },
a196a532
TF
47 }, {
48 'add_ie': ['Vevo'],
49 'url': 'https://myspace.com/threedaysgrace/music/song/animal-i-have-become-28400208-28218041',
50 'info_dict': {
19e92770
JMF
51 'id': 'USZM20600099',
52 'ext': 'mp4',
53 'title': 'Animal I Have Become',
54 'uploader': 'Three Days Grace',
a196a532 55 'timestamp': int,
19e92770 56 'upload_date': '20060502',
a196a532
TF
57 },
58 'skip': 'VEVO is only available in some countries',
59 }, {
60 'add_ie': ['Youtube'],
61 'url': 'https://myspace.com/starset2/music/song/first-light-95799905-106964426',
62 'info_dict': {
63 'id': 'ypWvQgnJrSU',
19e92770 64 'ext': 'mp4',
a196a532 65 'title': 'Starset - First Light',
19e92770 66 'description': 'md5:2d5db6c9d11d527683bcda818d332414',
a196a532
TF
67 'uploader': 'Jacob Soren',
68 'uploader_id': 'SorenPromotions',
69 'upload_date': '20140725',
70 }
2563bcc8 71 },
efb1bb90 72 ]
2563bcc8
JMF
73
74 def _real_extract(self, url):
75 mobj = re.match(self._VALID_URL, url)
76 video_id = mobj.group('id')
77 webpage = self._download_webpage(url, video_id)
f2b44a25
TF
78 player_url = self._search_regex(
79 r'playerSwf":"([^"?]*)', webpage, 'player URL')
efb1bb90 80
5016f3ea 81 if mobj.group('mediatype').startswith('music/song'):
efb1bb90 82 # songs don't store any useful info in the 'context' variable
1940fadd
TF
83 song_data = self._search_regex(
84 r'''<button.*data-song-id=(["\'])%s\1.*''' % video_id,
85 webpage, 'song_data', default=None, group=0)
86 if song_data is None:
954f36f8
JMF
87 # some songs in an album are not playable
88 self.report_warning(
1940fadd
TF
89 '%s: No downloadable song on this page' % video_id)
90 return
810fb84d 91
efb1bb90 92 def search_data(name):
b66e6998 93 return self._search_regex(
954f36f8
JMF
94 r'''data-%s=([\'"])(?P<data>.*?)\1''' % name,
95 song_data, name, default='', group='data')
efb1bb90 96 streamUrl = search_data('stream-url')
3266f0c6
TF
97 if not streamUrl:
98 vevo_id = search_data('vevo-id')
99 youtube_id = search_data('youtube-id')
100 if vevo_id:
101 self.to_screen('Vevo video detected: %s' % vevo_id)
102 return self.url_result('vevo:%s' % vevo_id, ie='Vevo')
103 elif youtube_id:
104 self.to_screen('Youtube video detected: %s' % youtube_id)
105 return self.url_result(youtube_id, ie='Youtube')
106 else:
107 raise ExtractorError(
108 'Found song but don\'t know how to download it')
efb1bb90
JMF
109 info = {
110 'id': video_id,
111 'title': self._og_search_title(webpage),
03fd72d9 112 'uploader': search_data('artist-name'),
efb1bb90
JMF
113 'uploader_id': search_data('artist-username'),
114 'thumbnail': self._og_search_thumbnail(webpage),
115 }
116 else:
b66e6998
PH
117 context = json.loads(self._search_regex(
118 r'context = ({.*?});', webpage, 'context'))
efb1bb90
JMF
119 video = context['video']
120 streamUrl = video['streamUrl']
121 info = {
122 'id': compat_str(video['mediaId']),
123 'title': video['title'],
124 'description': video['description'],
125 'thumbnail': video['imageUrl'],
126 'uploader': video['artistName'],
127 'uploader_id': video['artistUsername'],
128 }
129
130 rtmp_url, play_path = streamUrl.split(';', 1)
131 info.update({
2563bcc8
JMF
132 'url': rtmp_url,
133 'play_path': play_path,
f2b44a25 134 'player_url': player_url,
2563bcc8 135 'ext': 'flv',
efb1bb90
JMF
136 })
137 return info
95c673a1
TF
138
139
140class MySpaceAlbumIE(InfoExtractor):
141 IE_NAME = 'MySpace:album'
142 _VALID_URL = r'https?://myspace\.com/([^/]+)/music/album/(?P<title>.*-)(?P<id>\d+)'
143
144 _TESTS = [{
145 'url': 'https://myspace.com/starset2/music/album/transmissions-19455773',
146 'info_dict': {
147 'title': 'Transmissions',
148 'id': '19455773',
149 },
150 'playlist_count': 14,
151 'skip': 'this album is only available in some countries',
152 }, {
153 'url': 'https://myspace.com/killsorrow/music/album/the-demo-18596029',
154 'info_dict': {
155 'title': 'The Demo',
156 'id': '18596029',
157 },
158 'playlist_count': 5,
159 }]
160
161 def _real_extract(self, url):
162 mobj = re.match(self._VALID_URL, url)
163 playlist_id = mobj.group('id')
164 display_id = mobj.group('title') + playlist_id
165 webpage = self._download_webpage(url, display_id)
166 tracks_paths = re.findall(r'"music:song" content="(.*?)"', webpage)
167 if not tracks_paths:
954f36f8
JMF
168 raise ExtractorError(
169 '%s: No songs found, try using proxy' % display_id,
170 expected=True)
95c673a1
TF
171 entries = [
172 self.url_result(t_path, ie=MySpaceIE.ie_key())
173 for t_path in tracks_paths]
95c673a1
TF
174 return {
175 '_type': 'playlist',
176 'id': playlist_id,
177 'display_id': display_id,
954f36f8 178 'title': self._og_search_title(webpage),
95c673a1
TF
179 'entries': entries,
180 }