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.

79 lines
2.8 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..compat import (
  5. compat_urllib_request,
  6. )
  7. from ..utils import (
  8. ExtractorError,
  9. )
  10. class EveryonesMixtapeIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:www\.)?everyonesmixtape\.com/#/mix/(?P<id>[0-9a-zA-Z]+)(?:/(?P<songnr>[0-9]))?$'
  12. _TESTS = [{
  13. 'url': 'http://everyonesmixtape.com/#/mix/m7m0jJAbMQi/5',
  14. "info_dict": {
  15. 'id': '5bfseWNmlds',
  16. 'ext': 'mp4',
  17. "title": "Passion Pit - \"Sleepyhead\" (Official Music Video)",
  18. "uploader": "FKR.TV",
  19. "uploader_id": "frenchkissrecords",
  20. "description": "Music video for \"Sleepyhead\" from Passion Pit's debut EP Chunk Of Change.\nBuy on iTunes: https://itunes.apple.com/us/album/chunk-of-change-ep/id300087641\n\nDirected by The Wilderness.\n\nhttp://www.passionpitmusic.com\nhttp://www.frenchkissrecords.com",
  21. "upload_date": "20081015"
  22. },
  23. 'params': {
  24. 'skip_download': True, # This is simply YouTube
  25. }
  26. }, {
  27. 'url': 'http://everyonesmixtape.com/#/mix/m7m0jJAbMQi',
  28. 'info_dict': {
  29. 'id': 'm7m0jJAbMQi',
  30. 'title': 'Driving',
  31. },
  32. 'playlist_count': 24
  33. }]
  34. def _real_extract(self, url):
  35. mobj = re.match(self._VALID_URL, url)
  36. playlist_id = mobj.group('id')
  37. pllist_url = 'http://everyonesmixtape.com/mixtape.php?a=getMixes&u=-1&linked=%s&explore=' % playlist_id
  38. pllist_req = compat_urllib_request.Request(pllist_url)
  39. pllist_req.add_header('X-Requested-With', 'XMLHttpRequest')
  40. playlist_list = self._download_json(
  41. pllist_req, playlist_id, note='Downloading playlist metadata')
  42. try:
  43. playlist_no = next(playlist['id']
  44. for playlist in playlist_list
  45. if playlist['code'] == playlist_id)
  46. except StopIteration:
  47. raise ExtractorError('Playlist id not found')
  48. pl_url = 'http://everyonesmixtape.com/mixtape.php?a=getMix&id=%s&userId=null&code=' % playlist_no
  49. pl_req = compat_urllib_request.Request(pl_url)
  50. pl_req.add_header('X-Requested-With', 'XMLHttpRequest')
  51. playlist = self._download_json(
  52. pl_req, playlist_id, note='Downloading playlist info')
  53. entries = [{
  54. '_type': 'url',
  55. 'url': t['url'],
  56. 'title': t['title'],
  57. } for t in playlist['tracks']]
  58. if mobj.group('songnr'):
  59. songnr = int(mobj.group('songnr')) - 1
  60. return entries[songnr]
  61. playlist_title = playlist['mixData']['name']
  62. return {
  63. '_type': 'playlist',
  64. 'id': playlist_id,
  65. 'title': playlist_title,
  66. 'entries': entries,
  67. }