diff --git a/Dockerfile b/Dockerfile index 4e28851..a8d5791 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/air-support/Airplane_Sound_Effect.ogg b/air-support/Airplane_Sound_Effect.ogg new file mode 100644 index 0000000..9408eb0 Binary files /dev/null and b/air-support/Airplane_Sound_Effect.ogg differ diff --git a/air-support/Propeller_Plane_Sound_Effect.ogg b/air-support/Propeller_Plane_Sound_Effect.ogg new file mode 100644 index 0000000..0f9d86a Binary files /dev/null and b/air-support/Propeller_Plane_Sound_Effect.ogg differ diff --git a/icecast.xml.jinja b/icecast.xml.jinja index 765b7d3..342c34d 100644 --- a/icecast.xml.jinja +++ b/icecast.xml.jinja @@ -30,7 +30,7 @@ - /radio-bullshit.ogg + /radio-bullshit.ogg {{ source_username }} {{ source_password }} diff --git a/ices.xml.jinja b/ices.xml.jinja index d0bb972..668d069 100644 --- a/ices.xml.jinja +++ b/ices.xml.jinja @@ -14,7 +14,7 @@ {{ source_username }} {{ source_password }} - /radio-bullshit.ogg + /radio-bullshit.ogg diff --git a/next_song.py b/next_song.py index aa5dd60..320f88e 100755 --- a/next_song.py +++ b/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) diff --git a/ultrasync.sh b/ultrasync.sh index d82586a..15744fe 100644 --- a/ultrasync.sh +++ b/ultrasync.sh @@ -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 diff --git a/yt_sync.py b/yt_sync.py index d627454..89903b4 100644 --- a/yt_sync.py +++ b/yt_sync.py @@ -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(