-
|
So say i create a hook on messages on a specific path that runs a .py file. and in that .py file i spawns a another process ( calling to a bin that is on my systeom ) and then i capture and parse the output of that program and generates a report ( kinda ). and i wanna tell the client, that it is downloaded or not downloaded. for clearity here is the hook that i aadded: import subprocess as sp
import sys
def worker(url: str, server_path: str):
result = {
"downloaded_path": "",
"message": ""
}
if not url.startswith("https://") or url.startswith("upload-queue-empty;"):
result["message"] = "Lawn the mown ;)"
return
try:
command = [
"yt-dlp",
"-w",
"-N",
4,
"--restrict-filename",
"--embed-thumbnail",
"--embed-chapters",
"--add-metadata",
"--embed-subs",
"--newline",
"--progress-template",
"%(progress.downloaded_bytes)s %(progress.total_bytes)s",
"-t",
"mp4",
"-o",
f"{server_path}/%(extractor)s/%(title)s [%(uploader)s@%(extractor)s] [%(id)s].%(ext)s",
url,
]
output = sp.check_output(list(map(str, command))).decode(errors="ignore").strip()
for line in output:
if "Destination: " not in line:
continue
result["downloaded_path"] = line.split(":", 1)[1].strip()
break
result["message"] = "Downloaded at: {}".format(result["downloaded_path"])
except Exception as e:
result["message"] = "Exception happens: {}".format(e)
raise e
return result
def main():
import json
data: dict[str, str] = json.loads(sys.argv[1])
return worker(data['txt'], data['ap'])
if __name__ == "__main__":
main()and also the volume.conf: # Upload Folder
[/Upload]
~/.copyparty/uploads/
accs:
A: maxim
wG: joe
rwg: *
flags:
xm: aw,c,j,bin/hooks/download_ytdlp_video.pyi tried to print(result(...)["message"])and in verbose-hooks log it didn't captured the stdout stream :) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
the issue you're having is that it doesn't capture stdout by default, so the response is sent to the log instead -- I think the following should work;
|
Beta Was this translation helpful? Give feedback.
the issue you're having is that it doesn't capture stdout by default, so the response is sent to the log instead -- I think the following should work;
xm: j,c1,a.pyxm: c1,b.pya.pyisprint('{"stdout":"hello world"}')b.pyisprint("this works too")