mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-09-03 13:05:25 +02:00
[eighttracks] modernize
This commit is contained in:
parent
9a66c1079c
commit
0963f92f23
@ -1,10 +1,13 @@
|
|||||||
|
# coding: utf-8
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
ExtractorError,
|
compat_str,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -12,86 +15,98 @@ class EightTracksIE(InfoExtractor):
|
|||||||
IE_NAME = '8tracks'
|
IE_NAME = '8tracks'
|
||||||
_VALID_URL = r'https?://8tracks\.com/(?P<user>[^/]+)/(?P<id>[^/#]+)(?:#.*)?$'
|
_VALID_URL = r'https?://8tracks\.com/(?P<user>[^/]+)/(?P<id>[^/#]+)(?:#.*)?$'
|
||||||
_TEST = {
|
_TEST = {
|
||||||
u"name": u"EightTracks",
|
"name": "EightTracks",
|
||||||
u"url": u"http://8tracks.com/ytdl/youtube-dl-test-tracks-a",
|
"url": "http://8tracks.com/ytdl/youtube-dl-test-tracks-a",
|
||||||
u"playlist": [
|
"info_dict": {
|
||||||
|
'id': '1336550',
|
||||||
|
'display_id': 'youtube-dl-test-tracks-a',
|
||||||
|
"description": "test chars: \"'/\\ä↭",
|
||||||
|
"title": "youtube-dl test tracks \"'/\\ä↭<>",
|
||||||
|
},
|
||||||
|
"playlist": [
|
||||||
{
|
{
|
||||||
u"file": u"11885610.m4a",
|
"md5": "96ce57f24389fc8734ce47f4c1abcc55",
|
||||||
u"md5": u"96ce57f24389fc8734ce47f4c1abcc55",
|
"info_dict": {
|
||||||
u"info_dict": {
|
"id": "11885610",
|
||||||
u"title": u"youtue-dl project<>\"' - youtube-dl test track 1 \"'/\\\u00e4\u21ad",
|
"ext": "m4a",
|
||||||
u"uploader_id": u"ytdl"
|
"title": "youtue-dl project<>\"' - youtube-dl test track 1 \"'/\\\u00e4\u21ad",
|
||||||
|
"uploader_id": "ytdl"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
u"file": u"11885608.m4a",
|
"md5": "4ab26f05c1f7291ea460a3920be8021f",
|
||||||
u"md5": u"4ab26f05c1f7291ea460a3920be8021f",
|
"info_dict": {
|
||||||
u"info_dict": {
|
"id": "11885608",
|
||||||
u"title": u"youtube-dl project - youtube-dl test track 2 \"'/\\\u00e4\u21ad",
|
"ext": "m4a",
|
||||||
u"uploader_id": u"ytdl"
|
"title": "youtube-dl project - youtube-dl test track 2 \"'/\\\u00e4\u21ad",
|
||||||
|
"uploader_id": "ytdl"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
u"file": u"11885679.m4a",
|
"md5": "d30b5b5f74217410f4689605c35d1fd7",
|
||||||
u"md5": u"d30b5b5f74217410f4689605c35d1fd7",
|
"info_dict": {
|
||||||
u"info_dict": {
|
"id": "11885679",
|
||||||
u"title": u"youtube-dl project as well - youtube-dl test track 3 \"'/\\\u00e4\u21ad",
|
"ext": "m4a",
|
||||||
u"uploader_id": u"ytdl"
|
"title": "youtube-dl project as well - youtube-dl test track 3 \"'/\\\u00e4\u21ad",
|
||||||
|
"uploader_id": "ytdl"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
u"file": u"11885680.m4a",
|
"md5": "4eb0a669317cd725f6bbd336a29f923a",
|
||||||
u"md5": u"4eb0a669317cd725f6bbd336a29f923a",
|
"info_dict": {
|
||||||
u"info_dict": {
|
"id": "11885680",
|
||||||
u"title": u"youtube-dl project as well - youtube-dl test track 4 \"'/\\\u00e4\u21ad",
|
"ext": "m4a",
|
||||||
u"uploader_id": u"ytdl"
|
"title": "youtube-dl project as well - youtube-dl test track 4 \"'/\\\u00e4\u21ad",
|
||||||
|
"uploader_id": "ytdl"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
u"file": u"11885682.m4a",
|
"md5": "1893e872e263a2705558d1d319ad19e8",
|
||||||
u"md5": u"1893e872e263a2705558d1d319ad19e8",
|
"info_dict": {
|
||||||
u"info_dict": {
|
"id": "11885682",
|
||||||
u"title": u"PH - youtube-dl test track 5 \"'/\\\u00e4\u21ad",
|
"ext": "m4a",
|
||||||
u"uploader_id": u"ytdl"
|
"title": "PH - youtube-dl test track 5 \"'/\\\u00e4\u21ad",
|
||||||
|
"uploader_id": "ytdl"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
u"file": u"11885683.m4a",
|
"md5": "b673c46f47a216ab1741ae8836af5899",
|
||||||
u"md5": u"b673c46f47a216ab1741ae8836af5899",
|
"info_dict": {
|
||||||
u"info_dict": {
|
"id": "11885683",
|
||||||
u"title": u"PH - youtube-dl test track 6 \"'/\\\u00e4\u21ad",
|
"ext": "m4a",
|
||||||
u"uploader_id": u"ytdl"
|
"title": "PH - youtube-dl test track 6 \"'/\\\u00e4\u21ad",
|
||||||
|
"uploader_id": "ytdl"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
u"file": u"11885684.m4a",
|
"md5": "1d74534e95df54986da7f5abf7d842b7",
|
||||||
u"md5": u"1d74534e95df54986da7f5abf7d842b7",
|
"info_dict": {
|
||||||
u"info_dict": {
|
"id": "11885684",
|
||||||
u"title": u"phihag - youtube-dl test track 7 \"'/\\\u00e4\u21ad",
|
"ext": "m4a",
|
||||||
u"uploader_id": u"ytdl"
|
"title": "phihag - youtube-dl test track 7 \"'/\\\u00e4\u21ad",
|
||||||
|
"uploader_id": "ytdl"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
u"file": u"11885685.m4a",
|
"md5": "f081f47af8f6ae782ed131d38b9cd1c0",
|
||||||
u"md5": u"f081f47af8f6ae782ed131d38b9cd1c0",
|
"info_dict": {
|
||||||
u"info_dict": {
|
"id": "11885685",
|
||||||
u"title": u"phihag - youtube-dl test track 8 \"'/\\\u00e4\u21ad",
|
"ext": "m4a",
|
||||||
u"uploader_id": u"ytdl"
|
"title": "phihag - youtube-dl test track 8 \"'/\\\u00e4\u21ad",
|
||||||
|
"uploader_id": "ytdl"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
mobj = re.match(self._VALID_URL, url)
|
mobj = re.match(self._VALID_URL, url)
|
||||||
if mobj is None:
|
|
||||||
raise ExtractorError(u'Invalid URL: %s' % url)
|
|
||||||
playlist_id = mobj.group('id')
|
playlist_id = mobj.group('id')
|
||||||
|
|
||||||
webpage = self._download_webpage(url, playlist_id)
|
webpage = self._download_webpage(url, playlist_id)
|
||||||
|
|
||||||
json_like = self._search_regex(r"PAGE.mix = (.*?);\n", webpage, u'trax information', flags=re.DOTALL)
|
json_like = self._search_regex(
|
||||||
|
r"(?s)PAGE.mix = (.*?);\n", webpage, 'trax information')
|
||||||
data = json.loads(json_like)
|
data = json.loads(json_like)
|
||||||
|
|
||||||
session = str(random.randint(0, 1000000000))
|
session = str(random.randint(0, 1000000000))
|
||||||
@ -99,21 +114,30 @@ def _real_extract(self, url):
|
|||||||
track_count = data['tracks_count']
|
track_count = data['tracks_count']
|
||||||
first_url = 'http://8tracks.com/sets/%s/play?player=sm&mix_id=%s&format=jsonh' % (session, mix_id)
|
first_url = 'http://8tracks.com/sets/%s/play?player=sm&mix_id=%s&format=jsonh' % (session, mix_id)
|
||||||
next_url = first_url
|
next_url = first_url
|
||||||
res = []
|
entries = []
|
||||||
for i in range(track_count):
|
for i in range(track_count):
|
||||||
api_json = self._download_webpage(next_url, playlist_id,
|
api_json = self._download_webpage(
|
||||||
note=u'Downloading song information %s/%s' % (str(i+1), track_count),
|
next_url, playlist_id,
|
||||||
errnote=u'Failed to download song information')
|
note='Downloading song information %d/%d' % (i + 1, track_count),
|
||||||
|
errnote='Failed to download song information')
|
||||||
api_data = json.loads(api_json)
|
api_data = json.loads(api_json)
|
||||||
track_data = api_data[u'set']['track']
|
track_data = api_data['set']['track']
|
||||||
info = {
|
info = {
|
||||||
'id': track_data['id'],
|
'id': compat_str(track_data['id']),
|
||||||
'url': track_data['track_file_stream_url'],
|
'url': track_data['track_file_stream_url'],
|
||||||
'title': track_data['performer'] + u' - ' + track_data['name'],
|
'title': track_data['performer'] + u' - ' + track_data['name'],
|
||||||
'raw_title': track_data['name'],
|
'raw_title': track_data['name'],
|
||||||
'uploader_id': data['user']['login'],
|
'uploader_id': data['user']['login'],
|
||||||
'ext': 'm4a',
|
'ext': 'm4a',
|
||||||
}
|
}
|
||||||
res.append(info)
|
entries.append(info)
|
||||||
next_url = 'http://8tracks.com/sets/%s/next?player=sm&mix_id=%s&format=jsonh&track_id=%s' % (session, mix_id, track_data['id'])
|
next_url = 'http://8tracks.com/sets/%s/next?player=sm&mix_id=%s&format=jsonh&track_id=%s' % (
|
||||||
return res
|
session, mix_id, track_data['id'])
|
||||||
|
return {
|
||||||
|
'_type': 'playlist',
|
||||||
|
'entries': entries,
|
||||||
|
'id': compat_str(mix_id),
|
||||||
|
'display_id': playlist_id,
|
||||||
|
'title': data.get('name'),
|
||||||
|
'description': data.get('description'),
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user