You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

180 lines
6.6 KiB

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