Compare commits

..

No commits in common. "9c65117e9c6452b13cb7ca1859004987d23a4ea5" and "220717d522e72bd7233a8ee7ee3bab7fb83be85b" have entirely different histories.

5 changed files with 14 additions and 50 deletions

4
funkwhale_cli.py Executable file → Normal file
View File

@ -1,5 +1,3 @@
#!/usr/bin/env python3
from src.fw_api import current_instance, federate_search_by_url, get_instance_settings from src.fw_api import current_instance, federate_search_by_url, get_instance_settings
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
@ -87,7 +85,7 @@ def main():
If You want sign in, please visit: If You want sign in, please visit:
https://{instance}/settings/applications/new https://{instance}/settings/applications/new
And fill Name funkwhale-cli And fill Name funkwhale-cli
Scopes: Read, Write (optional): write:favorites write:listenings write:filters Scopes: Read (only listen music), Write (optional)
Insert token from "Access token" here''') Insert token from "Access token" here''')
register_token = input() register_token = input()

View File

@ -228,16 +228,6 @@ def federate_search_by_url(object):
} }
r = current_instance.s.post(f'https://{current_instance.instance}/api/v1/federation/fetches', json=params) r = current_instance.s.post(f'https://{current_instance.instance}/api/v1/federation/fetches', json=params)
return r.json() return r.json()
@logger.catch
def record_track_in_history(track_id):
params = {
'track': int(track_id)
}
r = current_instance.s.post(f'https://{current_instance.instance}/api/v1/history/listenings', json=params)
r.raise_for_status()
return r.json
@logger.catch @logger.catch

View File

@ -2,7 +2,7 @@ from src.fw_api import current_instance, get_radios, post_radio_session, get_tra
from src.fw_libraries import libraries from src.fw_libraries import libraries
from src.fw_tags import list_tags from src.fw_tags import list_tags
from src.utils import download_track from src.utils import download_track
from src.mpv_control import player, track_url_to_uuid, player_fw_storage from src.mpv_control import player, track_url_to_uuid
from src.settings import get_config from src.settings import get_config
from pyfzf.pyfzf import FzfPrompt from pyfzf.pyfzf import FzfPrompt
from loguru import logger from loguru import logger
@ -11,6 +11,7 @@ import time
fzf = FzfPrompt() fzf = FzfPrompt()
audio_info = {}
@logger.catch @logger.catch
def list_radios(): def list_radios():
@ -130,7 +131,7 @@ def radio_load(id_radio=None, type_radio='custom', name=None, related_object=Non
name_downloaded = download_track(player.stream_open_filename) name_downloaded = download_track(player.stream_open_filename)
print(f'Downloaded: {name_downloaded}') print(f'Downloaded: {name_downloaded}')
elif select == 'Info': elif select == 'Info':
track = player_fw_storage.storage.get(track_url_to_uuid()) track = audio_info.get(track_url_to_uuid())
for i in ('title', 'fid', 'license', 'album', 'artist'): for i in ('title', 'fid', 'license', 'album', 'artist'):
if i in ('album', 'artist'): if i in ('album', 'artist'):
name_aa = track.get(i).get('name') name_aa = track.get(i).get('name')
@ -142,7 +143,7 @@ def radio_load(id_radio=None, type_radio='custom', name=None, related_object=Non
print(i + ': ' + key) print(i + ': ' + key)
input() input()
elif select == 'Like': elif select == 'Like':
favorite_track(player_fw_storage.storage.get(track_url_to_uuid())['id']) favorite_track(audio_info.get(track_url_to_uuid())['id'])
elif select == 'Exit': elif select == 'Exit':
try: try:
radio_event_gen.clear() radio_event_gen.clear()
@ -151,7 +152,6 @@ def radio_load(id_radio=None, type_radio='custom', name=None, related_object=Non
pass pass
player.playlist_clear() player.playlist_clear()
player.stop() player.stop()
player_fw_storage.storage = {}
break break
except: except:
try: try:
@ -161,7 +161,6 @@ def radio_load(id_radio=None, type_radio='custom', name=None, related_object=Non
pass pass
player.playlist_clear() player.playlist_clear()
player.stop() player.stop()
player_fw_storage.storage = {}
logger.exception('Radio force stopped') logger.exception('Radio force stopped')
break break
@ -181,7 +180,7 @@ def radio_get_track(radio_session_id):
else: else:
track = radio_context.get('track') track = radio_context.get('track')
listen_url = track['listen_url'] listen_url = track['listen_url']
player_fw_storage.storage[track_url_to_uuid(listen_url)] = track audio_info[track_url_to_uuid(listen_url)] = track
player.loadfile(get_audio_file(listen_url, listen_url=True), 'append-play') player.loadfile(get_audio_file(listen_url, listen_url=True), 'append-play')

View File

@ -4,7 +4,6 @@ from src.settings import get_config
from loguru import logger from loguru import logger
from pyfzf.pyfzf import FzfPrompt from pyfzf.pyfzf import FzfPrompt
import mpv import mpv
import time
fzf = FzfPrompt() fzf = FzfPrompt()
@ -12,14 +11,16 @@ player = mpv.MPV()
player.ytdl = False # Prevent attempts load track with yt-dlp player.ytdl = False # Prevent attempts load track with yt-dlp
player.prefetch_playlist = get_config('prefetch_playlist') # Fast loading next track, but high network traffic player.prefetch_playlist = get_config('prefetch_playlist') # Fast loading next track, but high network traffic
show_like_button = get_config('show_like_button') show_like_button = get_config('show_like_button')
track_activity_history = get_config('track_activity_history')
class player_fw_storage: class player_fw_storage:
storage = {} storage = {}
@logger.catch def set_http_header(headers=[]):
player.http_header_fields = headers
def track_url_to_uuid(listen_url=None): def track_url_to_uuid(listen_url=None):
'''Attempt get uuid from track listen url or current playing url''' '''Attempt get uuid from track listen url or current playing url'''
if listen_url: if listen_url:
@ -29,31 +30,9 @@ def track_url_to_uuid(listen_url=None):
return uuid return uuid
if track_activity_history:
@player.property_observer('time-pos')
@logger.catch
def time_observer(_name, value):
# Here, _value is either None if nothing is playing or a float containing
# fractional seconds since the beginning of the file.
if value and player.http_header_fields != []:
if value >= 30.0 and value <= 30.1:
# detect 30 secs for reporting listen activity
track = player_fw_storage.storage.get(track_url_to_uuid())
track_id = track.get('id')
if track_id:
src.fw_api.record_track_in_history(track_id)
else:
logger.error("Can't write track to history: No track id")
time.sleep(1)
def set_http_header(headers=[]):
player.http_header_fields = headers
@logger.catch @logger.catch
def player_menu(header='', storage={}): def player_menu(header='', storage={}):
player_fw_storage.storage.update(storage) player_fw_storage.storage = storage
player.volume = get_config("mpv_volume") player.volume = get_config("mpv_volume")
while True: while True:
try: try:
@ -82,7 +61,7 @@ def player_menu(header='', storage={}):
name_downloaded = download_track(player.stream_open_filename) name_downloaded = download_track(player.stream_open_filename)
print(f'Downloaded: {name_downloaded}') print(f'Downloaded: {name_downloaded}')
elif select == 'Info': elif select == 'Info':
track = player_fw_storage.storage.get(track_url_to_uuid()) track = storage.get(track_url_to_uuid())
for i in track.keys(): for i in track.keys():
if i in ('album', 'artist'): if i in ('album', 'artist'):
name_aa = track.get(i).get('name') name_aa = track.get(i).get('name')
@ -94,14 +73,13 @@ def player_menu(header='', storage={}):
print(i + ': ' + key) print(i + ': ' + key)
input() input()
elif select == 'Like': elif select == 'Like':
src.fw_api.favorite_track(player_fw_storage.storage.get(track_url_to_uuid())['id']) src.fw_api.favorite_track(storage.get(track_url_to_uuid())['id'])
elif select == 'Hide artist': elif select == 'Hide artist':
track = player_fw_storage.storage.get(track_url_to_uuid()) track = storage.get(track_url_to_uuid())
src.fw_api.hide_content({'target': {'id': track.get('artist').get('id'), 'type': 'artist'}}) src.fw_api.hide_content({'target': {'id': track.get('artist').get('id'), 'type': 'artist'}})
elif select == 'Exit': elif select == 'Exit':
player.playlist_clear() player.playlist_clear()
player.stop() player.stop()
player_fw_storage.storage = {}
break break
except KeyboardInterrupt: except KeyboardInterrupt:
break break

View File

@ -39,7 +39,6 @@ default_conf = {
"shitnoise.monster" "shitnoise.monster"
], ],
'enable_server_transcoding': False, 'enable_server_transcoding': False,
'track_activity_history': False,
'prefetch_playlist': True, 'prefetch_playlist': True,
'mpv_volume': 100, 'mpv_volume': 100,
'show_like_button': True, 'show_like_button': True,