Skip to content

Instantly share code, notes, and snippets.

@ohld
Last active February 28, 2022 02:44
Show Gist options
  • Save ohld/6c42813148c53737ec855ea5bd7ad4b8 to your computer and use it in GitHub Desktop.
Save ohld/6c42813148c53737ec855ea5bd7ad4b8 to your computer and use it in GitHub Desktop.
Create 24/7 Youtube online radio (like lo-fi music for study/relax/sleep)
import os, json
from flask import Flask, request
app = Flask(__name__)
FNAME = "song.txt"
@app.route('/', methods=['POST','GET'])
def index():
with open(FNAME, "w") as f:
req_data = request.get_json()
if "now_playing" in req_data:
if "song" in req_data["now_playing"]:
if "text" in req_data["now_playing"]["song"]:
text = req_data["now_playing"]["song"]["text"]
f.write(text)
return '{"success":"true"}'
if __name__ == "__main__":
app.run(host='0.0.0.0', port=5000)
@dropitlikecross
Copy link

dropitlikecross commented Jun 2, 2020

@dropitlikecross You need just to set up a webhook via Azuracast admin panel: provide your webhook's URL and that is it.


So if I'm running both ffmpeg and azuracast on the same box, I'd just be inputting the IP address of that machine into the Azuracast admin panel webhook section?

Also can I run azuracast and ffmpeg on 2 separate machines with webhook.py running or is webhook.py reliant on azuracast running on that machine? Sorry new to python and trying to understand what @app.route is doing.

Thanks @ohld :)

@ohld
Copy link
Author

ohld commented Jun 3, 2020

@app.route just tells "if someone comes to / endpoint of your server - call that function". The script can be hosted anywhere

@Waffleuncle
Copy link

Is this full script ?

@version6-hub
Copy link

Hi can you give an example of how you would set up a webhook for this to work on azuracast. I think thats the confusing portion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment