myspace.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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_id': search_data('artist-username'),
  57. 'thumbnail': self._og_search_thumbnail(webpage),
  58. }
  59. else:
  60. context = json.loads(self._search_regex(
  61. r'context = ({.*?});', webpage, 'context'))
  62. video = context['video']
  63. streamUrl = video['streamUrl']
  64. info = {
  65. 'id': compat_str(video['mediaId']),
  66. 'title': video['title'],
  67. 'description': video['description'],
  68. 'thumbnail': video['imageUrl'],
  69. 'uploader': video['artistName'],
  70. 'uploader_id': video['artistUsername'],
  71. }
  72. rtmp_url, play_path = streamUrl.split(';', 1)
  73. info.update({
  74. 'url': rtmp_url,
  75. 'play_path': play_path,
  76. 'player_url': player_url,
  77. 'ext': 'flv',
  78. })
  79. return info