logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

myspace.py (8412B)


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