change album cover layout and add improve player syncing when connection is dropped
This commit is contained in:
36
player.py
36
player.py
@@ -16,6 +16,7 @@ import threading
|
||||
import queue
|
||||
import sys
|
||||
import io
|
||||
import fcntl
|
||||
|
||||
os.makedirs("logs", exist_ok=True)
|
||||
|
||||
@@ -59,9 +60,10 @@ class FFQueuePlayer:
|
||||
|
||||
def _open_ffmpeg(self, url, seek=0):
|
||||
self.song+=1
|
||||
return subprocess.Popen(
|
||||
proc = subprocess.Popen(
|
||||
[
|
||||
"ffmpeg",
|
||||
# "-re",
|
||||
"-ss", str(seek),
|
||||
"-i", url,
|
||||
"-f", "s16le",
|
||||
@@ -73,6 +75,13 @@ class FFQueuePlayer:
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=open('logs/'+str(self.song)+".txt", "wb")
|
||||
)
|
||||
|
||||
# --- make stdout non-blocking ---
|
||||
fd = proc.stdout.fileno()
|
||||
flags = fcntl.fcntl(fd, fcntl.F_GETFL)
|
||||
fcntl.fcntl(fd, fcntl.F_SETFL, flags | os.O_NONBLOCK)
|
||||
|
||||
return proc
|
||||
|
||||
def seek(self, pos):
|
||||
with self.lock:
|
||||
@@ -173,18 +182,25 @@ class FFQueuePlayer:
|
||||
elif self.next_preload_state == 0:
|
||||
self.preload_next_threaded()
|
||||
else:
|
||||
data = self.proc.stdout.read(needed) or b''
|
||||
try:
|
||||
data = self.proc.stdout.read(needed) or b''
|
||||
except BlockingIOError:
|
||||
pass
|
||||
self.position += len(data) / (self.samplerate * self.channels * 2)
|
||||
if self.position >= self.playback_info_to_duration(self.playback_info)-10:
|
||||
self.preload_next_threaded()
|
||||
if self.proc.poll() is not None and len(data)<needed:
|
||||
self._start_next()
|
||||
if self.proc is not None and self.proc.poll() is None:
|
||||
new_data = self.proc.stdout.read(needed-len(data)) or b''
|
||||
self.position += len(new_data) / (self.samplerate * self.channels * 2)
|
||||
data += new_data
|
||||
if round(self.position, 2) >= self.playback_info_to_duration(self.playback_info)-0.1:
|
||||
self._start_next()
|
||||
if self.proc is not None and self.proc.poll() is None:
|
||||
try:
|
||||
new_data = self.proc.stdout.read(needed-len(data)) or b''
|
||||
except BlockingIOError:
|
||||
new_data = b''
|
||||
self.position += len(new_data) / (self.samplerate * self.channels * 2)
|
||||
data += new_data
|
||||
else:
|
||||
print("bruh")
|
||||
self.proc = self._open_ffmpeg(self.current_file, self.position)
|
||||
|
||||
outdata[:len(data)] = data
|
||||
|
||||
@@ -204,7 +220,7 @@ def build_jellyfin_audio_url(
|
||||
"""
|
||||
Build a Jellyfin audio stream URL using urllib.parse.
|
||||
"""
|
||||
path = f"/Items/{item_id}/Download"
|
||||
path = f"/Audio/{item_id}/universal"
|
||||
|
||||
params = {
|
||||
"UserId": user_id,
|
||||
@@ -226,7 +242,7 @@ def build_jellyfin_audio_url(
|
||||
client = JellyfinClient()
|
||||
load_dotenv()
|
||||
|
||||
client.config.app('FinPod', '0.0.1', 'FinPod prototype', 'FinPod_prototype_1')
|
||||
client.config.app('UgPod', '0.0.1', 'UgPod prototype', 'UgPod_prototype_1')
|
||||
client.config.data["auth.ssl"] = True
|
||||
|
||||
client.auth.connect_to_address(os.getenv("host"))
|
||||
|
||||
Reference in New Issue
Block a user