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.

119 lines
4.4 KiB

[8tracks] Use track count instead of looking at at_last_track property This fixes the error: $ youtube-dl http://8tracks.com/vladmc/counting-stars [8tracks] counting-stars: Downloading webpage [8tracks] counting-stars: Downloading song information 1/4 [8tracks] counting-stars: Downloading song information 2/4 [8tracks] counting-stars: Downloading song information 3/4 [8tracks] counting-stars: Downloading song information 4/4 [8tracks] counting-stars: Downloading song information 5/4 Traceback (most recent call last): File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main "__main__", fname, loader, pkg_name) File "/usr/lib/python2.7/runpy.py", line 72, in _run_code exec code in run_globals File "/home/phihag/projects/youtube-dl/youtube_dl/__main__.py", line 18, in <module> youtube_dl.main() File "/home/phihag/projects/youtube-dl/youtube_dl/__init__.py", line 761, in main _real_main(argv) File "/home/phihag/projects/youtube-dl/youtube_dl/__init__.py", line 714, in _real_main retcode = ydl.download(all_urls) File "/home/phihag/projects/youtube-dl/youtube_dl/YoutubeDL.py", line 701, in download videos = self.extract_info(url) File "/home/phihag/projects/youtube-dl/youtube_dl/YoutubeDL.py", line 342, in extract_info ie_result = ie.extract(url) File "/home/phihag/projects/youtube-dl/youtube_dl/extractor/common.py", line 121, in extract return self._real_extract(url) File "/home/phihag/projects/youtube-dl/youtube_dl/extractor/eighttracks.py", line 111, in _real_extract 'id': track_data['id'], KeyError: 'id'
11 years ago
  1. import json
  2. import random
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. ExtractorError,
  7. )
  8. class EightTracksIE(InfoExtractor):
  9. IE_NAME = '8tracks'
  10. _VALID_URL = r'https?://8tracks\.com/(?P<user>[^/]+)/(?P<id>[^/#]+)(?:#.*)?$'
  11. _TEST = {
  12. u"name": u"EightTracks",
  13. u"url": u"http://8tracks.com/ytdl/youtube-dl-test-tracks-a",
  14. u"playlist": [
  15. {
  16. u"file": u"11885610.m4a",
  17. u"md5": u"96ce57f24389fc8734ce47f4c1abcc55",
  18. u"info_dict": {
  19. u"title": u"youtue-dl project<>\"' - youtube-dl test track 1 \"'/\\\u00e4\u21ad",
  20. u"uploader_id": u"ytdl"
  21. }
  22. },
  23. {
  24. u"file": u"11885608.m4a",
  25. u"md5": u"4ab26f05c1f7291ea460a3920be8021f",
  26. u"info_dict": {
  27. u"title": u"youtube-dl project - youtube-dl test track 2 \"'/\\\u00e4\u21ad",
  28. u"uploader_id": u"ytdl"
  29. }
  30. },
  31. {
  32. u"file": u"11885679.m4a",
  33. u"md5": u"d30b5b5f74217410f4689605c35d1fd7",
  34. u"info_dict": {
  35. u"title": u"youtube-dl project as well - youtube-dl test track 3 \"'/\\\u00e4\u21ad",
  36. u"uploader_id": u"ytdl"
  37. }
  38. },
  39. {
  40. u"file": u"11885680.m4a",
  41. u"md5": u"4eb0a669317cd725f6bbd336a29f923a",
  42. u"info_dict": {
  43. u"title": u"youtube-dl project as well - youtube-dl test track 4 \"'/\\\u00e4\u21ad",
  44. u"uploader_id": u"ytdl"
  45. }
  46. },
  47. {
  48. u"file": u"11885682.m4a",
  49. u"md5": u"1893e872e263a2705558d1d319ad19e8",
  50. u"info_dict": {
  51. u"title": u"PH - youtube-dl test track 5 \"'/\\\u00e4\u21ad",
  52. u"uploader_id": u"ytdl"
  53. }
  54. },
  55. {
  56. u"file": u"11885683.m4a",
  57. u"md5": u"b673c46f47a216ab1741ae8836af5899",
  58. u"info_dict": {
  59. u"title": u"PH - youtube-dl test track 6 \"'/\\\u00e4\u21ad",
  60. u"uploader_id": u"ytdl"
  61. }
  62. },
  63. {
  64. u"file": u"11885684.m4a",
  65. u"md5": u"1d74534e95df54986da7f5abf7d842b7",
  66. u"info_dict": {
  67. u"title": u"phihag - youtube-dl test track 7 \"'/\\\u00e4\u21ad",
  68. u"uploader_id": u"ytdl"
  69. }
  70. },
  71. {
  72. u"file": u"11885685.m4a",
  73. u"md5": u"f081f47af8f6ae782ed131d38b9cd1c0",
  74. u"info_dict": {
  75. u"title": u"phihag - youtube-dl test track 8 \"'/\\\u00e4\u21ad",
  76. u"uploader_id": u"ytdl"
  77. }
  78. }
  79. ]
  80. }
  81. def _real_extract(self, url):
  82. mobj = re.match(self._VALID_URL, url)
  83. if mobj is None:
  84. raise ExtractorError(u'Invalid URL: %s' % url)
  85. playlist_id = mobj.group('id')
  86. webpage = self._download_webpage(url, playlist_id)
  87. json_like = self._search_regex(r"PAGE.mix = (.*?);\n", webpage, u'trax information', flags=re.DOTALL)
  88. data = json.loads(json_like)
  89. session = str(random.randint(0, 1000000000))
  90. mix_id = data['id']
  91. track_count = data['tracks_count']
  92. first_url = 'http://8tracks.com/sets/%s/play?player=sm&mix_id=%s&format=jsonh' % (session, mix_id)
  93. next_url = first_url
  94. res = []
  95. for i in range(track_count):
  96. api_json = self._download_webpage(next_url, playlist_id,
  97. note=u'Downloading song information %s/%s' % (str(i+1), track_count),
  98. errnote=u'Failed to download song information')
  99. api_data = json.loads(api_json)
  100. track_data = api_data[u'set']['track']
  101. info = {
  102. 'id': track_data['id'],
  103. 'url': track_data['track_file_stream_url'],
  104. 'title': track_data['performer'] + u' - ' + track_data['name'],
  105. 'raw_title': track_data['name'],
  106. 'uploader_id': data['user']['login'],
  107. 'ext': 'm4a',
  108. }
  109. res.append(info)
  110. next_url = 'http://8tracks.com/sets/%s/next?player=sm&mix_id=%s&format=jsonh&track_id=%s' % (session, mix_id, track_data['id'])
  111. return res