it's resilient
This commit is contained in:
parent
147f406219
commit
88aa22ad32
@ -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
|
||||
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
RUN apt-get update
|
||||
RUN apt-get install -y icecast2 ices2
|
||||
RUN apt-get install -y icecast2 ices2 ffmpeg
|
||||
RUN pip install jinja2 j2cli
|
||||
|
||||
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 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 /opt
|
||||
@ -28,6 +28,8 @@ RUN chown -R zambla:zambla /jingles
|
||||
RUN chown -R zambla:zambla /var/log/icecast
|
||||
RUN chown -R zambla:zambla /usr/share/icecast2
|
||||
|
||||
ADD air-support /air-support
|
||||
|
||||
COPY entrypoint.sh /opt/entrypoint.sh
|
||||
RUN chmod +x /opt/entrypoint.sh
|
||||
|
||||
|
BIN
air-support/Airplane_Sound_Effect.ogg
Normal file
BIN
air-support/Airplane_Sound_Effect.ogg
Normal file
Binary file not shown.
BIN
air-support/Propeller_Plane_Sound_Effect.ogg
Normal file
BIN
air-support/Propeller_Plane_Sound_Effect.ogg
Normal file
Binary file not shown.
@ -30,7 +30,7 @@
|
||||
|
||||
|
||||
<mount type="normal">
|
||||
<mount-name>/radio-bullshit.ogg</mount-name>
|
||||
<mount-name>/radio-bullshit.ogg</mount-name>
|
||||
|
||||
<username>{{ source_username }}</username>
|
||||
<password>{{ source_password }}</password>
|
||||
|
@ -14,7 +14,7 @@
|
||||
<instance>
|
||||
<username>{{ source_username }}</username>
|
||||
<password>{{ source_password }}</password>
|
||||
<mount>/radio-bullshit.ogg</mount>
|
||||
<mount>/radio-bullshit.ogg</mount>
|
||||
</instance>
|
||||
</stream>
|
||||
</ices>
|
||||
|
24
next_song.py
24
next_song.py
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python3
|
||||
#!/usr/bin/env python3
|
||||
import random, glob, os, json
|
||||
|
||||
|
||||
@ -6,7 +6,12 @@ if __name__ == "__main__":
|
||||
|
||||
songs_folder = "/songs"
|
||||
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"):
|
||||
# create state file if it doesnt exist
|
||||
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:
|
||||
state = json.load(f)
|
||||
|
||||
# song choice
|
||||
if state["current_song_type"] == "song":
|
||||
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":
|
||||
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:
|
||||
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:
|
||||
json.dump(state, f, indent=4)
|
||||
|
@ -2,6 +2,6 @@
|
||||
|
||||
while true; do
|
||||
pip3 install -U youtube_dl
|
||||
runuser -l zambla -c '/opt/yt_sync.py'
|
||||
runuser -l zambla -c '/opt/yt_sync.py' || true
|
||||
sleep 10m
|
||||
done
|
||||
|
@ -1,5 +1,4 @@
|
||||
#!/usr/bin/python3
|
||||
import os
|
||||
#!/usr/bin/env python3
|
||||
import youtube_dl
|
||||
|
||||
|
||||
@ -13,7 +12,7 @@ if __name__ == "__main__":
|
||||
ydl_parameters = {
|
||||
"format": "bestaudio/best",
|
||||
"postprocessors": [{"key": "FFmpegExtractAudio", "preferredcodec": "vorbis"}],
|
||||
"outtmpl": f"{songs_folder}/%(title)s.ogg",
|
||||
"outtmpl": f"{songs_folder}/%(title)s.godwin",
|
||||
"ignoreerrors": True,
|
||||
"restrictfilenames": True,
|
||||
}
|
||||
@ -25,7 +24,7 @@ if __name__ == "__main__":
|
||||
|
||||
# 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
|
||||
ydl = youtube_dl.YoutubeDL(ydl_parameters)
|
||||
ydl.extract_info(
|
||||
|
Loading…
Reference in New Issue
Block a user