mirror of
http://gitea.phreedom.club/localhost_frssoft/funkwlmpv
synced 2024-11-25 14:11:26 +00:00
Radios avalaible on unauthorized instances; Switching instances
This commit is contained in:
parent
f582c15c77
commit
080699c4c8
|
@ -7,12 +7,18 @@ fzf = FzfPrompt()
|
||||||
def main():
|
def main():
|
||||||
logger.remove()
|
logger.remove()
|
||||||
while True:
|
while True:
|
||||||
menu = ('Radios', )
|
menu = ('Radios', 'Switch instance' )
|
||||||
ids = fzf.prompt(menu)
|
ids = fzf.prompt(menu)
|
||||||
|
|
||||||
selected = ids[0]
|
selected = ids[0]
|
||||||
if selected == 'Radios':
|
if selected == 'Radios':
|
||||||
list_radios()
|
list_radios()
|
||||||
|
if selected == 'Switch instance':
|
||||||
|
with open('config.json', 'rt') as f:
|
||||||
|
conf = json.loads(f.read())
|
||||||
|
list_instances = conf.get('public_list_instances')
|
||||||
|
instance = fzf.prompt(list_instances, '--header \'Select instance\'')[0]
|
||||||
|
select_instance(instance)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -1,30 +1,70 @@
|
||||||
|
from src.mpv_control import player
|
||||||
import requests, json, time
|
import requests, json, time
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
with open('.auth.json', 'rt') as f:
|
with open('.auth.json', 'rt') as f:
|
||||||
auth = json.loads(f.read())
|
auth = json.loads(f.read())
|
||||||
|
|
||||||
|
s = requests.Session()
|
||||||
instance = 'fw.ponychord.rocks'
|
instance = 'fw.ponychord.rocks'
|
||||||
headers= {
|
token = auth.get(instance)
|
||||||
"Authorization": "Bearer " + auth.get('fw.ponychord.rocks')
|
|
||||||
}
|
if token:
|
||||||
|
s.headers.update = {
|
||||||
|
"Authorization": "Bearer " + token
|
||||||
|
}
|
||||||
|
player.http_header_fields = ['Authorization: ' + 'Bearer ' + token]
|
||||||
|
else:
|
||||||
|
s.get(f'https://{instance}/') # Get cookies from unauthorized instance for working some functionality (radios)
|
||||||
|
player.http_header_fields = []
|
||||||
|
|
||||||
|
|
||||||
|
def select_instance(new_instance=None):
|
||||||
|
global instance
|
||||||
|
instance = new_instance
|
||||||
|
new_token = auth.get(instance)
|
||||||
|
s.headers.update = {}
|
||||||
|
player.http_header_fields = []
|
||||||
|
if new_token:
|
||||||
|
s.get(f'https://{instance}')
|
||||||
|
s.headers.update = {
|
||||||
|
"Authorization": "Bearer " + new_token
|
||||||
|
}
|
||||||
|
player.http_header_fields = ['Authorization: ' + 'Bearer ' + new_token]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def concatinate_endpoint(endpoint):
|
def concatinate_endpoint(endpoint):
|
||||||
return 'https://' + instance + endpoint
|
return 'https://' + instance + endpoint
|
||||||
|
|
||||||
|
|
||||||
|
def list_tracks(page=None, q=None, artist=None, album=None, favourites=None):
|
||||||
|
'''This function get tracks by params'''
|
||||||
|
params = {
|
||||||
|
'page': page,
|
||||||
|
'q': q,
|
||||||
|
'artist': artist,
|
||||||
|
'album': album,
|
||||||
|
'favourites': favourites
|
||||||
|
}
|
||||||
|
|
||||||
|
r = requests.get(f'https://{instance}/api/v1/tracks', params)
|
||||||
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
# [FunkWhale radios]
|
# [FunkWhale radios]
|
||||||
def get_radios():
|
def get_radios():
|
||||||
r = requests.get(f'https://{instance}/api/v1/radios/radios/', headers=headers)
|
r = s.get(f'https://{instance}/api/v1/radios/radios/')
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
def post_radio_session(requested_radio):
|
def post_radio_session(requested_radio):
|
||||||
r = requests.post(f'https://{instance}/api/v1/radios/sessions/', json=requested_radio, headers=headers)
|
r = s.post(f'https://{instance}/api/v1/radios/sessions/', json=requested_radio)
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
def get_track_radio(radio_session):
|
def get_track_radio(radio_session):
|
||||||
r = requests.post(f'https://{instance}/api/v1/radios/tracks/',json=radio_session, headers=headers)
|
r = s.post(f'https://{instance}/api/v1/radios/tracks/',json=radio_session)
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
from src.fw_api import headers
|
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
import mpv
|
import mpv
|
||||||
|
|
||||||
|
@ -10,5 +9,4 @@ def mpv_log(loglevel, component, message):
|
||||||
logger.error(f'{component} {message}')
|
logger.error(f'{component} {message}')
|
||||||
|
|
||||||
player = mpv.MPV(log_handler=mpv_log, ytdl=False)
|
player = mpv.MPV(log_handler=mpv_log, ytdl=False)
|
||||||
player.http_header_fields = ['Authorization: ' + headers.get('Authorization')]
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue