A Python library and example script that downloads an audio file via youtube-dl and streams it to an IceCast server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.2 KiB

#!/usr/bin/env python3
# a daemon for IceDJ that accepts urls and filenames in a fifo
import os, signal, sys, queue, threading
from icedj import IceDJ
def stop_program(_signo, _stack_frame):
os.remove(fifo_path)
sys.exit(0)
# FIXME: I think this is the thread that has 100% cpu usage for one core?
def add_song():
while True:
song = songq.get()
dj.stream(song)
songq.task_done()
dj = IceDJ()
fifo_path = '/tmp/icedjd.fifo'
songq = queue.LifoQueue()
threading.Thread(target=add_song, daemon=True).start()
signal.signal(signal.SIGTERM, stop_program)
signal.signal(signal.SIGINT, stop_program)
try:
os.mkfifo(fifo_path)
except OSError:
print("FIFO failed to create at {fifo_path} (is IceDJd already running?)")
else:
fifo = open(fifo_path, 'r')
while True:
url = fifo.readline().strip()
if url == "":
continue
# TODO: replace with regex?
# TODO: print queue position
if url.startswith("http"):
filename = dj.download(url)
print(filename + " added to top of queue")
songq.put(filename)
elif os.path.exists(url):
print(url + " added to top of queue")
songq.put(url)