mirror of
https://github.com/RafaelSolVargas/Vulkan.git
synced 2025-10-29 16:57:23 +00:00
Changing some methods signature in Playlist to be compatible in Shared Memory, now finishing process after some time
This commit is contained in:
@@ -5,6 +5,7 @@ from Controllers.AbstractController import AbstractController
|
||||
from Controllers.ControllerResponse import ControllerResponse
|
||||
from Music.Downloader import Downloader
|
||||
from Utils.Utils import Utils
|
||||
from Parallelism.ProcessManager import ProcessManager
|
||||
|
||||
|
||||
class QueueController(AbstractController):
|
||||
@@ -13,32 +14,43 @@ class QueueController(AbstractController):
|
||||
self.__down = Downloader()
|
||||
|
||||
async def run(self) -> ControllerResponse:
|
||||
if self.player.playlist.looping_one:
|
||||
song = self.player.playlist.current
|
||||
embed = self.embeds.ONE_SONG_LOOPING(song.info)
|
||||
return ControllerResponse(self.ctx, embed)
|
||||
|
||||
songs_preload = self.player.playlist.songs_to_preload
|
||||
if len(songs_preload) == 0:
|
||||
# Retrieve the process of the guild
|
||||
process = ProcessManager()
|
||||
processContext = process.getRunningPlayerContext(self.guild)
|
||||
if not processContext: # If no process return empty list
|
||||
embed = self.embeds.EMPTY_QUEUE()
|
||||
return ControllerResponse(self.ctx, embed)
|
||||
|
||||
asyncio.create_task(self.__down.preload(songs_preload))
|
||||
# Acquire the Lock to manipulate the playlist
|
||||
with processContext.getLock():
|
||||
playlist = processContext.getPlaylist()
|
||||
|
||||
if self.player.playlist.looping_all:
|
||||
title = self.messages.ALL_SONGS_LOOPING
|
||||
else:
|
||||
title = self.messages.QUEUE_TITLE
|
||||
if playlist.isLoopingOne():
|
||||
song = playlist.getCurrentSong()
|
||||
embed = self.embeds.ONE_SONG_LOOPING(song.info)
|
||||
return ControllerResponse(self.ctx, embed)
|
||||
|
||||
total_time = Utils.format_time(sum([int(song.duration if song.duration else 0)
|
||||
for song in songs_preload]))
|
||||
total_songs = len(self.player.playlist)
|
||||
songs_preload = playlist.getSongsToPreload()
|
||||
if len(songs_preload) == 0:
|
||||
embed = self.embeds.EMPTY_QUEUE()
|
||||
return ControllerResponse(self.ctx, embed)
|
||||
|
||||
text = f'📜 Queue length: {total_songs} | ⌛ Duration: `{total_time}` downloaded \n\n'
|
||||
asyncio.create_task(self.__down.preload(songs_preload))
|
||||
|
||||
for pos, song in enumerate(songs_preload, start=1):
|
||||
song_name = song.title if song.title else self.messages.SONG_DOWNLOADING
|
||||
text += f"**`{pos}` - ** {song_name} - `{Utils.format_time(song.duration)}`\n"
|
||||
if playlist.isLoopingAll():
|
||||
title = self.messages.ALL_SONGS_LOOPING
|
||||
else:
|
||||
title = self.messages.QUEUE_TITLE
|
||||
|
||||
embed = self.embeds.QUEUE(title, text)
|
||||
return ControllerResponse(self.ctx, embed)
|
||||
total_time = Utils.format_time(sum([int(song.duration if song.duration else 0)
|
||||
for song in songs_preload]))
|
||||
total_songs = len(playlist.getSongs())
|
||||
|
||||
text = f'📜 Queue length: {total_songs} | ⌛ Duration: `{total_time}` downloaded \n\n'
|
||||
|
||||
for pos, song in enumerate(songs_preload, start=1):
|
||||
song_name = song.title if song.title else self.messages.SONG_DOWNLOADING
|
||||
text += f"**`{pos}` - ** {song_name} - `{Utils.format_time(song.duration)}`\n"
|
||||
|
||||
embed = self.embeds.QUEUE(title, text)
|
||||
return ControllerResponse(self.ctx, embed)
|
||||
|
||||
Reference in New Issue
Block a user