Update subgen.py
Added Tautulli webhooks back, minor housekeeping.
This commit is contained in:
@@ -9,9 +9,6 @@ import subprocess
|
|||||||
from flask import Flask, request
|
from flask import Flask, request
|
||||||
import xml.etree.ElementTree as ET
|
import xml.etree.ElementTree as ET
|
||||||
|
|
||||||
def getenv(env, default):
|
|
||||||
return os.getenv(env, default)
|
|
||||||
|
|
||||||
def converttobool(in_bool):
|
def converttobool(in_bool):
|
||||||
value = str(in_bool).lower()
|
value = str(in_bool).lower()
|
||||||
if value in ('false', 'off', '0'):
|
if value in ('false', 'off', '0'):
|
||||||
@@ -20,39 +17,39 @@ def converttobool(in_bool):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
# parse our arguments from environment variables
|
# parse our arguments from environment variables
|
||||||
plextoken = getenv('PLEXTOKEN', "tokenhere")
|
plextoken = os.getenv('PLEXTOKEN', "tokenhere")
|
||||||
plexserver = getenv('PLEXSERVER', "http://plex:32400")
|
plexserver = os.getenv('PLEXSERVER', "http://plex:32400")
|
||||||
whisper_model = getenv('WHISPER_MODEL', "medium")
|
whisper_model = os.getenv('WHISPER_MODEL', "medium")
|
||||||
whisper_speedup = getenv('WHISPER_SPEEDUP', "False")
|
whisper_speedup = converttobool(os.getenv('WHISPER_SPEEDUP', "False"))
|
||||||
whisper_speedup = converttobool(whisper_speedup)
|
whisper_threads = os.getenv('WHISPER_THREADS', "4")
|
||||||
whisper_threads = getenv('WHISPER_THREADS', "4")
|
whisper_processors = os.getenv('WHISPER_PROCESSORS', "1")
|
||||||
whisper_processors = getenv('WHISPER_PROCESSORS', "1")
|
procaddedmedia = converttobool(os.getenv('PROCADDEDMEDIA', "True"))
|
||||||
procaddedmedia = getenv('PROCADDEDMEDIA', "True")
|
procmediaonplay = converttobool(os.getenv('PROCMEDIAONPLAY', "False"))
|
||||||
procaddedmedia = converttobool(procaddedmedia)
|
namesublang = os.getenv('NAMESUBLANG', "aa")
|
||||||
procmediaonplay = getenv('PROCMEDIAONPLAY', "False")
|
updaterepo = converttobool(os.getenv('UPDATEREPO', "True"))
|
||||||
procmediaonplay = converttobool(procmediaonplay)
|
skipifinternalsublang = os.getenv('SKIPIFINTERNALSUBLANG', "eng")
|
||||||
namesublang = getenv('NAMESUBLANG', "aa")
|
webhookport = os.getenv('WEBHOOKPORT', 8090)
|
||||||
updaterepo = getenv('UPDATEREPO', "True")
|
|
||||||
updaterepo = converttobool(updaterepo)
|
|
||||||
skipifinternalsublang = getenv('SKIPIFINTERNALSUBLANG', "eng")
|
|
||||||
webhookport = getenv('WEBHOOKPORT', 8090)
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
@app.route("/webhook", methods=["POST"])
|
@app.route("/webhook", methods=["POST"])
|
||||||
def receive_webhook():
|
def receive_webhook():
|
||||||
|
if request.headers.get("source") == "Tautulli":
|
||||||
|
payload = request.json
|
||||||
|
else:
|
||||||
payload = json.loads(request.form['payload'])
|
payload = json.loads(request.form['payload'])
|
||||||
event = payload.get("event")
|
event = payload.get("event")
|
||||||
|
if ((event == "library.new" or event == "added") and procaddedmedia) or ((event == "media.play" or event == "played") and procmediaonplay):
|
||||||
|
|
||||||
|
if event == "library.new" or event == "media.play": # these are the plex webhooks!
|
||||||
|
print("Plex webhook received!")
|
||||||
metadata = payload.get("Metadata")
|
metadata = payload.get("Metadata")
|
||||||
|
|
||||||
if (event == "library.new" and procaddedmedia) or (event == "media.play" and procmediaonplay):
|
|
||||||
|
|
||||||
|
|
||||||
print("Webhook received!")
|
|
||||||
|
|
||||||
ratingkey = metadata.get("ratingKey")
|
ratingkey = metadata.get("ratingKey")
|
||||||
fullpath = get_file_name(ratingkey, plexserver, plextoken)
|
fullpath = get_file_name(ratingkey, plexserver, plextoken)
|
||||||
print("Media ID: {}".format(metadata.get("ratingKey")))
|
else:
|
||||||
|
print("Tautulli webhook received!")
|
||||||
|
fullpath = payload.get("file")
|
||||||
|
|
||||||
filename = pathlib.Path(fullpath).name
|
filename = pathlib.Path(fullpath).name
|
||||||
filepath = os.path.dirname(fullpath)
|
filepath = os.path.dirname(fullpath)
|
||||||
filenamenoextension = filename.replace(pathlib.Path(fullpath).suffix, "")
|
filenamenoextension = filename.replace(pathlib.Path(fullpath).suffix, "")
|
||||||
@@ -127,22 +124,17 @@ def get_file_name(item_id, plexserver, plextoken):
|
|||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
if not os.path.isdir("/whisper.cpp"):
|
#if not os.path.isdir("/whisper.cpp"):
|
||||||
os.mkdir("/whisper.cpp")
|
#os.mkdir("/whisper.cpp")
|
||||||
os.chdir("/whisper.cpp")
|
#os.chdir("/whisper.cpp")
|
||||||
subprocess.call("git clone https://github.com/ggerganov/whisper.cpp .", shell=True)
|
#subprocess.call("git clone https://github.com/ggerganov/whisper.cpp .", shell=True)
|
||||||
if updaterepo:
|
if updaterepo:
|
||||||
print("Updating repo!")
|
print("Updating repo!")
|
||||||
subprocess.call("git pull", shell=True)
|
#subprocess.call("git pull", shell=True)
|
||||||
if os.path.isfile("/whisper.cpp/samples/jfk.wav"): # delete the sample file, so it doesn't try transcribing it. Saves us a couple seconds.
|
if os.path.isfile("/whisper.cpp/samples/jfk.wav"): # delete the sample file, so it doesn't try transcribing it. Saves us a couple seconds.
|
||||||
print("Deleting sample file")
|
print("Deleting sample file")
|
||||||
os.remove("/whisper.cpp/samples/jfk.wav")
|
#os.remove("/whisper.cpp/samples/jfk.wav")
|
||||||
subprocess.call("make " + whisper_model, shell=True)
|
#subprocess.call("make " + whisper_model, shell=True)
|
||||||
print("Starting webhook!")
|
print("Starting webhook!")
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.run(debug=False, host='0.0.0.0', port=int(webhookport))
|
app.run(debug=True, host='0.0.0.0', port=int(webhookport))
|
||||||
print("Webhook started")
|
|
||||||
|
|
||||||
while True:
|
|
||||||
print("Still alive...")
|
|
||||||
time.sleep(300)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user