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.

143 lines
5.1 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. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import json
  4. import random
  5. import re
  6. from .common import InfoExtractor
  7. from ..utils import (
  8. compat_str,
  9. )
  10. class EightTracksIE(InfoExtractor):
  11. IE_NAME = '8tracks'
  12. _VALID_URL = r'https?://8tracks\.com/(?P<user>[^/]+)/(?P<id>[^/#]+)(?:#.*)?$'
  13. _TEST = {
  14. "name": "EightTracks",
  15. "url": "http://8tracks.com/ytdl/youtube-dl-test-tracks-a",
  16. "info_dict": {
  17. 'id': '1336550',
  18. 'display_id': 'youtube-dl-test-tracks-a',
  19. "description": "test chars: \"'/\\ä↭",
  20. "title": "youtube-dl test tracks \"'/\\ä↭<>",
  21. },
  22. "playlist": [
  23. {
  24. "md5": "96ce57f24389fc8734ce47f4c1abcc55",
  25. "info_dict": {
  26. "id": "11885610",
  27. "ext": "m4a",
  28. "title": "youtue-dl project<>\"' - youtube-dl test track 1 \"'/\\\u00e4\u21ad",
  29. "uploader_id": "ytdl"
  30. }
  31. },
  32. {
  33. "md5": "4ab26f05c1f7291ea460a3920be8021f",
  34. "info_dict": {
  35. "id": "11885608",
  36. "ext": "m4a",
  37. "title": "youtube-dl project - youtube-dl test track 2 \"'/\\\u00e4\u21ad",
  38. "uploader_id": "ytdl"
  39. }
  40. },
  41. {
  42. "md5": "d30b5b5f74217410f4689605c35d1fd7",
  43. "info_dict": {
  44. "id": "11885679",
  45. "ext": "m4a",
  46. "title": "youtube-dl project as well - youtube-dl test track 3 \"'/\\\u00e4\u21ad",
  47. "uploader_id": "ytdl"
  48. }
  49. },
  50. {
  51. "md5": "4eb0a669317cd725f6bbd336a29f923a",
  52. "info_dict": {
  53. "id": "11885680",
  54. "ext": "m4a",
  55. "title": "youtube-dl project as well - youtube-dl test track 4 \"'/\\\u00e4\u21ad",
  56. "uploader_id": "ytdl"
  57. }
  58. },
  59. {
  60. "md5": "1893e872e263a2705558d1d319ad19e8",
  61. "info_dict": {
  62. "id": "11885682",
  63. "ext": "m4a",
  64. "title": "PH - youtube-dl test track 5 \"'/\\\u00e4\u21ad",
  65. "uploader_id": "ytdl"
  66. }
  67. },
  68. {
  69. "md5": "b673c46f47a216ab1741ae8836af5899",
  70. "info_dict": {
  71. "id": "11885683",
  72. "ext": "m4a",
  73. "title": "PH - youtube-dl test track 6 \"'/\\\u00e4\u21ad",
  74. "uploader_id": "ytdl"
  75. }
  76. },
  77. {
  78. "md5": "1d74534e95df54986da7f5abf7d842b7",
  79. "info_dict": {
  80. "id": "11885684",
  81. "ext": "m4a",
  82. "title": "phihag - youtube-dl test track 7 \"'/\\\u00e4\u21ad",
  83. "uploader_id": "ytdl"
  84. }
  85. },
  86. {
  87. "md5": "f081f47af8f6ae782ed131d38b9cd1c0",
  88. "info_dict": {
  89. "id": "11885685",
  90. "ext": "m4a",
  91. "title": "phihag - youtube-dl test track 8 \"'/\\\u00e4\u21ad",
  92. "uploader_id": "ytdl"
  93. }
  94. }
  95. ]
  96. }
  97. def _real_extract(self, url):
  98. mobj = re.match(self._VALID_URL, url)
  99. playlist_id = mobj.group('id')
  100. webpage = self._download_webpage(url, playlist_id)
  101. json_like = self._search_regex(
  102. r"(?s)PAGE.mix = (.*?);\n", webpage, 'trax information')
  103. data = json.loads(json_like)
  104. session = str(random.randint(0, 1000000000))
  105. mix_id = data['id']
  106. track_count = data['tracks_count']
  107. first_url = 'http://8tracks.com/sets/%s/play?player=sm&mix_id=%s&format=jsonh' % (session, mix_id)
  108. next_url = first_url
  109. entries = []
  110. for i in range(track_count):
  111. api_json = self._download_webpage(
  112. next_url, playlist_id,
  113. note='Downloading song information %d/%d' % (i + 1, track_count),
  114. errnote='Failed to download song information')
  115. api_data = json.loads(api_json)
  116. track_data = api_data['set']['track']
  117. info = {
  118. 'id': compat_str(track_data['id']),
  119. 'url': track_data['track_file_stream_url'],
  120. 'title': track_data['performer'] + u' - ' + track_data['name'],
  121. 'raw_title': track_data['name'],
  122. 'uploader_id': data['user']['login'],
  123. 'ext': 'm4a',
  124. }
  125. entries.append(info)
  126. next_url = 'http://8tracks.com/sets/%s/next?player=sm&mix_id=%s&format=jsonh&track_id=%s' % (
  127. session, mix_id, track_data['id'])
  128. return {
  129. '_type': 'playlist',
  130. 'entries': entries,
  131. 'id': compat_str(mix_id),
  132. 'display_id': playlist_id,
  133. 'title': data.get('name'),
  134. 'description': data.get('description'),
  135. }