Created
May 15, 2020 14:30
-
-
Save cosven/9fa5f5f9a376b6495b04a081d77b4e05 to your computer and use it in GitHub Desktop.
右键找相似
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def add_download_action(ctx): | |
from fuocore import aio | |
from fuocore.models import ModelType, SearchType | |
global app | |
def sample(models): | |
for model in models: | |
if model.meta.model_type == ModelType.song: | |
print(str(model)) | |
def find_similar(models): | |
if not models or models[0].meta.model_type != ModelType.song: | |
return | |
song = models[0] | |
title = song.title_display | |
artist = song.artists_name_display | |
sources = [] | |
for provider in app.library.list(): | |
if provider.identifier == song.source: | |
continue | |
sources.append(provider.identifier) | |
query = {'source_in': ','.join(sources), | |
'type': SearchType.so.value, | |
'q': f'{title} {artist}'} | |
app.browser.goto(uri='/search', query=query) | |
add_action = ctx['add_action'] | |
add_action('下载歌曲', sample) | |
add_action('搜索类似', find_similar) | |
when('app.ui.songs_table.about_to_show_menu', add_download_action, use_symbol=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment