Tags added

This commit is contained in:
localhost_frssoft 2022-11-30 03:17:18 +03:00
parent 3124613c3a
commit 5d23553dd3
3 changed files with 54 additions and 4 deletions

View file

@ -83,13 +83,15 @@ def get_audio_file(track_uuid, listen_url=False, download=False,
@logger.catch
def get_tracks(page=None, q=None, artist=None, album=None, favourites=None, include_channels=None, pg=None):
def get_tracks(page=None, q=None, artist=None, album=None,
tag=None, favourites=None, include_channels=None, pg=None):
'''This function get tracks by params'''
params = {
'page': page,
'q': q,
'artist': artist,
'album': album,
'tag': tag,
'favourites': favourites,
'include_channels': include_channels
}
@ -206,6 +208,17 @@ def list_libraries(page=None, page_size=None, q=None, scope='all', pg=None):
r = s.get(f'https://{instance}/api/v1/libraries', params=params)
return r.json()
@logger.catch
def get_tags(q=None, pg=None):
params = {
'q': q,
}
if pg:
r = s.get(pg)
else:
r = s.get(f'https://{instance}/api/v1/tags', params=params)
return r.json()
@logger.catch
def federate_search_by_url(object):

33
src/fw_tags.py Normal file
View file

@ -0,0 +1,33 @@
from src.fw_api import get_tags
from pyfzf.pyfzf import FzfPrompt
from loguru import logger
fzf = FzfPrompt()
@logger.catch
def list_tags(pg=None, search=None):
tags = get_tags(q=search, pg=pg)
tags_next = tags.get('next')
tags_prev = tags.get('previous')
tags_results = tags.get('results')
view = ['Search']
if tags_next:
view.append('Next page')
if tags_prev:
view.append('Prev page')
for i in tags_results:
index = tags_results.index(i)
tag_name = i.get('name')
view.append(f'{index}.{tag_name}')
select = fzf.prompt(view)[0].split('.', 1)[0]
if select == 'Next page':
list_tags(pg=tags_next)
elif select == 'Prev page':
list_tags(pg=tags_prev)
elif select == 'Search':
print('Search by tag:')
list_tags(search=input())
else:
return tags_results[int(select)].get('name')

View file

@ -1,4 +1,5 @@
from src.fw_api import get_tracks, get_audio_file
from src.fw_tags import list_tags
from src.mpv_control import player, player_menu, track_url_to_uuid
from pyfzf.pyfzf import FzfPrompt
from loguru import logger
@ -6,12 +7,12 @@ from loguru import logger
fzf = FzfPrompt()
@logger.catch
def list_tracks(pg=None, search=None):
tracks = get_tracks(q=search, pg=pg)
def list_tracks(pg=None, search=None, tag=None):
tracks = get_tracks(q=search, pg=pg, tag=tag)
tracks_next = tracks.get('next')
tracks_prev = tracks.get('previous')
tracks_results = tracks.get('results')
view = ['Search']
view = ['Search', 'Tags']
if tracks_next:
view.append('Next page')
if tracks_prev:
@ -29,6 +30,9 @@ def list_tracks(pg=None, search=None):
elif select == 'Search':
print('Search by track:')
list_tracks(search=input())
elif select == 'Tags':
select_tag = list_tags()
list_tracks(tag=select_tag)
else:
play_track(track=tracks_results[int(select)])