]> git.bitcoin.ninja Git - youtube-dl/blob - youtube_dl/extractor/myspace.py
1a118a37f7cba821d378671a9ab035c00567cd64
[youtube-dl] / 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
11
12 class MySpaceIE(InfoExtractor):
13     _VALID_URL = r'https?://myspace\.com/([^/]+)/(?P<mediatype>video/[^/]+/|music/song/.*?)(?P<id>\d+)'
14
15     _TESTS = [
16         {
17             'url': 'https://myspace.com/coldplay/video/viva-la-vida/100008689',
18             'info_dict': {
19                 'id': '100008689',
20                 'ext': 'flv',
21                 'title': 'Viva La Vida',
22                 'description': 'The official Viva La Vida video, directed by Hype Williams',
23                 'uploader': 'Coldplay',
24                 'uploader_id': 'coldplay',
25             },
26             'params': {
27                 # rtmp download
28                 'skip_download': True,
29             },
30         },
31         # song
32         {
33             'url': 'https://myspace.com/spiderbags/music/song/darkness-in-my-heart-39008454-27041242',
34             'info_dict': {
35                 'id': '39008454',
36                 'ext': 'flv',
37                 'title': 'Darkness In My Heart',
38                 'uploader_id': 'spiderbags',
39             },
40             'params': {
41                 # rtmp download
42                 'skip_download': True,
43             },
44         },
45     ]
46
47     def _real_extract(self, url):
48         mobj = re.match(self._VALID_URL, url)
49         video_id = mobj.group('id')
50         webpage = self._download_webpage(url, video_id)
51         player_url = self._search_regex(
52             r'playerSwf":"([^"?]*)', webpage, 'player URL')
53
54         if mobj.group('mediatype').startswith('music/song'):
55             # songs don't store any useful info in the 'context' variable
56             def search_data(name):
57                 return self._search_regex(
58                     r'data-%s="(.*?)"' % name, webpage, name)
59             streamUrl = search_data('stream-url')
60             info = {
61                 'id': video_id,
62                 'title': self._og_search_title(webpage),
63                 'uploader': search_data('artist-name'),
64                 'uploader_id': search_data('artist-username'),
65                 'playlist': search_data('album-title'),
66                 'thumbnail': self._og_search_thumbnail(webpage),
67             }
68         else:
69             context = json.loads(self._search_regex(
70                 r'context = ({.*?});', webpage, 'context'))
71             video = context['video']
72             streamUrl = video['streamUrl']
73             info = {
74                 'id': compat_str(video['mediaId']),
75                 'title': video['title'],
76                 'description': video['description'],
77                 'thumbnail': video['imageUrl'],
78                 'uploader': video['artistName'],
79                 'uploader_id': video['artistUsername'],
80             }
81
82         rtmp_url, play_path = streamUrl.split(';', 1)
83         info.update({
84             'url': rtmp_url,
85             'play_path': play_path,
86             'player_url': player_url,
87             'ext': 'flv',
88         })
89         return info