mirror of
https://gitlab.com/RemixDev/deezer-py.git
synced 2024-12-28 02:16:08 +00:00
Removed eventlet and added get_session and set_session
This commit is contained in:
parent
6f90d520f2
commit
ad4ccf1b1d
|
@ -1,5 +1,4 @@
|
||||||
import eventlet
|
import requests
|
||||||
requests = eventlet.import_patched('requests')
|
|
||||||
from deezer.gw import GW
|
from deezer.gw import GW
|
||||||
from deezer.api import API
|
from deezer.api import API
|
||||||
import json
|
import json
|
||||||
|
@ -18,15 +17,13 @@ class TrackFormats():
|
||||||
LOCAL = 0
|
LOCAL = 0
|
||||||
|
|
||||||
class Deezer:
|
class Deezer:
|
||||||
def __init__(self):
|
def __init__(self, accept_language=None):
|
||||||
self.http_headers = {
|
self.http_headers = {
|
||||||
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) " \
|
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) " \
|
||||||
"Chrome/79.0.3945.130 Safari/537.36",
|
"Chrome/79.0.3945.130 Safari/537.36",
|
||||||
"Accept-Language": None
|
"Accept-Language": accept_language
|
||||||
}
|
}
|
||||||
self.session = requests.Session()
|
self.session = requests.Session()
|
||||||
self.session.mount('http://', requests.adapters.HTTPAdapter(pool_maxsize=100))
|
|
||||||
self.session.mount('https://', requests.adapters.HTTPAdapter(pool_maxsize=100))
|
|
||||||
|
|
||||||
self.logged_in = False
|
self.logged_in = False
|
||||||
self.current_user = {}
|
self.current_user = {}
|
||||||
|
@ -36,11 +33,27 @@ class Deezer:
|
||||||
self.api = API(self.session, self.http_headers)
|
self.api = API(self.session, self.http_headers)
|
||||||
self.gw = GW(self.session, self.http_headers)
|
self.gw = GW(self.session, self.http_headers)
|
||||||
|
|
||||||
|
def get_accept_language(self):
|
||||||
|
return self.http_headers['Accept-Language']
|
||||||
|
|
||||||
def set_accept_language(self, lang):
|
def set_accept_language(self, lang):
|
||||||
self.http_headers['Accept-Language'] = lang
|
self.http_headers['Accept-Language'] = lang
|
||||||
|
|
||||||
def get_accept_language(self):
|
def get_session(self):
|
||||||
return self.http_headers['Accept-Language']
|
return {
|
||||||
|
'logged_in': self.logged_in,
|
||||||
|
'current_user': self.current_user,
|
||||||
|
'childs': self.childs,
|
||||||
|
'selected_account': self.selected_account,
|
||||||
|
'cookies': self.session.cookies.get_dict()
|
||||||
|
}
|
||||||
|
|
||||||
|
def set_session(self, data):
|
||||||
|
self.logged_in = data['logged_in']
|
||||||
|
self.current_user = data['current_user']
|
||||||
|
self.childs = data['childs']
|
||||||
|
self.selected_account = data['selected_account']
|
||||||
|
self.session.cookies.update(data['cookies'])
|
||||||
|
|
||||||
def login(self, email, password, re_captcha_token, child=0):
|
def login(self, email, password, re_captcha_token, child=0):
|
||||||
# Check if user already logged in
|
# Check if user already logged in
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import eventlet
|
import requests
|
||||||
requests = eventlet.import_patched('requests')
|
from time import sleep
|
||||||
|
|
||||||
class SearchOrder():
|
class SearchOrder():
|
||||||
"""Possible values for order parameter in search"""
|
"""Possible values for order parameter in search"""
|
||||||
|
@ -34,12 +34,12 @@ class API:
|
||||||
)
|
)
|
||||||
result_json = result.json()
|
result_json = result.json()
|
||||||
except:
|
except:
|
||||||
eventlet.sleep(2)
|
sleep(2)
|
||||||
return self.api_call(method, args)
|
return self.api_call(method, args)
|
||||||
if 'error' in result_json.keys():
|
if 'error' in result_json.keys():
|
||||||
if 'code' in result_json['error']:
|
if 'code' in result_json['error']:
|
||||||
if result_json['error']['code'] in [4, 700]:
|
if result_json['error']['code'] in [4, 700]:
|
||||||
eventlet.sleep(5)
|
sleep(5)
|
||||||
return self.api_call(method, args)
|
return self.api_call(method, args)
|
||||||
if result_json['error']['code'] == 100: raise ItemsLimitExceededException(f"ItemsLimitExceededException: {method}")
|
if result_json['error']['code'] == 100: raise ItemsLimitExceededException(f"ItemsLimitExceededException: {method}")
|
||||||
if result_json['error']['code'] == 200: raise PermissionException(f"PermissionException: {method}")
|
if result_json['error']['code'] == 200: raise PermissionException(f"PermissionException: {method}")
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import eventlet
|
import requests
|
||||||
requests = eventlet.import_patched('requests')
|
from time import sleep
|
||||||
|
|
||||||
import json
|
import json
|
||||||
from deezer.utils import map_artist_album, map_user_track, map_user_artist, map_user_album, map_user_playlist
|
from deezer.utils import map_artist_album, map_user_track, map_user_artist, map_user_album, map_user_playlist
|
||||||
|
@ -72,7 +72,7 @@ class GW:
|
||||||
)
|
)
|
||||||
result_json = result.json()
|
result_json = result.json()
|
||||||
except:
|
except:
|
||||||
eventlet.sleep(2)
|
sleep(2)
|
||||||
return self.api_call(method, args, params)
|
return self.api_call(method, args, params)
|
||||||
if len(result_json['error']):
|
if len(result_json['error']):
|
||||||
raise APIError(json.dumps(result_json['error']))
|
raise APIError(json.dumps(result_json['error']))
|
||||||
|
|
|
@ -1,2 +1 @@
|
||||||
requests
|
requests
|
||||||
eventlet
|
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -26,5 +26,5 @@ setup(
|
||||||
python_requires='>=3.6',
|
python_requires='>=3.6',
|
||||||
packages=find_packages(exclude=("tests",)),
|
packages=find_packages(exclude=("tests",)),
|
||||||
include_package_data=True,
|
include_package_data=True,
|
||||||
install_requires=["requests", "eventlet"],
|
install_requires=["requests"],
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue