myspace.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. from __future__ import unicode_literals
  2. import re
  3. import json
  4. from .common import InfoExtractor
  5. from ..compat import (
  6. compat_str,
  7. )
  8. class MySpaceIE(InfoExtractor):
  9. _VALID_URL = r'https?://myspace\.com/([^/]+)/(?P<mediatype>video/[^/]+/|music/song/.*?)(?P<id>\d+)'
  10. _TESTS = [
  11. {
  12. 'url': 'https://myspace.com/coldplay/video/viva-la-vida/100008689',
  13. 'info_dict': {
  14. 'id': '100008689',
  15. 'ext': 'flv',
  16. 'title': 'Viva La Vida',
  17. 'description': 'The official Viva La Vida video, directed by Hype Williams',
  18. 'uploader': 'Coldplay',
  19. 'uploader_id': 'coldplay',
  20. },
  21. 'params': {
  22. # rtmp download
  23. 'skip_download': True,
  24. },
  25. },
  26. # song
  27. {
  28. 'url': 'https://myspace.com/spiderbags/music/song/darkness-in-my-heart-39008454-27041242',
  29. 'info_dict': {
  30. 'id': '39008454',
  31. 'ext': 'flv',
  32. 'title': 'Darkness In My Heart',
  33. 'uploader_id': 'spiderbags',
  34. },
  35. 'params': {
  36. # rtmp download
  37. 'skip_download': True,
  38. },
  39. },
  40. ]
  41. def _real_extract(self, url):
  42. mobj = re.match(self._VALID_URL, url)
  43. video_id = mobj.group('id')
  44. webpage = self._download_webpage(url, video_id)
  45. player_url = self._search_regex(
  46. r'playerSwf":"([^"?]*)', webpage, 'player URL')
  47. if mobj.group('mediatype').startswith('music/song'):
  48. # songs don't store any useful info in the 'context' variable
  49. def search_data(name):
  50. return self._search_regex(
  51. r'data-%s="(.*?)"' % name, webpage, name)
  52. streamUrl = search_data('stream-url')
  53. info = {
  54. 'id': video_id,
  55. 'title': self._og_search_title(webpage),
  56. 'uploader': search_data('artist-name'),
  57. 'uploader_id': search_data('artist-username'),
  58. 'playlist': search_data('album-title'),
  59. 'thumbnail': self._og_search_thumbnail(webpage),
  60. }
  61. else:
  62. context = json.loads(self._search_regex(
  63. r'context = ({.*?});', webpage, 'context'))
  64. video = context['video']
  65. streamUrl = video['streamUrl']
  66. info = {
  67. 'id': compat_str(video['mediaId']),
  68. 'title': video['title'],
  69. 'description': video['description'],
  70. 'thumbnail': video['imageUrl'],
  71. 'uploader': video['artistName'],
  72. 'uploader_id': video['artistUsername'],
  73. }
  74. rtmp_url, play_path = streamUrl.split(';', 1)
  75. info.update({
  76. 'url': rtmp_url,
  77. 'play_path': play_path,
  78. 'player_url': player_url,
  79. 'ext': 'flv',
  80. })
  81. return info