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.

214 lines
8.3 KiB

10 years ago
10 years ago
10 years ago
10 years ago
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. ExtractorError,
  7. int_or_none,
  8. parse_iso8601,
  9. )
  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. 'md5': '9c1483c106f4a695c47d2911feed50a7',
  16. 'info_dict': {
  17. 'id': '109594919',
  18. 'ext': 'mp4',
  19. 'title': 'Little Big Town',
  20. 'description': 'This country quartet was all smiles while playing a sold out show at the Pacific Amphitheatre in Orange County, California.',
  21. 'uploader': 'Five Minutes to the Stage',
  22. 'uploader_id': 'fiveminutestothestage',
  23. 'timestamp': 1414108751,
  24. 'upload_date': '20141023',
  25. },
  26. },
  27. # songs
  28. {
  29. 'url': 'https://myspace.com/killsorrow/music/song/of-weakened-soul...-93388656-103880681',
  30. 'md5': '1d7ee4604a3da226dd69a123f748b262',
  31. 'info_dict': {
  32. 'id': '93388656',
  33. 'ext': 'm4a',
  34. 'title': 'Of weakened soul...',
  35. 'uploader': 'Killsorrow',
  36. 'uploader_id': 'killsorrow',
  37. },
  38. }, {
  39. 'add_ie': ['Youtube'],
  40. 'url': 'https://myspace.com/threedaysgrace/music/song/animal-i-have-become-28400208-28218041',
  41. 'info_dict': {
  42. 'id': 'xqds0B_meys',
  43. 'ext': 'webm',
  44. 'title': 'Three Days Grace - Animal I Have Become',
  45. 'description': 'md5:8bd86b3693e72a077cf863a8530c54bb',
  46. 'uploader': 'ThreeDaysGraceVEVO',
  47. 'uploader_id': 'ThreeDaysGraceVEVO',
  48. 'upload_date': '20091002',
  49. },
  50. }, {
  51. 'add_ie': ['Youtube'],
  52. 'url': 'https://myspace.com/starset2/music/song/first-light-95799905-106964426',
  53. 'info_dict': {
  54. 'id': 'ypWvQgnJrSU',
  55. 'ext': 'mp4',
  56. 'title': 'Starset - First Light',
  57. 'description': 'md5:2d5db6c9d11d527683bcda818d332414',
  58. 'uploader': 'Yumi K',
  59. 'uploader_id': 'SorenPromotions',
  60. 'upload_date': '20140725',
  61. }
  62. },
  63. ]
  64. def _real_extract(self, url):
  65. mobj = re.match(self._VALID_URL, url)
  66. video_id = mobj.group('id')
  67. is_song = mobj.group('mediatype').startswith('music/song')
  68. webpage = self._download_webpage(url, video_id)
  69. player_url = self._search_regex(
  70. r'videoSwf":"([^"?]*)', webpage, 'player URL', fatal=False)
  71. def formats_from_stream_urls(stream_url, hls_stream_url, http_stream_url, width=None, height=None):
  72. formats = []
  73. vcodec = 'none' if is_song else None
  74. if hls_stream_url:
  75. formats.append({
  76. 'format_id': 'hls',
  77. 'url': hls_stream_url,
  78. 'protocol': 'm3u8_native',
  79. 'ext': 'm4a' if is_song else 'mp4',
  80. 'vcodec': vcodec,
  81. })
  82. if stream_url and player_url:
  83. rtmp_url, play_path = stream_url.split(';', 1)
  84. formats.append({
  85. 'format_id': 'rtmp',
  86. 'url': rtmp_url,
  87. 'play_path': play_path,
  88. 'player_url': player_url,
  89. 'protocol': 'rtmp',
  90. 'ext': 'flv',
  91. 'width': width,
  92. 'height': height,
  93. 'vcodec': vcodec,
  94. })
  95. if http_stream_url:
  96. formats.append({
  97. 'format_id': 'http',
  98. 'url': http_stream_url,
  99. 'width': width,
  100. 'height': height,
  101. 'vcodec': vcodec,
  102. })
  103. return formats
  104. if is_song:
  105. # songs don't store any useful info in the 'context' variable
  106. song_data = self._search_regex(
  107. r'''<button.*data-song-id=(["\'])%s\1.*''' % video_id,
  108. webpage, 'song_data', default=None, group=0)
  109. if song_data is None:
  110. # some songs in an album are not playable
  111. self.report_warning(
  112. '%s: No downloadable song on this page' % video_id)
  113. return
  114. def search_data(name):
  115. return self._search_regex(
  116. r'''data-%s=([\'"])(?P<data>.*?)\1''' % name,
  117. song_data, name, default='', group='data')
  118. formats = formats_from_stream_urls(
  119. search_data('stream-url'), search_data('hls-stream-url'),
  120. search_data('http-stream-url'))
  121. if not formats:
  122. vevo_id = search_data('vevo-id')
  123. youtube_id = search_data('youtube-id')
  124. if vevo_id:
  125. self.to_screen('Vevo video detected: %s' % vevo_id)
  126. return self.url_result('vevo:%s' % vevo_id, ie='Vevo')
  127. elif youtube_id:
  128. self.to_screen('Youtube video detected: %s' % youtube_id)
  129. return self.url_result(youtube_id, ie='Youtube')
  130. else:
  131. raise ExtractorError(
  132. 'Found song but don\'t know how to download it')
  133. self._sort_formats(formats)
  134. return {
  135. 'id': video_id,
  136. 'title': self._og_search_title(webpage),
  137. 'uploader': search_data('artist-name'),
  138. 'uploader_id': search_data('artist-username'),
  139. 'thumbnail': self._og_search_thumbnail(webpage),
  140. 'duration': int_or_none(search_data('duration')),
  141. 'formats': formats,
  142. }
  143. else:
  144. video = self._parse_json(self._search_regex(
  145. r'context = ({.*?});', webpage, 'context'),
  146. video_id)['video']
  147. formats = formats_from_stream_urls(
  148. video.get('streamUrl'), video.get('hlsStreamUrl'),
  149. video.get('mp4StreamUrl'), int_or_none(video.get('width')),
  150. int_or_none(video.get('height')))
  151. self._sort_formats(formats)
  152. return {
  153. 'id': video_id,
  154. 'title': video['title'],
  155. 'description': video.get('description'),
  156. 'thumbnail': video.get('imageUrl'),
  157. 'uploader': video.get('artistName'),
  158. 'uploader_id': video.get('artistUsername'),
  159. 'duration': int_or_none(video.get('duration')),
  160. 'timestamp': parse_iso8601(video.get('dateAdded')),
  161. 'formats': formats,
  162. }
  163. class MySpaceAlbumIE(InfoExtractor):
  164. IE_NAME = 'MySpace:album'
  165. _VALID_URL = r'https?://myspace\.com/([^/]+)/music/album/(?P<title>.*-)(?P<id>\d+)'
  166. _TESTS = [{
  167. 'url': 'https://myspace.com/starset2/music/album/transmissions-19455773',
  168. 'info_dict': {
  169. 'title': 'Transmissions',
  170. 'id': '19455773',
  171. },
  172. 'playlist_count': 14,
  173. 'skip': 'this album is only available in some countries',
  174. }, {
  175. 'url': 'https://myspace.com/killsorrow/music/album/the-demo-18596029',
  176. 'info_dict': {
  177. 'title': 'The Demo',
  178. 'id': '18596029',
  179. },
  180. 'playlist_count': 5,
  181. }]
  182. def _real_extract(self, url):
  183. mobj = re.match(self._VALID_URL, url)
  184. playlist_id = mobj.group('id')
  185. display_id = mobj.group('title') + playlist_id
  186. webpage = self._download_webpage(url, display_id)
  187. tracks_paths = re.findall(r'"music:song" content="(.*?)"', webpage)
  188. if not tracks_paths:
  189. raise ExtractorError(
  190. '%s: No songs found, try using proxy' % display_id,
  191. expected=True)
  192. entries = [
  193. self.url_result(t_path, ie=MySpaceIE.ie_key())
  194. for t_path in tracks_paths]
  195. return {
  196. '_type': 'playlist',
  197. 'id': playlist_id,
  198. 'display_id': display_id,
  199. 'title': self._og_search_title(webpage),
  200. 'entries': entries,
  201. }