added ff/rewind & make album art load just bytes instead of writing to a file
This commit is contained in:
1 parent
c1c640f837
commit
7ad56fa4be
3 files changed
+56
-18
No files matched your search
+34
-7
@@ -25,6 +25,7 @@ from textual.widgets.option_list import Option
|
||||
from textual.timer import Timer
|
||||
|
||||
from rich_pixels import Pixels
|
||||
from PIL import Image
|
||||
|
||||
u = 'pseudo'
|
||||
p = 'telegram9dock-MICHEL'
|
||||
@@ -286,17 +287,18 @@ class Favourites(Screen):
|
||||
if song.id == self.selected_song_id:
|
||||
return i
|
||||
|
||||
# TODO : Maybe should just take bytes instead of saving it as a file
|
||||
class CoverArtPixels(Container):
|
||||
|
||||
def __init__(self, cover_art_id: str):
|
||||
super().__init__()
|
||||
cover_art_id: str | None = None
|
||||
|
||||
def set_cover_art(self, cover_art_id: str) -> None:
|
||||
self.cover_art_id = cover_art_id
|
||||
conn.getCoverArt(cover_art_id, path=f'art/{cover_art_id}.png')
|
||||
|
||||
def render(self) -> RenderResult:
|
||||
|
||||
if not self.cover_art_id:
|
||||
return ""
|
||||
|
||||
# Make the size square
|
||||
width, height = self.size
|
||||
|
||||
@@ -305,7 +307,8 @@ class CoverArtPixels(Container):
|
||||
elif height > width:
|
||||
height = width
|
||||
|
||||
return Pixels().from_image_path(f'art/{self.cover_art_id}.png', resize=(width, height))
|
||||
image = Image.open(io.BytesIO(conn.getCoverArtRaw(self.cover_art_id)))
|
||||
return Pixels().from_image(image, resize=(width, height))
|
||||
|
||||
class MainView(Screen):
|
||||
CSS_PATH = 'main.tcss'
|
||||
@@ -317,6 +320,7 @@ class MainView(Screen):
|
||||
yield Label("Playing")
|
||||
yield DataTable(id="currently_playing")
|
||||
yield ProgressBar()
|
||||
yield CoverArtPixels()
|
||||
with Vertical(classes="column"):
|
||||
yield Label("Queue")
|
||||
yield DataTable(id="queue")
|
||||
@@ -333,7 +337,7 @@ class MainView(Screen):
|
||||
currentlyPlaying.add_columns("", "")
|
||||
|
||||
@on(events.ScreenResume)
|
||||
async def screen_resumed(self, event: events.ScreenResume) -> None:
|
||||
def screen_resumed(self, event: events.ScreenResume) -> None:
|
||||
app.sub_title = "Overview"
|
||||
|
||||
# Update Queue Table
|
||||
@@ -359,7 +363,7 @@ class MainView(Screen):
|
||||
currentlyPlaying.add_row("Track Number", song.trackNumber)
|
||||
currentlyPlaying.add_row("Bit Rate", song.bitRate)
|
||||
|
||||
await self.query_one('#info').mount(CoverArtPixels(app.currently_playing.id))
|
||||
self.query_one(CoverArtPixels).set_cover_art(app.currently_playing.id)
|
||||
|
||||
def _clear_table(self, table_id: str) -> None:
|
||||
table: DataTable = self.query_one(table_id)
|
||||
@@ -374,7 +378,9 @@ class MainView(Screen):
|
||||
|
||||
class TextualSubpyPlayer(App):
|
||||
BINDINGS = [
|
||||
("r", "rewind()", "⏪"),
|
||||
("space", "play_pause_song()", "⏯️"),
|
||||
("s", "skip()", "⏭️"),
|
||||
("f1", "switch_mode('main')", "Overview"),
|
||||
("f2", "switch_mode('artists')", "Artists"),
|
||||
("f3", "switch_mode('albums')", "Albums"),
|
||||
@@ -393,6 +399,7 @@ class TextualSubpyPlayer(App):
|
||||
currently_playing: SubSonic.Song | None = None
|
||||
song_queue: list[SubSonic.Song] = []
|
||||
user_queue: list[SubSonic.Song] = []
|
||||
play_history: list[SubSonic.Song] = []
|
||||
is_paused: bool = False
|
||||
place: int = 0
|
||||
|
||||
@@ -430,6 +437,7 @@ class TextualSubpyPlayer(App):
|
||||
|
||||
def check_done_playing(self) -> None:
|
||||
if not pygame.mixer.music.get_busy() and not self.is_paused:
|
||||
self.play_history.append(self.currently_playing)
|
||||
queue = self.user_queue
|
||||
queue.extend(self.song_queue)
|
||||
|
||||
@@ -439,6 +447,25 @@ class TextualSubpyPlayer(App):
|
||||
|
||||
self.check_playing_timer.stop()
|
||||
|
||||
def action_skip(self) -> None:
|
||||
|
||||
if self.check_playing_timer:
|
||||
self.check_playing_timer.stop()
|
||||
|
||||
if self.currently_playing:
|
||||
self.play_history.append(self.currently_playing)
|
||||
|
||||
queue = self.user_queue
|
||||
queue.extend(self.song_queue)
|
||||
|
||||
self.play_song(queue.pop(0))
|
||||
|
||||
def action_rewind(self) -> None:
|
||||
if self.check_playing_timer:
|
||||
self.check_playing_timer.stop()
|
||||
|
||||
self.play_song(self.play_history.pop())
|
||||
|
||||
# def update_progress(self) -> None:
|
||||
# self.query_one(ProgressBar).advance(1)
|
||||
|
||||
|
||||
Reference in new issue
Block a user