Browse Source

added missing headers to another request (#385)

master
def-hash 9 months ago committed by GitHub
parent
commit
8dbe937a22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      scdl/__init__.py
  2. 4
      scdl/client.py
  3. 16
      scdl/scdl.py

3
scdl/__init__.py

@ -9,6 +9,9 @@ CLIENT_ID = 'a3e059563d7fd3372b49b37f00a00bcf'
ALT_CLIENT_ID = '2t9loNQH90kzJcsFCODdigxfp325aq4z'
ALT2_CLIENT_ID = 'NONE'
USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36'
default_config = """[scdl]
auth_token =
path = .

4
scdl/client.py

@ -1,7 +1,7 @@
# -*- encoding: utf-8 -*-
import requests
from scdl import CLIENT_ID
from scdl import CLIENT_ID, USER_AGENT
class Client():
@ -15,7 +15,7 @@ class Client():
params['oauth_token'] = token
resources = list()
while url:
response = requests.get(url, params=params)
response = requests.get(url, params=params, headers={'User-Agent': USER_AGENT})
response.raise_for_status()
json_data = response.json()
if 'collection' in json_data:

16
scdl/scdl.py

@ -74,7 +74,7 @@ import mutagen
from docopt import docopt
from clint.textui import progress
from scdl import __version__, CLIENT_ID, ALT_CLIENT_ID
from scdl import __version__, CLIENT_ID, ALT_CLIENT_ID, USER_AGENT
from scdl import client, utils
from datetime import datetime
@ -238,7 +238,7 @@ def get_item(track_url, client_id=CLIENT_ID):
try:
item_url = url['resolve'].format(track_url)
r = requests.get(item_url, params={'client_id': client_id})
r = requests.get(item_url, params={'client_id': client_id}, headers={'User-Agent': USER_AGENT})
logger.debug(r.url)
if r.status_code == 403:
return get_item(track_url, ALT_CLIENT_ID)
@ -303,7 +303,7 @@ def who_am_i():
Display username from current token and check for validity
"""
me = url['me'].format(token)
r = requests.get(me, params={'client_id': CLIENT_ID})
r = requests.get(me, params={'client_id': CLIENT_ID}, headers={'User-Agent': USER_AGENT})
r.raise_for_status()
current_user = r.json()
logger.debug(me)
@ -332,7 +332,7 @@ def get_track_info(track):
logger.info('Retrieving more info on the track')
info_url = url["trackinfo"].format(track['id'])
r = requests.get(info_url, params={'client_id': CLIENT_ID}, stream=True)
r = requests.get(info_url, params={'client_id': CLIENT_ID}, stream=True, headers={'User-Agent': USER_AGENT})
item = r.json()
logger.debug(item)
return item
@ -465,9 +465,9 @@ def download_original_file(track, title):
# Get the requests stream
r = requests.get(
original_url, params={'client_id': CLIENT_ID}
original_url, params={'client_id': CLIENT_ID}, headers={'User-Agent': USER_AGENT}
)
r = requests.get(r.json()['redirectUri'], stream=True)
r = requests.get(r.json()['redirectUri'], stream=True, headers={'User-Agent': USER_AGENT})
if r.status_code == 401:
logger.info('The original file has no download left.')
return (None, False)
@ -529,7 +529,7 @@ def get_track_m3u8(track):
url = transcoding['url']
if url is not None:
r = requests.get(url, params={'client_id': CLIENT_ID})
r = requests.get(url, params={'client_id': CLIENT_ID}, headers={'User-Agent': USER_AGENT})
logger.debug(r.url)
return r.json()['url']
@ -706,7 +706,7 @@ def set_metadata(track, filename, playlist_info=None):
if not artwork_url:
artwork_url = user['avatar_url']
artwork_url = artwork_url.replace('large', 't500x500')
response = requests.get(artwork_url, stream=True)
response = requests.get(artwork_url, stream=True, headers={'User-Agent': USER_AGENT})
with tempfile.NamedTemporaryFile() as out_file:
shutil.copyfileobj(response.raw, out_file)
out_file.seek(0)

Loading…
Cancel
Save