]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/myspace.py
c16939f5437cf55b6d3e51e9d51ab45d1d12392f
[youtubedl] / 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 ..utils 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
52 if mobj.group('mediatype').startswith('music/song'):
53 # songs don't store any useful info in the 'context' variable
54 def search_data(name):
55 return self._search_regex(r'data-%s="(.*?)"' % name, webpage,
56 name)
57 streamUrl = search_data('stream-url')
58 info = {
59 'id': video_id,
60 'title': self._og_search_title(webpage),
61 'uploader_id': search_data('artist-username'),
62 'thumbnail': self._og_search_thumbnail(webpage),
63 }
64 else:
65 context = json.loads(self._search_regex(r'context = ({.*?});', webpage,
66 u'context'))
67 video = context['video']
68 streamUrl = video['streamUrl']
69 info = {
70 'id': compat_str(video['mediaId']),
71 'title': video['title'],
72 'description': video['description'],
73 'thumbnail': video['imageUrl'],
74 'uploader': video['artistName'],
75 'uploader_id': video['artistUsername'],
76 }
77
78 rtmp_url, play_path = streamUrl.split(';', 1)
79 info.update({
80 'url': rtmp_url,
81 'play_path': play_path,
82 'ext': 'flv',
83 })
84 return info