mirror of
https://github.com/soimort/you-get.git
synced 2025-03-13 03:17:44 +03:00
[soundcloud]update client id and new api
This commit is contained in:
parent
728360f4cc
commit
7eb7ead380
@ -459,6 +459,9 @@ def url_info(url, faker = False, headers = {}):
|
||||
'video/x-ms-asf': 'asf',
|
||||
'audio/mp4': 'mp4',
|
||||
'audio/mpeg': 'mp3',
|
||||
'audio/wav': 'wav',
|
||||
'audio/x-wav': 'wav',
|
||||
'audio/wave': 'wav',
|
||||
'image/jpeg': 'jpg',
|
||||
'image/png': 'png',
|
||||
'image/gif': 'gif',
|
||||
@ -1085,6 +1088,8 @@ def print_info(site_info, title, type, size):
|
||||
type_info = "MPEG-4 audio (%s)" % type
|
||||
elif type in ['audio/mpeg']:
|
||||
type_info = "MP3 (%s)" % type
|
||||
elif type in ['audio/wav', 'audio/wave', 'audio/x-wav']:
|
||||
type_info = 'Waveform Audio File Format ({})'.format(type)
|
||||
|
||||
elif type in ['image/jpeg']:
|
||||
type_info = "JPEG Image (%s)" % type
|
||||
|
@ -3,28 +3,46 @@
|
||||
__all__ = ['soundcloud_download', 'soundcloud_download_by_id']
|
||||
|
||||
from ..common import *
|
||||
import json
|
||||
import urllib.error
|
||||
|
||||
def soundcloud_download_by_id(id, title = None, output_dir = '.', merge = True, info_only = False):
|
||||
client_id = 'JlZIsxg2hY5WnBgtn3jfS0UYCl0K8DOg'
|
||||
|
||||
def soundcloud_download_by_id(id, title=None, output_dir='.', merge=True, info_only=False):
|
||||
assert title
|
||||
url = 'https://api.soundcloud.com/tracks/{}/{}?client_id={}'.format(id, 'stream', client_id)
|
||||
|
||||
#if info["downloadable"]:
|
||||
# url = 'https://api.soundcloud.com/tracks/' + id + '/download?client_id=b45b1aa10f1ac2941910a7f0d10f8e28'
|
||||
url = 'https://api.soundcloud.com/tracks/' + id + '/stream?client_id=02gUJC0hH2ct1EGOcYXQIzRFU91c72Ea'
|
||||
assert url
|
||||
type, ext, size = url_info(url)
|
||||
|
||||
print_info(site_info, title, type, size)
|
||||
|
||||
if not info_only:
|
||||
download_urls([url], title, ext, size, output_dir, merge = merge)
|
||||
|
||||
def soundcloud_download(url, output_dir = '.', merge = True, info_only = False, **kwargs):
|
||||
metadata = get_html('https://api.soundcloud.com/resolve.json?url=' + url + '&client_id=02gUJC0hH2ct1EGOcYXQIzRFU91c72Ea')
|
||||
import json
|
||||
def soundcloud_i1_api(track_id):
|
||||
url = 'https://api.soundcloud.com/i1/tracks/{}/streams?client_id={}'.format(track_id, client_id)
|
||||
return json.loads(get_content(url))['http_mp3_128_url']
|
||||
|
||||
def soundcloud_download(url, output_dir='.', merge=True, info_only=False, **kwargs):
|
||||
url = 'https://api.soundcloud.com/resolve.json?url={}&client_id={}'.format(url, client_id)
|
||||
metadata = get_content(url)
|
||||
info = json.loads(metadata)
|
||||
title = info["title"]
|
||||
id = str(info["id"])
|
||||
|
||||
soundcloud_download_by_id(id, title, output_dir, merge = merge, info_only = info_only)
|
||||
real_url = info.get('download_url')
|
||||
if real_url is None:
|
||||
real_url = info.get('steram_url')
|
||||
if real_url is None:
|
||||
raise Exception('Cannot get media URI for {}'.format(url))
|
||||
real_url = '{}?client_id={}'.format(real_url, client_id)
|
||||
try:
|
||||
mime, ext, size = url_info(real_url)
|
||||
except urllib.error.HTTPError as e:
|
||||
if 401 == e.status:
|
||||
real_url = soundcloud_i1_api(info['id'])
|
||||
mime, ext, size = url_info(real_url)
|
||||
print_info(site_info, title, mime, size)
|
||||
if not info_only:
|
||||
download_urls([real_url], title, ext, size, output_dir, merge=merge)
|
||||
|
||||
site_info = "SoundCloud.com"
|
||||
download = soundcloud_download
|
||||
|
Loading…
x
Reference in New Issue
Block a user