Skip to content

Commit

Permalink
adapt to the latest FeelUOwn (though all kuwo API are invalid)
Browse files Browse the repository at this point in the history
  • Loading branch information
cosven committed Jan 3, 2024
1 parent abbc239 commit 224f979
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 116 deletions.
8 changes: 4 additions & 4 deletions fuo_kuwo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
from feeluown.app import App

from .provider import provider
from .ui import KuwoUiManager

ui_mgr = None


def enable(app: App):
global ui_mgr
app.library.register(provider)
if app.mode & App.GuiMode:
ui_mgr = ui_mgr or KuwoUiManager(app)
from .ui import ProviderUi

provider_ui = ProviderUi(app)
app.pvd_ui_mgr.register(provider_ui)


def disable(app: App):
Expand Down
Empty file removed fuo_kuwo/pages/__init__.py
Empty file.
82 changes: 0 additions & 82 deletions fuo_kuwo/pages/explorer.py

This file was deleted.

6 changes: 5 additions & 1 deletion fuo_kuwo/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ class KuwoProvider(
):
api: KuwoApi

class meta:
identifier: str = __identifier__
name: str = __alias__

def __init__(self):
super().__init__()
self.api = KuwoApi()
Expand Down Expand Up @@ -72,7 +76,7 @@ def current_user_playlists(self):
return [_deserialize(data_playlist, KuwoUserPlaylistSchema)
for data_playlist in data_playlists]

def current_user_rec_playlists(self):
def rec_list_daily_playlists(self):
data_playlists = self.api.playlist_recommend(20, 1)
return [_deserialize(data_playlist, KuwoPlaylistSchema)
for data_playlist in data_playlists.get('data', {}).get('list', [])]
Expand Down
40 changes: 12 additions & 28 deletions fuo_kuwo/ui.py
Original file line number Diff line number Diff line change
@@ -1,60 +1,44 @@
import json
import os
from pathlib import Path

from feeluown.consts import DATA_DIR
from feeluown.library import BriefUserModel
from feeluown.gui.widgets import CookiesLoginDialog
from feeluown.gui.widgets.login import InvalidCookies
from feeluown.uimodels.provider import ProviderUiManager
from feeluown.utils import aio
from feeluown.gui.provider_ui import AbstractProviderUi

from . import __identifier__, __alias__
from .provider import provider

USER_INFO_FILE = DATA_DIR + '/kuwo_music_user_session.json'


class KuwoUiManager:
class ProviderUi(AbstractProviderUi):
def __init__(self, app):
self._app = app
self._pvd_uimgr: ProviderUiManager = app.pvd_uimgr
self._pvd_item = self._pvd_uimgr.create_item(
name='kuwo',
text=__alias__,
symbol='♫ ',
desc='点击登录',
colorful_svg=str(Path(__file__).resolve().parent / 'assets' / 'icon.svg'))
self._pvd_item.clicked.connect(self.login_or_show)
self._pvd_uimgr.add_item(self._pvd_item)
self.initialize()

def login_or_show(self):

@property
def provider(self):
return provider

def get_colorful_svg(self) -> str:
return os.path.join(os.path.dirname(__file__), 'assets', 'icon.svg')

def login_or_go_home(self):
if provider.user is None:
dialog = LoginDialog()
self._dialog = dialog = LoginDialog()
dialog.login_succeed.connect(lambda: aio.run_afn(self.load_user))
dialog.show()
dialog.autologin()
else:
aio.run_afn(self.load_user)

def initialize(self):
from .pages.explorer import render as explore_render # noqa
self._app.browser.route('/providers/kuwo/explore')(explore_render)

async def load_user(self):
self._app.ui.left_panel.my_music_con.show()
self._app.ui.left_panel.playlists_con.show()
self._app.pl_uimgr.clear()
user_playlists = await aio.run_fn(provider.current_user_playlists)
self._app.pl_uimgr.add(user_playlists)
kw_explore_item = self._app.mymusic_uimgr.create_item('🎵 发现音乐')
kw_explore_item.clicked.connect(
lambda: self._app.browser.goto(page='/providers/kuwo/explore'),
weak=False)
self._app.mymusic_uimgr.clear()
self._app.mymusic_uimgr.add_item(kw_explore_item)
self._pvd_item.text = f'{__alias__} - 已登录'


class LoginDialog(CookiesLoginDialog):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from setuptools import setup

packages = \
['fuo_kuwo', 'fuo_kuwo.enc', 'fuo_kuwo.pages']
['fuo_kuwo', 'fuo_kuwo.enc']

package_data = \
{'': ['*'], 'fuo_kuwo': ['assets/*']}
Expand Down

0 comments on commit 224f979

Please sign in to comment.