2013-06-23 14:15:50 -06:00
|
|
|
import json
|
|
|
|
import random
|
|
|
|
|
|
|
|
from .common import InfoExtractor
|
2015-01-09 21:51:07 -07:00
|
|
|
from ..utils import (
|
2014-10-14 21:46:47 -06:00
|
|
|
ExtractorError,
|
2013-06-23 14:15:50 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class EightTracksIE(InfoExtractor):
|
|
|
|
IE_NAME = '8tracks'
|
2013-12-04 06:34:47 -07:00
|
|
|
_VALID_URL = r'https?://8tracks\.com/(?P<user>[^/]+)/(?P<id>[^/#]+)(?:#.*)?$'
|
2013-06-27 12:22:00 -06:00
|
|
|
_TEST = {
|
2016-02-14 02:37:17 -07:00
|
|
|
'name': 'EightTracks',
|
2021-02-24 11:45:56 -07:00
|
|
|
'url': 'http://8tracks.com/ytdl/youtube-dl-test-tracks-a',
|
2016-02-14 02:37:17 -07:00
|
|
|
'info_dict': {
|
2014-08-26 03:31:23 -06:00
|
|
|
'id': '1336550',
|
2021-02-24 11:45:56 -07:00
|
|
|
'display_id': 'youtube-dl-test-tracks-a',
|
2016-02-14 02:37:17 -07:00
|
|
|
'description': "test chars: \"'/\\ä↭",
|
2021-02-24 11:45:56 -07:00
|
|
|
'title': "youtube-dl test tracks \"'/\\ä↭<>",
|
2014-08-26 03:31:23 -06:00
|
|
|
},
|
2016-02-14 02:37:17 -07:00
|
|
|
'playlist': [
|
2013-06-27 12:22:00 -06:00
|
|
|
{
|
2016-02-14 02:37:17 -07:00
|
|
|
'md5': '96ce57f24389fc8734ce47f4c1abcc55',
|
|
|
|
'info_dict': {
|
|
|
|
'id': '11885610',
|
|
|
|
'ext': 'm4a',
|
2021-02-24 11:45:56 -07:00
|
|
|
'title': "youtue-dl project<>\"' - youtube-dl test track 1 \"'/\\\u00e4\u21ad",
|
2024-06-11 17:09:58 -06:00
|
|
|
'uploader_id': 'ytdl',
|
|
|
|
},
|
2013-06-27 12:22:00 -06:00
|
|
|
},
|
|
|
|
{
|
2016-02-14 02:37:17 -07:00
|
|
|
'md5': '4ab26f05c1f7291ea460a3920be8021f',
|
|
|
|
'info_dict': {
|
|
|
|
'id': '11885608',
|
|
|
|
'ext': 'm4a',
|
2021-02-24 11:45:56 -07:00
|
|
|
'title': "youtube-dl project - youtube-dl test track 2 \"'/\\\u00e4\u21ad",
|
2024-06-11 17:09:58 -06:00
|
|
|
'uploader_id': 'ytdl',
|
|
|
|
},
|
2013-06-27 12:22:00 -06:00
|
|
|
},
|
|
|
|
{
|
2016-02-14 02:37:17 -07:00
|
|
|
'md5': 'd30b5b5f74217410f4689605c35d1fd7',
|
|
|
|
'info_dict': {
|
|
|
|
'id': '11885679',
|
|
|
|
'ext': 'm4a',
|
2021-02-24 11:45:56 -07:00
|
|
|
'title': "youtube-dl project as well - youtube-dl test track 3 \"'/\\\u00e4\u21ad",
|
2024-06-11 17:09:58 -06:00
|
|
|
'uploader_id': 'ytdl',
|
|
|
|
},
|
2013-06-27 12:22:00 -06:00
|
|
|
},
|
|
|
|
{
|
2016-02-14 02:37:17 -07:00
|
|
|
'md5': '4eb0a669317cd725f6bbd336a29f923a',
|
|
|
|
'info_dict': {
|
|
|
|
'id': '11885680',
|
|
|
|
'ext': 'm4a',
|
2021-02-24 11:45:56 -07:00
|
|
|
'title': "youtube-dl project as well - youtube-dl test track 4 \"'/\\\u00e4\u21ad",
|
2024-06-11 17:09:58 -06:00
|
|
|
'uploader_id': 'ytdl',
|
|
|
|
},
|
2013-06-27 12:22:00 -06:00
|
|
|
},
|
|
|
|
{
|
2016-02-14 02:37:17 -07:00
|
|
|
'md5': '1893e872e263a2705558d1d319ad19e8',
|
|
|
|
'info_dict': {
|
|
|
|
'id': '11885682',
|
|
|
|
'ext': 'm4a',
|
2021-02-24 11:45:56 -07:00
|
|
|
'title': "PH - youtube-dl test track 5 \"'/\\\u00e4\u21ad",
|
2024-06-11 17:09:58 -06:00
|
|
|
'uploader_id': 'ytdl',
|
|
|
|
},
|
2013-06-27 12:22:00 -06:00
|
|
|
},
|
|
|
|
{
|
2016-02-14 02:37:17 -07:00
|
|
|
'md5': 'b673c46f47a216ab1741ae8836af5899',
|
|
|
|
'info_dict': {
|
|
|
|
'id': '11885683',
|
|
|
|
'ext': 'm4a',
|
2021-02-24 11:45:56 -07:00
|
|
|
'title': "PH - youtube-dl test track 6 \"'/\\\u00e4\u21ad",
|
2024-06-11 17:09:58 -06:00
|
|
|
'uploader_id': 'ytdl',
|
|
|
|
},
|
2013-06-27 12:22:00 -06:00
|
|
|
},
|
|
|
|
{
|
2016-02-14 02:37:17 -07:00
|
|
|
'md5': '1d74534e95df54986da7f5abf7d842b7',
|
|
|
|
'info_dict': {
|
|
|
|
'id': '11885684',
|
|
|
|
'ext': 'm4a',
|
2021-02-24 11:45:56 -07:00
|
|
|
'title': "phihag - youtube-dl test track 7 \"'/\\\u00e4\u21ad",
|
2024-06-11 17:09:58 -06:00
|
|
|
'uploader_id': 'ytdl',
|
|
|
|
},
|
2013-06-27 12:22:00 -06:00
|
|
|
},
|
|
|
|
{
|
2016-02-14 02:37:17 -07:00
|
|
|
'md5': 'f081f47af8f6ae782ed131d38b9cd1c0',
|
|
|
|
'info_dict': {
|
|
|
|
'id': '11885685',
|
|
|
|
'ext': 'm4a',
|
2021-02-24 11:45:56 -07:00
|
|
|
'title': "phihag - youtube-dl test track 8 \"'/\\\u00e4\u21ad",
|
2024-06-11 17:09:58 -06:00
|
|
|
'uploader_id': 'ytdl',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
2013-06-27 12:22:00 -06:00
|
|
|
}
|
|
|
|
|
2013-06-23 14:15:50 -06:00
|
|
|
def _real_extract(self, url):
|
2015-03-14 03:55:21 -06:00
|
|
|
playlist_id = self._match_id(url)
|
2013-06-23 14:15:50 -06:00
|
|
|
|
|
|
|
webpage = self._download_webpage(url, playlist_id)
|
|
|
|
|
2015-03-14 03:54:23 -06:00
|
|
|
data = self._parse_json(
|
|
|
|
self._search_regex(
|
2024-06-11 17:09:58 -06:00
|
|
|
r'(?s)PAGE\.mix\s*=\s*({.+?});\n', webpage, 'trax information'),
|
2015-03-14 03:54:23 -06:00
|
|
|
playlist_id)
|
2013-06-23 14:15:50 -06:00
|
|
|
|
|
|
|
session = str(random.randint(0, 1000000000))
|
|
|
|
mix_id = data['id']
|
|
|
|
track_count = data['tracks_count']
|
2014-10-14 21:46:47 -06:00
|
|
|
duration = data['duration']
|
2015-01-09 21:51:07 -07:00
|
|
|
avg_song_duration = float(duration) / track_count
|
2015-03-14 03:52:06 -06:00
|
|
|
# duration is sometimes negative, use predefined avg duration
|
|
|
|
if avg_song_duration <= 0:
|
|
|
|
avg_song_duration = 300
|
2024-06-11 17:09:58 -06:00
|
|
|
first_url = f'http://8tracks.com/sets/{session}/play?player=sm&mix_id={mix_id}&format=jsonh'
|
2013-06-23 14:15:50 -06:00
|
|
|
next_url = first_url
|
2014-08-26 03:31:23 -06:00
|
|
|
entries = []
|
2014-10-14 21:46:47 -06:00
|
|
|
|
[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'
2013-10-25 15:46:18 -06:00
|
|
|
for i in range(track_count):
|
2014-10-14 21:46:47 -06:00
|
|
|
api_json = None
|
|
|
|
download_tries = 0
|
|
|
|
|
|
|
|
while api_json is None:
|
|
|
|
try:
|
|
|
|
api_json = self._download_webpage(
|
|
|
|
next_url, playlist_id,
|
|
|
|
note='Downloading song information %d/%d' % (i + 1, track_count),
|
|
|
|
errnote='Failed to download song information')
|
|
|
|
except ExtractorError:
|
|
|
|
if download_tries > 3:
|
|
|
|
raise
|
|
|
|
else:
|
2014-12-06 00:20:35 -07:00
|
|
|
download_tries += 1
|
2015-01-09 21:51:07 -07:00
|
|
|
self._sleep(avg_song_duration, playlist_id)
|
2014-10-14 21:46:47 -06:00
|
|
|
|
2013-06-23 14:15:50 -06:00
|
|
|
api_data = json.loads(api_json)
|
2014-08-26 03:31:23 -06:00
|
|
|
track_data = api_data['set']['track']
|
2013-06-23 14:15:50 -06:00
|
|
|
info = {
|
2024-06-11 17:09:58 -06:00
|
|
|
'id': str(track_data['id']),
|
2013-06-23 14:15:50 -06:00
|
|
|
'url': track_data['track_file_stream_url'],
|
2014-11-26 05:06:02 -07:00
|
|
|
'title': track_data['performer'] + ' - ' + track_data['name'],
|
2013-06-23 14:15:50 -06:00
|
|
|
'raw_title': track_data['name'],
|
|
|
|
'uploader_id': data['user']['login'],
|
|
|
|
'ext': 'm4a',
|
|
|
|
}
|
2014-08-26 03:31:23 -06:00
|
|
|
entries.append(info)
|
2014-10-14 21:46:47 -06:00
|
|
|
|
2024-06-11 17:09:58 -06:00
|
|
|
next_url = 'http://8tracks.com/sets/{}/next?player=sm&mix_id={}&format=jsonh&track_id={}'.format(
|
2014-08-26 03:31:23 -06:00
|
|
|
session, mix_id, track_data['id'])
|
|
|
|
return {
|
|
|
|
'_type': 'playlist',
|
|
|
|
'entries': entries,
|
2024-06-11 17:09:58 -06:00
|
|
|
'id': str(mix_id),
|
2014-08-26 03:31:23 -06:00
|
|
|
'display_id': playlist_id,
|
|
|
|
'title': data.get('name'),
|
|
|
|
'description': data.get('description'),
|
|
|
|
}
|