83 lines
1.9 KiB
Python
83 lines
1.9 KiB
Python
# import urwid
|
|
|
|
# txt = urwid.Text("hello world")
|
|
# fill = urwid.Filler(txt, "top")
|
|
# loop = urwid.MainLoop(fill)
|
|
# loop.run()
|
|
|
|
import subprocess
|
|
import wave
|
|
import io
|
|
|
|
import SubSonic
|
|
import pyaudio
|
|
import pydub
|
|
|
|
u = 'pseudo'
|
|
p = 'telegram9dock-MICHEL'
|
|
conn = SubSonic.SubpyConn(u, p, "https://music.0x01fe.net")
|
|
|
|
echidna_id = "937004317800a879f0cddd471fb82387"
|
|
|
|
def play_song(song_id: str):
|
|
r = conn.stream(song_id)
|
|
|
|
p = pyaudio.PyAudio()
|
|
|
|
# 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)
|
|
|
|
stream = p.open(format=pyaudio.paInt16,
|
|
channels=2,
|
|
rate=44100,
|
|
output=True)
|
|
|
|
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)
|
|
|
|
# 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) |