Skip to content

Commit

Permalink
*: remove model v1 (feeluown#746)
Browse files Browse the repository at this point in the history
  • Loading branch information
cosven authored and mokurin000 committed Jan 11, 2024
1 parent d38a67f commit dafcacb
Show file tree
Hide file tree
Showing 51 changed files with 269 additions and 1,840 deletions.
29 changes: 0 additions & 29 deletions examples/model_display.py

This file was deleted.

4 changes: 3 additions & 1 deletion feeluown/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from feeluown.utils.request import Request
from feeluown.library import Library
from feeluown.utils.dispatch import Signal
from feeluown.models import (
from feeluown.library import (
Resolver, reverse, resolve,
ResolverNotFound, ResolveFailed,
)
Expand Down Expand Up @@ -139,6 +139,8 @@ def apply_state(self, state):
song = resolve(song)
except ResolverNotFound:
pass
except ResolveFailed as e:
logger.warning(f'resolve failed, {e}')
else:
songs.append(song)
playlist.set_models(songs)
Expand Down
13 changes: 7 additions & 6 deletions feeluown/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

from feeluown.consts import COLLECTIONS_DIR
from feeluown.utils.dispatch import Signal
from feeluown.models.uri import resolve, reverse, ResolverNotFound, \
ResolveFailed, ModelExistence
from feeluown.library import resolve, reverse, ResolverNotFound, \
ResolveFailed, ModelState
from feeluown.utils.utils import elfhash

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -112,7 +112,7 @@ def load(self):
str(filepath), line, str(e))
model = None
if model is not None:
if model.exists is ModelExistence.no:
if model.state is ModelState.not_exists:
self._has_nonexistent_models = True
self.models.append(model)

Expand Down Expand Up @@ -140,7 +140,7 @@ def create_empty(cls, fpath, title=''):
def add(self, model):
"""add model to collection
:param model: :class:`feeluown.models.BaseModel`
:param model: :class:`feeluown.library.BaseModel`
:return: True means succeed, False means failed
"""
if model not in self.models:
Expand Down Expand Up @@ -184,7 +184,8 @@ def on_provider_added(self, provider):
if not self._has_nonexistent_models:
return
for i, model in enumerate(self.models.copy()):
if model.exists is ModelExistence.no and model.source == provider.identifier:
if model.state is ModelState.not_exists and \
model.source == provider.identifier:
new_model = resolve(reverse(model, as_line=True))
# TODO: emit data changed signal
self.models[i] = new_model
Expand All @@ -193,7 +194,7 @@ def on_provider_added(self, provider):
def on_provider_removed(self, provider):
for model in self.models:
if model.source == provider.identifier:
model.exists = ModelExistence.no
model.state = ModelState.not_exists
self._has_nonexistent_models = True

def _loads_metadata(self, metadata):
Expand Down
2 changes: 1 addition & 1 deletion feeluown/gui/base_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from abc import abstractmethod
from typing import runtime_checkable, Protocol

from feeluown.models import ModelType
from feeluown.library import ModelType
from feeluown.gui.widgets.tabbar import Tab, TabBar


Expand Down
2 changes: 1 addition & 1 deletion feeluown/gui/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from feeluown.utils import aio
from feeluown.utils.router import Router, NotFound
from feeluown.models.uri import resolve, reverse, ResolveFailed, parse_line
from feeluown.library import resolve, reverse, ResolveFailed, parse_line

logger = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion feeluown/gui/components/avatar.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from PyQt5.QtGui import QPainter, QIcon, QPalette, QContextMenuEvent

from feeluown.library import NoUserLoggedIn, UserModel
from feeluown.models.uri import reverse
from feeluown.library import reverse
from feeluown.utils.aio import run_afn, run_fn
from feeluown.gui.provider_ui import UISupportsLoginOrGoHome, ProviderUiItem, \
UISupportsLoginEvent
Expand Down
6 changes: 3 additions & 3 deletions feeluown/gui/components/song_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ def on_metadata_changed(self, metadata):

async def _switch_provider(self, provider_id):
song = self._app.playlist.current_song
songs = await self._app.library.a_list_song_standby(
songs = await self._app.library.a_list_song_standby_v2(
song, source_in=[provider_id])
if songs:
standby = songs[0]
standby, media = songs[0]
assert standby != song
self._app.show_msg(f'使用 {standby} 替换当前歌曲')
self._app.playlist.pure_set_current_song(standby, standby.url)
self._app.playlist.pure_set_current_song(standby, media)
self._app.playlist.remove(song)
else:
self._app.show_msg(f'提供方 “{provider_id}” 没有找到可用的相似歌曲')
2 changes: 1 addition & 1 deletion feeluown/gui/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
from feeluown.utils.typing_ import Protocol
from feeluown.excs import ProviderIOError, ResourceNotFound
from feeluown.library import NotSupported, ModelType, BaseModel
from feeluown.models.uri import reverse
from feeluown.library import reverse


if TYPE_CHECKING:
Expand Down
2 changes: 1 addition & 1 deletion feeluown/gui/mimedata.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from PyQt5.QtCore import QMimeData

from feeluown.models import ModelType
from feeluown.library import ModelType


model_mimetype_map = {
Expand Down
2 changes: 1 addition & 1 deletion feeluown/gui/pages/coll_mixed.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from feeluown.app.gui_app import GuiApp
from feeluown.collection import CollectionType, Collection
from feeluown.models import ModelType
from feeluown.library import ModelType
from feeluown.utils.reader import wrap
from feeluown.gui.page_containers.table import Renderer

Expand Down
2 changes: 1 addition & 1 deletion feeluown/gui/pages/model.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from feeluown.library import V2SupportedModelTypes, AlbumModel, NotSupported
from feeluown.utils import aio
from feeluown.utils.reader import create_reader
from feeluown.models import ModelType, reverse
from feeluown.library import ModelType, reverse

from feeluown.gui.base_renderer import TabBarRendererMixin
from feeluown.gui.page_containers.table import Renderer
Expand Down
2 changes: 1 addition & 1 deletion feeluown/gui/pages/my_fav.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from feeluown.app.gui_app import GuiApp
from feeluown.models import ModelType
from feeluown.library import ModelType
from feeluown.utils.aio import run_fn
from feeluown.gui.page_containers.table import Renderer
from feeluown.gui.base_renderer import TabBarRendererMixin
Expand Down
2 changes: 1 addition & 1 deletion feeluown/gui/pages/search.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from PyQt5.QtWidgets import QFrame, QVBoxLayout

from feeluown.models import SearchType
from feeluown.library import SearchType
from feeluown.gui.page_containers.table import TableContainer, Renderer
from feeluown.gui.page_containers.scroll_area import ScrollArea
from feeluown.gui.widgets.img_card_list import ImgCardListDelegate
Expand Down
2 changes: 1 addition & 1 deletion feeluown/gui/pages/song_explore.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
NotSupported, ModelFlags
)
from feeluown.player import Lyric
from feeluown.models.uri import reverse, resolve
from feeluown.library import reverse, resolve
from feeluown.utils import aio
from feeluown.utils.aio import run_afn
from feeluown.utils.reader import create_reader
Expand Down
2 changes: 1 addition & 1 deletion feeluown/gui/uimain/page_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from PyQt5.QtWidgets import QFrame, QVBoxLayout, QStackedLayout

from feeluown.utils import aio
from feeluown.models import ModelType
from feeluown.library import ModelType
from feeluown.utils.reader import wrap

from feeluown.gui.theme import Light
Expand Down
2 changes: 1 addition & 1 deletion feeluown/gui/uimodels/playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from feeluown.gui.widgets.playlists import PlaylistsModel

from feeluown.models import PlaylistModel
from feeluown.library import PlaylistModel


class PlaylistUiItem(PlaylistModel):
Expand Down
2 changes: 1 addition & 1 deletion feeluown/gui/widgets/img_card_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from feeluown.utils import aio
from feeluown.library import AlbumModel, AlbumType
from feeluown.utils.reader import wrap
from feeluown.models.uri import reverse
from feeluown.library import reverse
from feeluown.gui.helpers import (
ItemViewNoScrollMixin, resize_font, ReaderFetchMoreMixin, painter_save,
secondary_text_color
Expand Down
6 changes: 3 additions & 3 deletions feeluown/gui/widgets/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,15 @@ def autologin(self):
def setup_user(self, user):
"""Setup user session
:type user: feeluown.models.UserModel
:type user: feeluown.library.UserModel
"""
raise NotImplementedError

async def user_from_cookies(self, cookies):
"""Create a user model from cookies dict
:type cookies: dict
:rtype: feeluown.models.UserModel
:rtype: feeluown.library.UserModel
"""
raise NotImplementedError

Expand All @@ -214,7 +214,7 @@ def dump_user_cookies(self, user, cookies):
Generally, you can store the cookies in FeelUOwn data directory
with specifical filename.
:type user: feeluown.models.UserModel
:type user: feeluown.library.UserModel
:type cookies: dict
"""
raise NotImplementedError
Expand Down
2 changes: 1 addition & 1 deletion feeluown/gui/widgets/song_minicard_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
)

from feeluown.utils import aio
from feeluown.models.uri import reverse
from feeluown.library import reverse
from feeluown.gui.helpers import (
ItemViewNoScrollMixin, ReaderFetchMoreMixin, resize_font, SOLARIZED_COLORS
)
Expand Down
11 changes: 3 additions & 8 deletions feeluown/gui/widgets/songs.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@

from feeluown.utils import aio
from feeluown.utils.dispatch import Signal
from feeluown.library import ModelState, ModelFlags
from feeluown.models import ModelExistence
from feeluown.library import ModelState

from feeluown.gui.mimedata import ModelMimeData
from feeluown.gui.helpers import ItemViewNoScrollMixin, ReaderFetchMoreMixin
Expand Down Expand Up @@ -250,12 +249,8 @@ def flags(self, index):
# If song's state is `not_exists` or `cant_upgrade`, the album and
# artist columns are disabled.
incomplete = False
if ModelFlags.v2 & song.meta.flags:
if song.state in (ModelState.not_exists, ModelState.cant_upgrade):
incomplete = True
else:
if song and song.exists == ModelExistence.no:
incomplete = True
if song.state in (ModelState.not_exists, ModelState.cant_upgrade):
incomplete = True
if incomplete:
if index.column() != Column.song:
flags = no_item_flags
Expand Down
2 changes: 1 addition & 1 deletion feeluown/gui/widgets/table_toolbar.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from PyQt5.QtCore import pyqtSignal
from PyQt5.QtWidgets import QHBoxLayout, QComboBox, QWidget

from feeluown.models import AlbumType
from feeluown.library import AlbumType
from feeluown.gui.widgets import TextButton


Expand Down
6 changes: 5 additions & 1 deletion feeluown/library/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# flake8: noqa
from .library import Library
from .provider import AbstractProvider, dummy_provider
from .provider import AbstractProvider
from .provider_v2 import ProviderV2
from .flags import Flags as ProviderFlags
from .model_state import ModelState
Expand All @@ -25,3 +25,7 @@
from .excs import NotSupported, NoUserLoggedIn, ModelNotFound, \
ProviderAlreadyExists, ResourceNotFound, MediaNotFound
from .provider_protocol import *
from .uri import (
Resolver, reverse, resolve, ResolverNotFound, ResolveFailed,
parse_line, NS_TYPE_MAP,
)
Loading

0 comments on commit dafcacb

Please sign in to comment.