mirror of
https://gitea.phreedom.club/localhost_frssoft/funkwlmpv
synced 2024-12-22 13:49:48 +00:00
Automatically follow on library when adding
This commit is contained in:
parent
adfa00aeb4
commit
35879ac63e
@ -106,7 +106,13 @@ def main():
|
|||||||
If You want sign in, please visit:
|
If You want sign in, please visit:
|
||||||
https://{current_instance.instance}/settings/applications/new
|
https://{current_instance.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 | Write (optional):
|
||||||
|
write:libraries
|
||||||
|
write:favorites
|
||||||
|
write:listenings
|
||||||
|
write:follows
|
||||||
|
write:filters
|
||||||
|
|
||||||
Insert token from "Access token" here''')
|
Insert token from "Access token" here''')
|
||||||
register_token = input()
|
register_token = input()
|
||||||
|
@ -306,11 +306,10 @@ def federate_remote_library(fid):
|
|||||||
|
|
||||||
@logger.catch
|
@logger.catch
|
||||||
def scan_remote_library(uuid):
|
def scan_remote_library(uuid):
|
||||||
'''Scan remote library'''
|
|
||||||
for i in range(attempts_for_federate):
|
for i in range(attempts_for_federate):
|
||||||
try:
|
try:
|
||||||
r = current_instance.s.post(
|
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()
|
r.raise_for_status()
|
||||||
break
|
break
|
||||||
except Exception as Err:
|
except Exception as Err:
|
||||||
@ -319,6 +318,30 @@ def scan_remote_library(uuid):
|
|||||||
return r.json()
|
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
|
@logger.catch
|
||||||
def record_track_in_history(track_id):
|
def record_track_in_history(track_id):
|
||||||
params = {
|
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 pyfzf.pyfzf import FzfPrompt
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
import time
|
import time
|
||||||
@ -41,13 +41,17 @@ def libraries(pg=None, radio=False):
|
|||||||
return libraries(pg=libs_prev)
|
return libraries(pg=libs_prev)
|
||||||
elif lib_select[0] == 'Add remote library':
|
elif lib_select[0] == 'Add remote library':
|
||||||
print('Search a remote library (url\\fid):')
|
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'):
|
if new_library.get('detail'):
|
||||||
logger.error(new_library['detail'])
|
logger.error(new_library['detail'])
|
||||||
return
|
return
|
||||||
if new_library.get('count') > 0:
|
if new_library.get('count') > 0:
|
||||||
print('Library found')
|
print('Library found')
|
||||||
one_lib = new_library['results'][0]
|
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'])
|
scan = scan_remote_library(one_lib['uuid'])
|
||||||
if scan.get('detail'):
|
if scan.get('detail'):
|
||||||
logger.error(scan['detail'])
|
logger.error(scan['detail'])
|
||||||
|
Loading…
Reference in New Issue
Block a user