From ffeb6cc854df8ae7d8a15edb4fd83251d404cc08 Mon Sep 17 00:00:00 2001 From: Aethor Date: Sun, 6 Jun 2021 00:34:59 +0200 Subject: [PATCH] first commit --- .gitignore | 1 + jingles/.gitignore | 2 ++ next_song.py | 25 +++++++++++++++++++++++++ songs/.gitignore | 2 ++ yt_sync.py | 22 ++++++++++++++++++++++ 5 files changed, 52 insertions(+) create mode 100644 .gitignore create mode 100644 jingles/.gitignore create mode 100644 next_song.py create mode 100644 songs/.gitignore create mode 100644 yt_sync.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e4e5f6c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*~ \ No newline at end of file diff --git a/jingles/.gitignore b/jingles/.gitignore new file mode 100644 index 0000000..c96a04f --- /dev/null +++ b/jingles/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file diff --git a/next_song.py b/next_song.py new file mode 100644 index 0000000..deea092 --- /dev/null +++ b/next_song.py @@ -0,0 +1,25 @@ +#!/usr/bin/python3 +import random, glob, os, json + + +if __name__ == "__main__": + + script_dir = os.path.dirname(os.path.abspath(__file__)) + + if not os.path.isfile(f"{script_dir}/state.json"): + # create state file if it doesnt exist + with open(f"{script_dir}/state.json", "w") as f: + state = {"current_song_type": "jingle"} + json.dump(state, f, indent=4) + else: + with open(f"{script_dir}/state.json") as f: + state = json.load(f) + + if state["current_song_type"] == "song": + state["current_song_type"] = "jingle" + print(random.choice(glob.glob(f"{script_dir}/jingles/*.ogg"))) + elif state["current_song_type"] == "jingle": + state["current_song_type"] = "song" + print(random.choice(glob.glob(f"{script_dir}/songs/*.ogg"))) + else: + exit(1) diff --git a/songs/.gitignore b/songs/.gitignore new file mode 100644 index 0000000..c96a04f --- /dev/null +++ b/songs/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file diff --git a/yt_sync.py b/yt_sync.py new file mode 100644 index 0000000..8d77be5 --- /dev/null +++ b/yt_sync.py @@ -0,0 +1,22 @@ +import os +import youtube_dl + + +if __name__ == "__main__": + + script_dir = os.path.dirname(os.path.abspath(__file__)) + + ydl = youtube_dl.YoutubeDL( + { + "format": "bestaudio/best", + "postprocessors": [ + {"key": "FFmpegExtractAudio", "preferredcodec": "vorbis"} + ], + "outtmpl": f"{script_dir}/songs/%(title)s.ogg", + "ignoreerrors": True, + "restrictfilenames": True, + } + ) + playlist_infos = ydl.extract_info( + "https://www.youtube.com/playlist?list=PLQC73oq6JtgyYNOeifrJXXzZ1-F0Kgmbg", + )