mirror of
https://gitea.phreedom.club/localhost_frssoft/funkwlmpv
synced 2024-12-23 00:03:33 +02:00
Automatically follow on library when adding
This commit is contained in:
parent
adfa00aeb4
commit
35879ac63e
3 changed files with 38 additions and 5 deletions
|
@ -106,7 +106,13 @@ def main():
|
|||
If You want sign in, please visit:
|
||||
https://{current_instance.instance}/settings/applications/new
|
||||
And fill Name funkwhale-cli
|
||||
Scopes: Read, Write (optional): write:favorites write:listenings write:filters
|
||||
Scopes:
|
||||
Read | Write (optional):
|
||||
write:libraries
|
||||
write:favorites
|
||||
write:listenings
|
||||
write:follows
|
||||
write:filters
|
||||
|
||||
Insert token from "Access token" here''')
|
||||
register_token = input()
|
||||
|
|
|
@ -306,11 +306,10 @@ def federate_remote_library(fid):
|
|||
|
||||
@logger.catch
|
||||
def scan_remote_library(uuid):
|
||||
'''Scan remote library'''
|
||||
for i in range(attempts_for_federate):
|
||||
try:
|
||||
r = current_instance.s.post(
|
||||
f'https://{current_instance.instance}/api/v1/federation/libraries/{uuid}')
|
||||
f'https://{current_instance.instance}/api/v1/federation/libraries/{uuid}/scan')
|
||||
r.raise_for_status()
|
||||
break
|
||||
except Exception as Err:
|
||||
|
@ -319,6 +318,30 @@ def scan_remote_library(uuid):
|
|||
return r.json()
|
||||
|
||||
|
||||
@logger.catch
|
||||
def follow_on_remote_library(uuid):
|
||||
params = {'target': uuid}
|
||||
for i in range(attempts_for_federate):
|
||||
try:
|
||||
r = current_instance.s.post(
|
||||
f'https://{current_instance.instance}/api/v1/federation/follows/library/',
|
||||
json=params)
|
||||
r.raise_for_status()
|
||||
break
|
||||
except Exception as Err:
|
||||
logger.error(f'Attempt follow {i}: {Err}')
|
||||
time.sleep(3)
|
||||
return r.json()
|
||||
|
||||
|
||||
@logger.catch
|
||||
def unfollow_remote_library(uuid):
|
||||
r = current_instance.s.delete(
|
||||
f'https://{current_instance.instance}/api/v1/federation/follows/library/{uuid}/')
|
||||
r.raise_for_status()
|
||||
return r.json()
|
||||
|
||||
|
||||
@logger.catch
|
||||
def record_track_in_history(track_id):
|
||||
params = {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from src.fw_api import current_instance, list_libraries, federate_remote_library, scan_remote_library
|
||||
from src.fw_api import current_instance, list_libraries, federate_remote_library, scan_remote_library, follow_on_remote_library
|
||||
from pyfzf.pyfzf import FzfPrompt
|
||||
from loguru import logger
|
||||
import time
|
||||
|
@ -41,13 +41,17 @@ def libraries(pg=None, radio=False):
|
|||
return libraries(pg=libs_prev)
|
||||
elif lib_select[0] == 'Add remote library':
|
||||
print('Search a remote library (url\\fid):')
|
||||
new_library = federate_remote_library(input())
|
||||
new_library = federate_remote_library(input().strip())
|
||||
if new_library.get('detail'):
|
||||
logger.error(new_library['detail'])
|
||||
return
|
||||
if new_library.get('count') > 0:
|
||||
print('Library found')
|
||||
one_lib = new_library['results'][0]
|
||||
if one_lib['privacy_level'] == 'private':
|
||||
logger.warning('This library is private, you should wait until your request is approved')
|
||||
|
||||
follow_on_remote_library(one_lib['uuid'])
|
||||
scan = scan_remote_library(one_lib['uuid'])
|
||||
if scan.get('detail'):
|
||||
logger.error(scan['detail'])
|
||||
|
|
Loading…
Reference in a new issue