Browse Source

[FIX] Access Token

New CLIENT_ID!
master
flyingrub 6 years ago
parent
commit
3419acf082
  1. 7
      README.md
  2. 4
      scdl/__init__.py
  3. 6
      scdl/client.py
  4. 25
      scdl/scdl.py

7
README.md

@ -1,3 +1,4 @@
[![PyPI version](https://img.shields.io/pypi/v/scdl.svg)](https://pypi.python.org/pypi/scdl/)
[![PyPI version](https://img.shields.io/github/issues-raw/flyingrub/scdl.svg)](https://github.com/flyingrub/scdl/issues)
[![PyPI version](https://img.shields.io/pypi/dm/scdl.svg)](https://pypi.python.org/pypi/scdl/)
@ -19,17 +20,17 @@ ___
```
pip3 install scdl
```
or
or
```
git clone https://github.com/flyingrub/scdl.git && cd scdl
python3 setup.py install
```
```
(Optional) Setup your path and your auth_token in `$HOME/.config/scdl/scdl.cfg`
### Authentication
___
> Get your auth token here: `DOMAIN NAME EXPIRED` (will be replaced soon)
> Get your auth token here: [https://flyingrub.github.io/scdl/](https://flyingrub.github.io/scdl/)
* This allows scdl to access to your user profile data.
* You need to have this set to be able to use the `me` option

4
scdl/__init__.py

@ -4,7 +4,9 @@
import os
__version__ = 'v1.5.2'
__version__ = 'v1.5.3'
CLIENT_ID = 'bed20744714e9c5962c351efe15840ff'
ALT_CLIENT_ID = 'a3e059563d7fd3372b49b37f00a00bcf'
dir_path_to_conf = os.path.join(os.path.expanduser('~'), '.config/scdl')
file_path_to_conf = os.path.join(

6
scdl/client.py

@ -1,9 +1,7 @@
# -*- encoding: utf-8 -*-
import requests
scdl_client_id = '95a4c0ef214f2a4a0852142807b54b35'
alternative_client_id = 'a3e059563d7fd3372b49b37f00a00bcf'
from scdl import CLIENT_ID
class Client():
@ -12,7 +10,7 @@ class Client():
resources = list()
while url:
url = '{0}&client_id={1}&linked_partitioning=1'.format(
url, scdl_client_id)
url, CLIENT_ID)
response = requests.get(url)
json_data = response.json()
if 'collection' in json_data:

25
scdl/scdl.py

@ -55,9 +55,10 @@ import mutagen
from docopt import docopt
from clint.textui import progress
from scdl import __version__
from scdl import __version__, CLIENT_ID, ALT_CLIENT_ID
from scdl import client, utils
logging.basicConfig(level=logging.INFO, format='%(message)s')
logging.getLogger('requests').setLevel(logging.WARNING)
logger = logging.getLogger(__name__)
@ -69,8 +70,6 @@ arguments = None
token = ''
path = ''
offset = 0
scdl_client_id = '95a4c0ef214f2a4a0852142807b54b35'
alternative_client_id = 'a3e059563d7fd3372b49b37f00a00bcf'
url = {
'favorites': ('https://api.soundcloud.com/users/{0}/favorites?'
@ -188,7 +187,7 @@ def get_config():
sys.exit()
def get_item(track_url, client_id=scdl_client_id):
def get_item(track_url, client_id=CLIENT_ID):
"""
Fetches metadata for an track or playlist
"""
@ -199,20 +198,20 @@ def get_item(track_url, client_id=scdl_client_id):
r = requests.get(item_url)
if r.status_code == 403:
return get_item(track_url, alternative_client_id)
return get_item(track_url, ALT_CLIENT_ID)
item = r.json()
no_tracks = item['kind'] == 'playlist' and not item['tracks']
if no_tracks and client_id != alternative_client_id:
return get_item(track_url, alternative_client_id)
if no_tracks and client_id != ALT_CLIENT_ID:
return get_item(track_url, ALT_CLIENT_ID)
except Exception:
if client_id == alternative_client_id:
if client_id == ALT_CLIENT_ID:
logger.error('Get item failed...')
return
logger.error('Error resolving url, retrying...')
time.sleep(5)
try:
return get_item(track_url, alternative_client_id)
return get_item(track_url, ALT_CLIENT_ID)
except Exception as e:
logger.error('Could not resolve url {0}'.format(track_url))
logger.exception(e)
@ -257,7 +256,7 @@ def who_am_i():
display to who the current token correspond, check if the token is valid
"""
me = url['me'].format(token)
me = '{0}&client_id={1}'.format(me, scdl_client_id)
me = '{0}&client_id={1}'.format(me, CLIENT_ID)
r = requests.get(me)
current_user = r.json()
logger.debug(me)
@ -367,7 +366,7 @@ def download_track(track, playlist_name=None, playlist_file=None):
title = track['title']
title = title.encode('utf-8', 'ignore').decode('utf8')
if track['streamable']:
url = '{0}?client_id={1}'.format(track['stream_url'], scdl_client_id)
url = '{0}?client_id={1}'.format(track['stream_url'], CLIENT_ID)
else:
logger.error('{0} is not streamable...'.format(title))
logger.newline()
@ -378,7 +377,7 @@ def download_track(track, playlist_name=None, playlist_file=None):
if track['downloadable'] and not arguments['--onlymp3']:
logger.info('Downloading the original file.')
download_url = track['download_url']
url = '{0}?client_id={1}'.format(download_url, scdl_client_id)
url = '{0}?client_id={1}'.format(download_url, CLIENT_ID)
r = requests.get(url, stream=True)
d = r.headers['content-disposition']
filename = re.findall("filename=(.+)", d)[0][1:-1]
@ -406,7 +405,7 @@ def download_track(track, playlist_name=None, playlist_file=None):
logger.debug(url)
r = requests.get(url, stream=True)
if r.status_code == 401:
url = url[:-32] + alternative_client_id
url = url[:-32] + ALT_CLIENT_ID
logger.debug(url)
r = requests.get(url, stream=True)
temp = tempfile.NamedTemporaryFile(delete=False)

Loading…
Cancel
Save