mirror of
https://gitea.phreedom.club/localhost_frssoft/funkwlmpv
synced 2024-12-22 05:39:48 +00:00
Now uses listen_token for listening private tracks
Also this is required for external transcoder
This commit is contained in:
parent
221aa66a58
commit
1e3972d009
@ -1,4 +1,3 @@
|
||||
from src.mpv_control import set_http_header
|
||||
from src.settings import get_config
|
||||
import requests
|
||||
import json
|
||||
@ -32,6 +31,8 @@ class current_instance:
|
||||
s = requests.Session()
|
||||
instance = get_config('instance')
|
||||
token = auth.get(instance)
|
||||
listen_token = None
|
||||
|
||||
|
||||
@logger.catch
|
||||
def select_instance(new_instance=None):
|
||||
@ -41,14 +42,14 @@ class current_instance:
|
||||
new_token = auth.get(current_instance.instance)
|
||||
current_instance.s.headers.update({"Authorization": None,
|
||||
"Accept-encoding": 'gzip'})
|
||||
set_http_header()
|
||||
current_instance.token = new_token
|
||||
current_instance.listen_token = None
|
||||
if new_token:
|
||||
s.get(f'https://{current_instance.instance}')
|
||||
s.headers.update({
|
||||
"Authorization": "Bearer " + new_token,
|
||||
"Accept-encoding": 'gzip'
|
||||
})
|
||||
set_http_header(['Authorization: ' + 'Bearer ' + new_token])
|
||||
|
||||
|
||||
if current_instance.token:
|
||||
@ -56,12 +57,21 @@ if current_instance.token:
|
||||
"Authorization": "Bearer " + current_instance.token,
|
||||
"Accept-encoding": 'gzip'
|
||||
})
|
||||
set_http_header(['Authorization: ' + 'Bearer ' + current_instance.token])
|
||||
else:
|
||||
current_instance.s.headers.update({"Accept-encoding": 'gzip'})
|
||||
# Get cookies from unauthorized instance for working some functionality (radios)
|
||||
current_instance.s.get(f'https://{current_instance.instance}/')
|
||||
set_http_header()
|
||||
|
||||
|
||||
@logger.catch
|
||||
def get_me():
|
||||
'''Return current user if token avalaible'''
|
||||
if not current_instance.token:
|
||||
return
|
||||
r = current_instance.s.get(f'https://{current_instance.instance}/api/v1/users/me')
|
||||
resp = r.json()
|
||||
current_instance.listen_token = resp['tokens']['listen']
|
||||
return resp
|
||||
|
||||
|
||||
@logger.catch
|
||||
@ -79,6 +89,11 @@ def get_audio_file(track_uuid, listen_url=False, download=False,
|
||||
"download": download,
|
||||
"to": to
|
||||
}
|
||||
if current_instance.token and not current_instance.listen_token:
|
||||
get_me()
|
||||
if current_instance.listen_token:
|
||||
params['token'] = current_instance.listen_token
|
||||
|
||||
if not transcoding:
|
||||
del params['to']
|
||||
if listen_url:
|
||||
|
@ -104,10 +104,6 @@ def universal_observer(_name, value):
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
def set_http_header(headers=[]):
|
||||
player.http_header_fields = headers
|
||||
|
||||
|
||||
@logger.catch
|
||||
def player_menu(header='', storage={}):
|
||||
player_fw_storage.storage.update(storage)
|
||||
|
Loading…
Reference in New Issue
Block a user