added config file with caching and bitrate
This commit is contained in:
1 parent
e3e94f35df
commit
7b6a1ed30c
3 files changed
+23
-5
No files matched your search
@@ -306,11 +306,14 @@ class SubpyConn:
|
||||
return starred
|
||||
|
||||
# Returns a requests Response object, the data stream can be found in Response.content
|
||||
def stream(self, song_id: str) -> requests.Response:
|
||||
def stream(self, song_id: str, maxBitRate: int | None = None) -> requests.Response:
|
||||
url = self.base_url + '/rest/stream?'
|
||||
|
||||
payload = self._getBasePayload()
|
||||
|
||||
if maxBitRate:
|
||||
payload['maxBitRate'] = maxBitRate
|
||||
|
||||
payload['id'] = song_id
|
||||
|
||||
return requests.get(url + self._encodePayload(payload), stream=True)
|
||||
|
||||
+16
-4
@@ -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:
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
[STREAMING]
|
||||
Cache = true
|
||||
Bitrate = 320kbps
|
||||
Reference in new issue
Block a user