still can't get audio to play properly
This commit is contained in:
1 parent
6897b684ee
commit
270ab6799b
3 files changed
+84
-16
No files matched your search
+17
-1
@@ -232,7 +232,23 @@ class SubpyConn:
|
||||
|
||||
payload['id'] = song_id
|
||||
|
||||
return requests.get(url + self._encodePayload(payload))
|
||||
return requests.get(url + self._encodePayload(payload), stream=True)
|
||||
|
||||
def getSong(self, song_id: str) -> Song:
|
||||
url = self.base_url + '/rest/getSong?'
|
||||
|
||||
payload = self._getBasePayload()
|
||||
payload['id'] = song_id
|
||||
|
||||
r = requests.get(url + self._encodePayload(payload))
|
||||
|
||||
xml_data = r.content.decode('utf-8')
|
||||
|
||||
root = xml.etree.ElementTree.fromstring(xml_data)
|
||||
|
||||
for item in root.iter():
|
||||
if item.tag == '{http://subsonic.org/restapi}song':
|
||||
return Song(dict(item.items()))
|
||||
|
||||
conn = SubpyConn(u, p, "https://music.0x01fe.net")
|
||||
|
||||
|
||||
@@ -5,10 +5,13 @@
|
||||
# loop = urwid.MainLoop(fill)
|
||||
# loop.run()
|
||||
|
||||
import subprocess
|
||||
import wave
|
||||
import io
|
||||
|
||||
import SubSonic
|
||||
import pyaudio
|
||||
import pydub
|
||||
|
||||
u = 'pseudo'
|
||||
p = 'telegram9dock-MICHEL'
|
||||
@@ -19,28 +22,62 @@ echidna_id = "937004317800a879f0cddd471fb82387"
|
||||
def play_song(song_id: str):
|
||||
r = conn.stream(song_id)
|
||||
|
||||
# print(len(r.content))
|
||||
p = pyaudio.PyAudio()
|
||||
|
||||
stream_data: bytes = r.content
|
||||
# ogg_data = io.BytesIO(r.content)
|
||||
# audio = pydub.AudioSegment.from_ogg(ogg_data)
|
||||
# # audio.set_sample_width(2)
|
||||
# print("channels", audio.channels)
|
||||
# print("rate", audio.frame_rate)
|
||||
|
||||
def callback(in_data, frame_count, time_info, status):
|
||||
stream = p.open(format=pyaudio.paInt16,
|
||||
channels=2,
|
||||
rate=44100,
|
||||
output=True)
|
||||
|
||||
return (stream_data, pyaudio.paContinue)
|
||||
ffmpeg_process = subprocess.Popen(
|
||||
['ffmpeg', '-i', 'pipe:0', '-f', 'wav', '-ac', '2', '-ar', '44100', '-'],
|
||||
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE
|
||||
)
|
||||
|
||||
for chunk in r.iter_content(chunk_size=1024):
|
||||
if chunk:
|
||||
# print('b')
|
||||
ffmpeg_process.stdin.write(chunk)
|
||||
|
||||
ffmpeg_process.stdin.close()
|
||||
|
||||
while True:
|
||||
pcm_data = ffmpeg_process.stdout.read(1024)
|
||||
print('a')
|
||||
if not pcm_data:
|
||||
break
|
||||
|
||||
stream.write(pcm_data)
|
||||
|
||||
|
||||
# for chunk in r.iter_content(chunk_size=1024):
|
||||
# if chunk:
|
||||
# ogg_data = io.BytesIO(chunk)
|
||||
# audio = pydub.AudioSegment.from_ogg(ogg_data)
|
||||
# audio = audio.set_sample_width(2)
|
||||
# stream.write(audio.raw_data)
|
||||
|
||||
audio = pyaudio.PyAudio()
|
||||
|
||||
stream = audio.open(format=audio.get_format_from_width(2),
|
||||
channels=2,
|
||||
rate=44100,
|
||||
output=True,
|
||||
stream_callback=callback)
|
||||
|
||||
# r.content.
|
||||
|
||||
# def stream_callback(in_data)
|
||||
# stream.write(audio.raw_data)
|
||||
stream.stop_stream()
|
||||
stream.close()
|
||||
p.terminate()
|
||||
|
||||
ffmpeg_process.wait()
|
||||
|
||||
|
||||
play_song(echidna_id)
|
||||
|
||||
# with open('echidna.xml', 'wb') as file:
|
||||
# file.write(conn.getSong(echidna_id).content)
|
||||
|
||||
# echidna = conn.getSong(echidna_id)
|
||||
|
||||
# print(echidna.title)
|
||||
|
||||
# conn.stream(echidna_id)
|
||||
@@ -0,0 +1,15 @@
|
||||
<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.16.1" type="navidrome"
|
||||
serverVersion="0.54.3 (734eb30a)" openSubsonic="true">
|
||||
<song id="937004317800a879f0cddd471fb82387" parent="c69cdc593487ed813f1e11ecb270b228"
|
||||
isDir="false" title="Echidna" album="Helios" artist="Yakui the Maid" track="3" year="2019"
|
||||
coverArt="mf-937004317800a879f0cddd471fb82387_67857269" size="32724161"
|
||||
contentType="audio/flac" suffix="flac" starred="2025-01-13T17:42:47.935755328Z"
|
||||
duration="163" bitRate="1597" path="Yakui the Maid/Helios/01-03 - Echidna.flac"
|
||||
playCount="1" discNumber="1" created="2025-01-07T00:58:13.054979178Z"
|
||||
albumId="c69cdc593487ed813f1e11ecb270b228" artistId="7f6ca9951af294420382442061a2d6ee"
|
||||
type="music" isVideo="false" played="2025-01-16T16:48:25.475684076Z" bpm="0"
|
||||
comment="Visit https://yakuithemaid1.bandcamp.com" sortName="" mediaType="song"
|
||||
musicBrainzId="545a4f2b-23b5-4c11-924b-8d5641dc9e2b" channelCount="2" samplingRate="44100">
|
||||
<replayGain trackPeak="1" albumPeak="1"></replayGain>
|
||||
</song>
|
||||
</subsonic-response>
|
||||
Reference in new issue
Block a user