it's resilient

This commit is contained in:
Aethor 2021-06-15 23:27:04 +02:00
parent 147f406219
commit 88aa22ad32
8 changed files with 31 additions and 14 deletions

View File

@ -1,9 +1,9 @@
# docker build . -t radio-bullshit && docker run --rm -p 8000:8000 -v `pwd`/jingles:/jingles -v `pwd`/songs:/songs radio-bullshit # docker build . -t radio-bullshit && docker run -it --rm -p 8000:8000 -v `pwd`/jingles:/jingles -v `pwd`/songs:/songs radio-bullshit
FROM python:3.9 FROM python:3.9
ENV DEBIAN_FRONTEND=noninteractive ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update RUN apt-get update
RUN apt-get install -y icecast2 ices2 RUN apt-get install -y icecast2 ices2 ffmpeg
RUN pip install jinja2 j2cli RUN pip install jinja2 j2cli
WORKDIR /config WORKDIR /config
@ -19,7 +19,7 @@ COPY ultrasync.sh /opt
RUN chmod +x /opt/yt_sync.py /opt/next_song.py /opt/ultrasync.sh RUN chmod +x /opt/yt_sync.py /opt/next_song.py /opt/ultrasync.sh
RUN mkdir -p /songs /jingles /var/log/icecast RUN mkdir -p /songs /jingles /air-support /var/log/icecast
RUN chown -R zambla:zambla /config RUN chown -R zambla:zambla /config
RUN chown -R zambla:zambla /opt RUN chown -R zambla:zambla /opt
@ -28,6 +28,8 @@ RUN chown -R zambla:zambla /jingles
RUN chown -R zambla:zambla /var/log/icecast RUN chown -R zambla:zambla /var/log/icecast
RUN chown -R zambla:zambla /usr/share/icecast2 RUN chown -R zambla:zambla /usr/share/icecast2
ADD air-support /air-support
COPY entrypoint.sh /opt/entrypoint.sh COPY entrypoint.sh /opt/entrypoint.sh
RUN chmod +x /opt/entrypoint.sh RUN chmod +x /opt/entrypoint.sh

Binary file not shown.

Binary file not shown.

View File

@ -1,4 +1,4 @@
#!/usr/bin/python3 #!/usr/bin/env python3
import random, glob, os, json import random, glob, os, json
@ -6,7 +6,12 @@ if __name__ == "__main__":
songs_folder = "/songs" songs_folder = "/songs"
jingles_folder = "/jingles" jingles_folder = "/jingles"
air_support_folder = "/air-support"
def get_air_support():
return random.choice(glob.glob(f"{air_support_folder}/*.ogg"))
# state loading
if not os.path.isfile(f"{songs_folder}/state.json"): if not os.path.isfile(f"{songs_folder}/state.json"):
# create state file if it doesnt exist # create state file if it doesnt exist
with open(f"{songs_folder}/state.json", "w") as f: with open(f"{songs_folder}/state.json", "w") as f:
@ -16,14 +21,25 @@ if __name__ == "__main__":
with open(f"{songs_folder}/state.json") as f: with open(f"{songs_folder}/state.json") as f:
state = json.load(f) state = json.load(f)
# song choice
if state["current_song_type"] == "song": if state["current_song_type"] == "song":
state["current_song_type"] = "jingle" state["current_song_type"] = "jingle"
print(random.choice(glob.glob(f"{jingles_folder}/*.ogg"))) try:
print(random.choice(glob.glob(f"{jingles_folder}/*.ogg")))
except IndexError:
print(get_air_support())
elif state["current_song_type"] == "jingle": elif state["current_song_type"] == "jingle":
state["current_song_type"] = "song" state["current_song_type"] = "song"
print(random.choice(glob.glob(f"{songs_folder}/*.ogg"))) try:
print(random.choice(glob.glob(f"{songs_folder}/*.ogg")))
except IndexError:
print(get_air_support())
else: else:
exit(1) # should not happen
# resiliency mode
print(get_air_support())
state = {"current_song_type": "jingle"}
# state saving
with open(f"{songs_folder}/state.json", "w") as f: with open(f"{songs_folder}/state.json", "w") as f:
json.dump(state, f, indent=4) json.dump(state, f, indent=4)

View File

@ -2,6 +2,6 @@
while true; do while true; do
pip3 install -U youtube_dl pip3 install -U youtube_dl
runuser -l zambla -c '/opt/yt_sync.py' runuser -l zambla -c '/opt/yt_sync.py' || true
sleep 10m sleep 10m
done done

View File

@ -1,5 +1,4 @@
#!/usr/bin/python3 #!/usr/bin/env python3
import os
import youtube_dl import youtube_dl
@ -13,7 +12,7 @@ if __name__ == "__main__":
ydl_parameters = { ydl_parameters = {
"format": "bestaudio/best", "format": "bestaudio/best",
"postprocessors": [{"key": "FFmpegExtractAudio", "preferredcodec": "vorbis"}], "postprocessors": [{"key": "FFmpegExtractAudio", "preferredcodec": "vorbis"}],
"outtmpl": f"{songs_folder}/%(title)s.ogg", "outtmpl": f"{songs_folder}/%(title)s.godwin",
"ignoreerrors": True, "ignoreerrors": True,
"restrictfilenames": True, "restrictfilenames": True,
} }
@ -25,7 +24,7 @@ if __name__ == "__main__":
# Radio Bullshit Jingles # Radio Bullshit Jingles
## change output path for Radio Bullshit jingles ## change output path for Radio Bullshit jingles
ydl_parameters["outtmpl"] = f"{jingles_folder}/%(title)s.ogg" ydl_parameters["outtmpl"] = f"{jingles_folder}/%(title)s"
## download ## download
ydl = youtube_dl.YoutubeDL(ydl_parameters) ydl = youtube_dl.YoutubeDL(ydl_parameters)
ydl.extract_info( ydl.extract_info(