Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

player: emit songs_added/removed when songs is changed #896

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 11 additions & 15 deletions feeluown/player/playlist.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import asyncio
import warnings
import logging
import random
from enum import IntEnum, Enum
Expand Down Expand Up @@ -336,12 +335,14 @@ def remove(self, song):
with self._songs_lock:
self.remove_no_lock(song)

def init_from(self, songs):
warnings.warn(
'use set_models instead, this will be removed in v3.8',
DeprecationWarning
)
self.set_models(songs, fm=False)
def _replace_song_no_lock(self, model, umodel):
index = self._songs.index(model)
self._songs.insert(index+1, umodel)
self.songs_added.emit(index+1, 1)
if self.current_song == model:
self.set_current_song_none()
self._songs.remove(model)
self.songs_removed.emit(index, 1)

def clear(self):
"""remove all songs from playlists"""
Expand Down Expand Up @@ -755,16 +756,11 @@ async def a_play_model(self, model):
else:
# Replace the brief model with the upgraded model
# when user try to play a brief model that is already in the playlist.
if isinstance(model, BriefSongModel):
if isinstance(model, BriefSongModel) and not isinstance(model, SongModel):
with self._songs_lock:
if model in self._songs:
index = self._songs.index(model)
self._songs.insert(index+1, umodel)
if self.current_song == model:
self.set_current_song_none()
else:
self._songs.remove(model)
model = umodel
self._replace_song_no_lock(model, umodel)
model = umodel

try:
await self._app.task_mgr.run_afn_preemptive(
Expand Down
Loading