Modified function cache() so that the player can load all ffmpeg compatible files.

This commit is contained in:
The Wobbler 2024-12-29 20:10:06 +01:00
parent ae6081971b
commit 878583eaac
3 changed files with 17 additions and 3 deletions

1
wobuzz/__init__.py Normal file
View file

@ -0,0 +1 @@
#!/usr/bin/python3

View file

@ -33,8 +33,8 @@ class Playlist:
m3u = file.read() m3u = file.read()
file.close() file.close()
lines = m3u.split("\n") # m3u entries lines = m3u.split("\n") # m3u entries are separated by newlines
lines = lines[:-1] lines = lines[:-1] # remove last entry because it is just an empty string
i = 0 i = 0
num_lines = len(lines) num_lines = len(lines)

View file

@ -6,6 +6,13 @@ from pygame.mixer import Sound
from tinytag import TinyTag from tinytag import TinyTag
SUPPORTED_FORMATS = [
"mp3",
"wav",
"ogg"
]
class Track: class Track:
""" """
Class containing data for a track like file path, raw data... Class containing data for a track like file path, raw data...
@ -27,7 +34,7 @@ class Track:
self.cache() self.cache()
def cache(self): def cache(self):
self.audio = AudioSegment.from_mp3(self.path) self.load_audio()
# audio = normalize(audio) # audio = normalize(audio)
wav = self.audio.export(format="wav") wav = self.audio.export(format="wav")
@ -38,6 +45,12 @@ class Track:
self.cached = True self.cached = True
def load_audio(self):
type = self.path.split(".")[-1]
if type in SUPPORTED_FORMATS:
self.audio = AudioSegment.from_file(self.path)
def remaining(self, position: int): def remaining(self, position: int):
remaining_audio = self.audio[position:] remaining_audio = self.audio[position:]