mirror of
https://gitea.phreedom.club/localhost_frssoft/funkwlmpv
synced 2024-11-27 17:43:02 +00:00
'Bare bones' channels support; added federated search by url (scrapped from network monitor inspector)
This commit is contained in:
parent
ff26263496
commit
5c3e459cfe
@ -1,7 +1,8 @@
|
|||||||
from src.fw_api import s, select_instance, instance
|
from src.fw_api import s, select_instance, instance, federate_search_by_url
|
||||||
from src.fw_radios import list_radios
|
from src.fw_radios import list_radios
|
||||||
from src.fw_artists import list_artists
|
from src.fw_artists import list_artists
|
||||||
from src.fw_albums import list_albums
|
from src.fw_albums import list_albums
|
||||||
|
from src.fw_channels import list_channels
|
||||||
import json, sys
|
import json, sys
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
from pyfzf.pyfzf import FzfPrompt
|
from pyfzf.pyfzf import FzfPrompt
|
||||||
@ -13,10 +14,14 @@ def main():
|
|||||||
logger.add(sys.stderr, filter='src.fw_api')
|
logger.add(sys.stderr, filter='src.fw_api')
|
||||||
logger.add(sys.stderr, filter='src.fw_radios')
|
logger.add(sys.stderr, filter='src.fw_radios')
|
||||||
logger.add(sys.stderr, filter='src.fw_artists')
|
logger.add(sys.stderr, filter='src.fw_artists')
|
||||||
|
logger.add(sys.stderr, filter='src.fw_albums')
|
||||||
|
logger.add(sys.stderr, filter='src.fw_channels')
|
||||||
while True:
|
while True:
|
||||||
menu = ['Radios',
|
menu = ['Radios',
|
||||||
'Artists',
|
'Artists',
|
||||||
'Albums',
|
'Albums',
|
||||||
|
'Channels',
|
||||||
|
'Search',
|
||||||
'Switch instance']
|
'Switch instance']
|
||||||
if not s.headers.get('Authorization'):
|
if not s.headers.get('Authorization'):
|
||||||
menu.append('Sign in')
|
menu.append('Sign in')
|
||||||
@ -29,6 +34,14 @@ def main():
|
|||||||
list_artists()
|
list_artists()
|
||||||
if selected == 'Albums':
|
if selected == 'Albums':
|
||||||
list_albums()
|
list_albums()
|
||||||
|
if selected == 'Channels':
|
||||||
|
list_channels()
|
||||||
|
if selected == 'Search':
|
||||||
|
search_type = fzf.prompt(('Federated', 'All types'))[0]
|
||||||
|
if search_type == 'Federated':
|
||||||
|
print('Input url:')
|
||||||
|
returned_obj = federate_search_by_url(input())
|
||||||
|
|
||||||
if selected == 'Switch instance':
|
if selected == 'Switch instance':
|
||||||
with open('config.json', 'rt') as f:
|
with open('config.json', 'rt') as f:
|
||||||
conf = json.loads(f.read())
|
conf = json.loads(f.read())
|
||||||
|
@ -7,12 +7,12 @@ from loguru import logger
|
|||||||
fzf = FzfPrompt()
|
fzf = FzfPrompt()
|
||||||
|
|
||||||
@logger.catch
|
@logger.catch
|
||||||
def list_albums(albums=None, pg=None, search=None):
|
def list_albums(albums=None, pg=None, search=None, artist=None, include_channels=None):
|
||||||
albums_next = None
|
albums_next = None
|
||||||
albums_prev = None
|
albums_prev = None
|
||||||
play_artist_albums = False
|
play_artist_albums = False
|
||||||
if not albums:
|
if not albums:
|
||||||
albums = get_albums(q=search, pg=pg)
|
albums = get_albums(q=search, artist=artist, include_channels=include_channels, pg=pg)
|
||||||
albums_next = albums.get('next')
|
albums_next = albums.get('next')
|
||||||
albums_prev = albums.get('previous')
|
albums_prev = albums.get('previous')
|
||||||
albums_results = albums.get('results')
|
albums_results = albums.get('results')
|
||||||
@ -46,7 +46,7 @@ def list_albums(albums=None, pg=None, search=None):
|
|||||||
|
|
||||||
|
|
||||||
def play_album(album_id):
|
def play_album(album_id):
|
||||||
tracks = get_tracks(album=album_id)
|
tracks = get_tracks(album=album_id, include_channels=True)
|
||||||
tracks_results = tracks.get('results')
|
tracks_results = tracks.get('results')
|
||||||
storage = {}
|
storage = {}
|
||||||
for i in tracks_results:
|
for i in tracks_results:
|
||||||
|
@ -45,14 +45,15 @@ def concatinate_endpoint(endpoint):
|
|||||||
|
|
||||||
|
|
||||||
@logger.catch
|
@logger.catch
|
||||||
def get_tracks(page=None, q=None, artist=None, album=None, favourites=None, pg=None):
|
def get_tracks(page=None, q=None, artist=None, album=None, favourites=None, include_channels=None, pg=None):
|
||||||
'''This function get tracks by params'''
|
'''This function get tracks by params'''
|
||||||
params = {
|
params = {
|
||||||
'page': page,
|
'page': page,
|
||||||
'q': q,
|
'q': q,
|
||||||
'artist': artist,
|
'artist': artist,
|
||||||
'album': album,
|
'album': album,
|
||||||
'favourites': favourites
|
'favourites': favourites,
|
||||||
|
'include_channels': include_channels
|
||||||
}
|
}
|
||||||
if pg:
|
if pg:
|
||||||
r = s.get(pg)
|
r = s.get(pg)
|
||||||
@ -79,12 +80,13 @@ def get_artists(page=None, q=None, artist=None, album=None, favourites=None, pg=
|
|||||||
|
|
||||||
|
|
||||||
@logger.catch
|
@logger.catch
|
||||||
def get_albums(page=None, q=None, artist=None, pg=None):
|
def get_albums(page=None, q=None, artist=None, include_channels=None, pg=None):
|
||||||
'''This function get artists by params'''
|
'''This function get artists by params'''
|
||||||
params = {
|
params = {
|
||||||
'page': page,
|
'page': page,
|
||||||
'q': q,
|
'q': q,
|
||||||
'artist': artist
|
'artist': artist,
|
||||||
|
'include_channels': include_channels
|
||||||
}
|
}
|
||||||
if pg:
|
if pg:
|
||||||
r = s.get(pg)
|
r = s.get(pg)
|
||||||
@ -93,6 +95,20 @@ def get_albums(page=None, q=None, artist=None, pg=None):
|
|||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
|
@logger.catch
|
||||||
|
def get_channels(page=None, q=None, tag=None, pg=None):
|
||||||
|
params = {
|
||||||
|
'page': page,
|
||||||
|
'q': q,
|
||||||
|
'tag': tag
|
||||||
|
}
|
||||||
|
if pg:
|
||||||
|
r = s.get(pg)
|
||||||
|
else:
|
||||||
|
r = s.get(f'https://{instance}/api/v1/channels', params=params)
|
||||||
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
@logger.catch
|
@logger.catch
|
||||||
def list_libraries(page=None, page_size=None, q=None, scope='all', pg=None):
|
def list_libraries(page=None, page_size=None, q=None, scope='all', pg=None):
|
||||||
params = {
|
params = {
|
||||||
@ -108,6 +124,15 @@ def list_libraries(page=None, page_size=None, q=None, scope='all', pg=None):
|
|||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
|
@logger.catch
|
||||||
|
def federate_search_by_url(object):
|
||||||
|
params = {
|
||||||
|
'object': object
|
||||||
|
}
|
||||||
|
r = s.post(f'https://{instance}/api/v1/federation/fetches', json=params)
|
||||||
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
@logger.catch
|
@logger.catch
|
||||||
def favorite_track(track_id):
|
def favorite_track(track_id):
|
||||||
r = s.post(f'https://{instance}/api/v1/favorites/tracks', json={'track': int(track_id)})
|
r = s.post(f'https://{instance}/api/v1/favorites/tracks', json={'track': int(track_id)})
|
||||||
|
34
src/fw_channels.py
Normal file
34
src/fw_channels.py
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
from src.fw_api import get_channels
|
||||||
|
from src.fw_albums import list_albums
|
||||||
|
from loguru import logger
|
||||||
|
from pyfzf.pyfzf import FzfPrompt
|
||||||
|
|
||||||
|
fzf = FzfPrompt()
|
||||||
|
|
||||||
|
|
||||||
|
@logger.catch
|
||||||
|
def list_channels(pg=None, search=None):
|
||||||
|
channels = get_channels(q=search, pg=pg)
|
||||||
|
channels_next = channels.get('next')
|
||||||
|
channels_prev = channels.get('previous')
|
||||||
|
channels_results = channels.get('results')
|
||||||
|
view = ['Search']
|
||||||
|
if channels_next:
|
||||||
|
view.append('Next page')
|
||||||
|
if channels_prev:
|
||||||
|
view.append('Prev page')
|
||||||
|
|
||||||
|
for i in channels_results:
|
||||||
|
index = channels_results.index(i)
|
||||||
|
channel_name = i.get('artist').get('name')
|
||||||
|
view.append(f'{index}.{channel_name}')
|
||||||
|
select = fzf.prompt(view)[0].split('.', 1)[0]
|
||||||
|
if select == 'Next page':
|
||||||
|
list_channels(pg=channels_next)
|
||||||
|
elif select == 'Prev page':
|
||||||
|
list_channels(pg=channels_prev)
|
||||||
|
elif select == 'Search':
|
||||||
|
print('Search by channel:')
|
||||||
|
list_channels(search=input())
|
||||||
|
else:
|
||||||
|
list_albums(artist=channels_results[int(select)].get('artist').get('id'), include_channels=True)
|
Loading…
Reference in New Issue
Block a user