Added a "Playlist" class.

This commit is contained in:
The Wobbler 2024-12-24 17:22:30 +01:00
parent 1190059218
commit 94269fdae4
7 changed files with 119 additions and 53 deletions

View file

@ -10,22 +10,28 @@ class Track:
Class containing data for a track like file path, raw data...
"""
def __init__(self, path: str, cache: bool=False):
def __init__(self, app, path: str, property_string: str=None, cache: bool=False):
self.app = app
self.path = path
self.property_string = property_string
self.cached = cache
(self.audio, self.sound, self.duration) = self.cache() if self.cached else (None, None, 0)
self.audio = None
self.sound = None
self.duration = 0
if self.cached:
self.cache()
def cache(self):
audio = AudioSegment.from_mp3(self.path)
self.audio = AudioSegment.from_mp3(self.path)
# audio = normalize(audio)
wav = audio.export(format="wav")
wav = self.audio.export(format="wav")
sound = Sound(wav)
self.sound = Sound(wav)
# return pygame.mixer.Sound object and track duration in milliseconds
return audio, sound, len(audio)
self.duration = len(self.audio) # track duration in milliseconds
def remaining(self, position: int):
remaining_audio = self.audio[position:]
@ -34,4 +40,5 @@ class Track:
sound = Sound(wav)
# return the remaining part of the track's audio and the duration of the remaining part
return sound, len(remaining_audio)