]> jfr.im git - yt-dlp.git/blob - youtube_dl/extractor/myspace.py
[myspace] Redirect to other extractors
[yt-dlp.git] / youtube_dl / extractor / myspace.py
1 from __future__ import unicode_literals
2
3 import re
4 import json
5
6 from .common import InfoExtractor
7 from ..compat import (
8 compat_str,
9 )
10 from ..utils import ExtractorError
11
12
13 class MySpaceIE(InfoExtractor):
14 _VALID_URL = r'https?://myspace\.com/([^/]+)/(?P<mediatype>video/[^/]+/|music/song/.*?)(?P<id>\d+)'
15
16 _TESTS = [
17 {
18 'url': 'https://myspace.com/coldplay/video/viva-la-vida/100008689',
19 'info_dict': {
20 'id': '100008689',
21 'ext': 'flv',
22 'title': 'Viva La Vida',
23 'description': 'The official Viva La Vida video, directed by Hype Williams',
24 'uploader': 'Coldplay',
25 'uploader_id': 'coldplay',
26 },
27 'params': {
28 # rtmp download
29 'skip_download': True,
30 },
31 },
32 # song
33 {
34 'url': 'https://myspace.com/spiderbags/music/song/darkness-in-my-heart-39008454-27041242',
35 'info_dict': {
36 'id': '39008454',
37 'ext': 'flv',
38 'title': 'Darkness In My Heart',
39 'uploader_id': 'spiderbags',
40 },
41 'params': {
42 # rtmp download
43 'skip_download': True,
44 },
45 },
46 ]
47
48 def _real_extract(self, url):
49 mobj = re.match(self._VALID_URL, url)
50 video_id = mobj.group('id')
51 webpage = self._download_webpage(url, video_id)
52 player_url = self._search_regex(
53 r'playerSwf":"([^"?]*)', webpage, 'player URL')
54
55 if mobj.group('mediatype').startswith('music/song'):
56 # songs don't store any useful info in the 'context' variable
57 song_data = self._search_regex(
58 r'''<button.*data-song-id=(["\'])%s\1.*''' % video_id,
59 webpage, 'song_data', default=None, group=0)
60 if song_data is None:
61 self.to_screen(
62 '%s: No downloadable song on this page' % video_id)
63 return
64 def search_data(name):
65 return self._search_regex(
66 r'''data-%s=([\'"])(.*?)\1''' % name,
67 song_data, name, default='', group=2)
68 streamUrl = search_data('stream-url')
69 if not streamUrl:
70 vevo_id = search_data('vevo-id')
71 youtube_id = search_data('youtube-id')
72 if vevo_id:
73 self.to_screen('Vevo video detected: %s' % vevo_id)
74 return self.url_result('vevo:%s' % vevo_id, ie='Vevo')
75 elif youtube_id:
76 self.to_screen('Youtube video detected: %s' % youtube_id)
77 return self.url_result(youtube_id, ie='Youtube')
78 else:
79 raise ExtractorError(
80 'Found song but don\'t know how to download it')
81 info = {
82 'id': video_id,
83 'title': self._og_search_title(webpage),
84 'uploader': search_data('artist-name'),
85 'uploader_id': search_data('artist-username'),
86 'playlist': search_data('album-title'),
87 'thumbnail': self._og_search_thumbnail(webpage),
88 }
89 else:
90 context = json.loads(self._search_regex(
91 r'context = ({.*?});', webpage, 'context'))
92 video = context['video']
93 streamUrl = video['streamUrl']
94 info = {
95 'id': compat_str(video['mediaId']),
96 'title': video['title'],
97 'description': video['description'],
98 'thumbnail': video['imageUrl'],
99 'uploader': video['artistName'],
100 'uploader_id': video['artistUsername'],
101 }
102
103 rtmp_url, play_path = streamUrl.split(';', 1)
104 info.update({
105 'url': rtmp_url,
106 'play_path': play_path,
107 'player_url': player_url,
108 'ext': 'flv',
109 })
110 return info