myspace.py 7.6 KB

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