funkwlmpv/src/fw_channels.py

38 lines
1.2 KiB
Python

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:
refresh = False
if channels_results[int(select)].get('artist').get('is_local') == False:
refresh = True
list_albums(artist=channels_results[int(select)].get('artist').get('id'), include_channels=True, refresh=refresh)