added config file with caching and bitrate

This commit is contained in:
JISAUAY committed 2025-09-16 16:25:58 -05:00
1 parent e3e94f35df
commit 7b6a1ed30c
3 files changed
+23 -5

No files matched your search

+16 -4
View File
@@ -1,8 +1,10 @@
import configparser
import logging
import asyncio
import random
import os
import re
import io
import asyncio
LOG_FILE = 'textual.log'
LOGGING_LEVEL = logging.DEBUG
@@ -12,7 +14,14 @@ LOG_FORMAT = '[%(asctime)s] %(levelname)s in %(module)s: %(message)s'
if os.path.exists(LOG_FILE):
os.remove(LOG_FILE)
CACHE = True
# Read config file
config = configparser.ConfigParser()
config.read('config.ini')
CACHE = config.getboolean('STREAMING', 'Cache')
BITRATE = config.get('STREAMING', 'Bitrate')
BITRATE = re.findall(r'[0-9]+', BITRATE)[0]
BITRATE = int(BITRATE) if BITRATE else BITRATE
os.makedirs(".cache/art/", exist_ok=True)
os.makedirs(".cache/audio/", exist_ok=True)
@@ -30,7 +39,7 @@ from textual import on, events, work
from textual.binding import Binding
from textual.reactive import reactive
from textual.app import App, ComposeResult, RenderResult
from textual.widgets import Footer, Header, OptionList, DataTable, ProgressBar, Label, Input, Placeholder
from textual.widgets import Footer, Header, OptionList, DataTable, ProgressBar, Label, Input
from textual.widget import Widget
from textual.containers import Horizontal, Vertical, Container
from textual.screen import Screen
@@ -639,7 +648,10 @@ class TextualSubpyPlayer(App):
asyncio.create_task(asyncio.to_thread(conn.scrobble, song.id, submission=False))
else:
# Run the blocking stream call in a separate thread
r = await asyncio.to_thread(conn.stream, song.id)
if BITRATE:
r = await asyncio.to_thread(conn.stream, song.id, maxBitRate=BITRATE)
else:
r = await asyncio.to_thread(conn.stream, song.id)
audio_content = r.content
if CACHE: