mirror of
http://gitea.phreedom.club/localhost_frssoft/funkwlmpv
synced 2024-11-30 04:41:27 +00:00
Compare commits
4 commits
5c3e459cfe
...
a4bf0f69c0
Author | SHA1 | Date | |
---|---|---|---|
localhost_frssoft | a4bf0f69c0 | ||
localhost_frssoft | b945793689 | ||
localhost_frssoft | 3ea5a1fcb9 | ||
localhost_frssoft | 9181923e52 |
|
@ -7,15 +7,17 @@ from loguru import logger
|
|||
fzf = FzfPrompt()
|
||||
|
||||
@logger.catch
|
||||
def list_albums(albums=None, pg=None, search=None, artist=None, include_channels=None):
|
||||
def list_albums(albums=None, pg=None, search=None, artist=None, include_channels=None, refresh=False):
|
||||
albums_next = None
|
||||
albums_prev = None
|
||||
play_artist_albums = False
|
||||
if not albums:
|
||||
albums = get_albums(q=search, artist=artist, include_channels=include_channels, pg=pg)
|
||||
albums = get_albums(q=search, artist=artist, include_channels=include_channels, refresh=refresh, pg=pg)
|
||||
albums_next = albums.get('next')
|
||||
albums_prev = albums.get('previous')
|
||||
albums_results = albums.get('results')
|
||||
if artist:
|
||||
play_artist_albums = True
|
||||
else:
|
||||
play_artist_albums = True
|
||||
albums_results = albums
|
||||
|
@ -40,7 +42,10 @@ def list_albums(albums=None, pg=None, search=None, artist=None, include_channels
|
|||
print('Search by albums: ')
|
||||
list_albums(search=input())
|
||||
elif select == 'Play all':
|
||||
src.fw_artists.play_artist(albums_results[0].get('artist'))
|
||||
if artist:
|
||||
src.fw_artists.play_artist(artist)
|
||||
else:
|
||||
src.fw_artists.play_artist(albums_results[0].get('artist'))
|
||||
else:
|
||||
play_album(album_id=albums_results[int(select)].get('id'))
|
||||
|
||||
|
|
|
@ -1,9 +1,27 @@
|
|||
from src.mpv_control import set_http_header
|
||||
import requests, json, time
|
||||
import os
|
||||
from loguru import logger
|
||||
|
||||
with open('.auth.json', 'rt') as f:
|
||||
auth = json.loads(f.read())
|
||||
auth_file = '.auth.json'
|
||||
if os.path.exists(auth_file):
|
||||
with open('.auth.json', 'rt') as f:
|
||||
auth = json.loads(f.read())
|
||||
else:
|
||||
# The default umask is 0o22 which turns off write permission of group and others
|
||||
os.umask(0)
|
||||
|
||||
descriptor = os.open(
|
||||
path=auth_file,
|
||||
flags=(
|
||||
os.O_WRONLY # access mode: write only
|
||||
| os.O_CREAT # create if not exists
|
||||
| os.O_TRUNC # truncate the file to zero
|
||||
),
|
||||
mode=0o600)
|
||||
with open(descriptor, 'wt') as f:
|
||||
f.write('{}')
|
||||
auth = {}
|
||||
|
||||
s = requests.Session()
|
||||
instance = 'fw.ponychord.rocks'
|
||||
|
@ -24,7 +42,7 @@ else:
|
|||
def select_instance(new_instance=None):
|
||||
global instance
|
||||
instance = new_instance
|
||||
with open('.auth.json', 'rt') as f:
|
||||
with open(auth_file, 'rt') as f:
|
||||
auth = json.loads(f.read())
|
||||
new_token = auth.get(instance)
|
||||
s.headers.update({"Authorization": None,
|
||||
|
@ -63,14 +81,15 @@ def get_tracks(page=None, q=None, artist=None, album=None, favourites=None, incl
|
|||
|
||||
|
||||
@logger.catch
|
||||
def get_artists(page=None, q=None, artist=None, album=None, favourites=None, pg=None):
|
||||
def get_artists(page=None, q=None, artist=None, album=None, favourites=None, refresh=False, pg=None):
|
||||
'''This function get artists by params'''
|
||||
params = {
|
||||
'page': page,
|
||||
'q': q,
|
||||
'artist': artist,
|
||||
'album': album,
|
||||
'favourites': favourites
|
||||
'favourites': favourites,
|
||||
'refresh': refresh
|
||||
}
|
||||
if pg:
|
||||
r = s.get(pg)
|
||||
|
@ -80,13 +99,14 @@ def get_artists(page=None, q=None, artist=None, album=None, favourites=None, pg=
|
|||
|
||||
|
||||
@logger.catch
|
||||
def get_albums(page=None, q=None, artist=None, include_channels=None, pg=None):
|
||||
def get_albums(page=None, q=None, artist=None, include_channels=None, refresh=False, pg=None):
|
||||
'''This function get artists by params'''
|
||||
params = {
|
||||
'page': page,
|
||||
'q': q,
|
||||
'artist': artist,
|
||||
'include_channels': include_channels
|
||||
'include_channels': include_channels,
|
||||
'refresh': refresh
|
||||
}
|
||||
if pg:
|
||||
r = s.get(pg)
|
||||
|
|
|
@ -35,11 +35,21 @@ def list_artists(pg=None, search=None):
|
|||
|
||||
|
||||
def play_artist(artist_id):
|
||||
tracks = get_tracks(artist=artist_id)
|
||||
tracks_results = tracks.get('results')
|
||||
tracks = get_tracks(artist=artist_id, include_channels=True, pg=None)
|
||||
tracks_next = tracks.get('next')
|
||||
tracks_count = tracks.get('count')
|
||||
storage = {}
|
||||
for i in tracks_results:
|
||||
listen_url = concatinate_endpoint(i.get('listen_url'))
|
||||
storage[listen_url] = i
|
||||
player.loadfile(listen_url, 'append-play')
|
||||
if tracks_count > 50:
|
||||
print(f'Loading {tracks_count} tracks...')
|
||||
while True:
|
||||
tracks_results = tracks.get('results')
|
||||
tracks_next = tracks.get('next')
|
||||
for i in tracks_results:
|
||||
listen_url = concatinate_endpoint(i.get('listen_url'))
|
||||
storage[listen_url] = i
|
||||
player.loadfile(listen_url, 'append-play')
|
||||
if tracks_next:
|
||||
tracks = get_tracks(artist=artist_id, include_channels=True, pg=tracks_next)
|
||||
else:
|
||||
break
|
||||
player_menu("Artist playing...", storage)
|
||||
|
|
|
@ -31,4 +31,7 @@ def list_channels(pg=None, search=None):
|
|||
print('Search by channel:')
|
||||
list_channels(search=input())
|
||||
else:
|
||||
list_albums(artist=channels_results[int(select)].get('artist').get('id'), include_channels=True)
|
||||
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)
|
||||
|
|
|
@ -13,13 +13,19 @@ def mpv_log(loglevel, component, message):
|
|||
elif loglevel == 'error':
|
||||
logger.error(f'{component} {message}')
|
||||
|
||||
player = mpv.MPV(log_handler=mpv_log, ytdl=False,
|
||||
prefetch_playlist=True)
|
||||
player = mpv.MPV(log_handler=mpv_log)
|
||||
|
||||
list_options = dir(player)
|
||||
if 'ytdl' in list_options:
|
||||
player.ytdl = False
|
||||
if 'prefetch_playlist' in list_options:
|
||||
player.prefetch_playlist = True
|
||||
|
||||
|
||||
def set_http_header(headers=[]):
|
||||
player.http_header_fields = headers
|
||||
|
||||
|
||||
@logger.catch
|
||||
def player_menu(header=None, storage={}):
|
||||
while True:
|
||||
|
|
Loading…
Reference in a new issue