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.

84 lines
2.7 KiB

  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. if mobj.group('mediatype').startswith('music/song'):
  46. # songs don't store any useful info in the 'context' variable
  47. def search_data(name):
  48. return self._search_regex(
  49. r'data-%s="(.*?)"' % name, webpage, name)
  50. streamUrl = search_data('stream-url')
  51. info = {
  52. 'id': video_id,
  53. 'title': self._og_search_title(webpage),
  54. 'uploader_id': search_data('artist-username'),
  55. 'thumbnail': self._og_search_thumbnail(webpage),
  56. }
  57. else:
  58. context = json.loads(self._search_regex(
  59. r'context = ({.*?});', webpage, 'context'))
  60. video = context['video']
  61. streamUrl = video['streamUrl']
  62. info = {
  63. 'id': compat_str(video['mediaId']),
  64. 'title': video['title'],
  65. 'description': video['description'],
  66. 'thumbnail': video['imageUrl'],
  67. 'uploader': video['artistName'],
  68. 'uploader_id': video['artistUsername'],
  69. }
  70. rtmp_url, play_path = streamUrl.split(';', 1)
  71. info.update({
  72. 'url': rtmp_url,
  73. 'play_path': play_path,
  74. 'ext': 'flv',
  75. })
  76. return info