From a0a5c46108a33a30debc86f358e47bc29cb3c7d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C5=BD=C3=A1=C4=8Dek?= Date: Mon, 5 Dec 2022 18:48:26 +0100 Subject: [PATCH] Initial --- Dockerfile | 24 ++++++++++++++++++++++++ Dockerfile2 | 21 +++++++++++++++++++++ api.py | 37 +++++++++++++++++++++++++++++++++++++ main.py | 16 ++++++++++++++++ 4 files changed, 98 insertions(+) create mode 100644 Dockerfile create mode 100644 Dockerfile2 create mode 100644 api.py create mode 100644 main.py diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a88cd39 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +FROM ubuntu:20.04 + +ENV TERM linux +ENV DEBIAN_FRONTEND noninteractive + +RUN apt-get update +RUN apt-get upgrade -y +RUN apt-get install -y python3-pip tor +RUN pip3 install --upgrade ulozto-downloader[auto-captcha] + +RUN pip3 install fastapi uvicorn subprocess.run + +RUN cd /opt/ +RUN mkdir /path/ + +COPY api.py /opt/api.py +#CMD ["python3", "/opt/api.py"] +WORKDIR /opt/ +ENTRYPOINT ["uvicorn", "api:app", "--reload" , "--host", "0.0.0.0", "--port", "8000"] +#ENTRYPOINT ["python3", /opt/api.py"] +#CMD ["/bin/bash"] + +# cd /path/ +# ulozto-downloader --parts 15 "" \ No newline at end of file diff --git a/Dockerfile2 b/Dockerfile2 new file mode 100644 index 0000000..2e08513 --- /dev/null +++ b/Dockerfile2 @@ -0,0 +1,21 @@ +FROM ubuntu:20.04 + +ENV TERM linux +ENV DEBIAN_FRONTEND noninteractive + +RUN apt-get update +RUN apt-get upgrade -y +RUN apt-get install -y python3-pip tor +RUN pip3 install --upgrade ulozto-downloader[auto-captcha] + +RUN cd /opt/ +RUN mkdir /path/ + +#CMD ["python3", "/opt/api.py"] +WORKDIR /opt/ +CMD ["/bin/bash"] +#ENTRYPOINT ["python3", /opt/api.py"] +#CMD ["/bin/bash"] + +# cd /path/ +# ulozto-downloader --parts 15 "" \ No newline at end of file diff --git a/api.py b/api.py new file mode 100644 index 0000000..86f34d4 --- /dev/null +++ b/api.py @@ -0,0 +1,37 @@ +from typing import Union + +from fastapi import FastAPI +import os +import subprocess, signal +import threading + + +app = FastAPI() + + +@app.get("/") +def read_root(): + return {"status": "Success"} + + +@app.get("/download/") +def read_item(url: Union[str, None] = None, parts: Union[int, None] = None): + if parts is None: + parts = "15" + + os.chdir('/path/') + separator = '#' + url = url.split(separator, 1)[0] + print("URL: ", url) + + + + #command = ["nohup ulozto-downloader", "--parts", parts, url] + #os.system("nohup ulozto-downloader --parts " + parts + " " + url) + #command = subprocess.Popen(["ulozto-downloader"] + "--parts " + parts + " " + url + " >&/dev/null &", stdin=None, stdout=None, stderr=None, close_fds=True) + + cmd = 'nohup python /usr/local/bin/ulozto-downloader "--parts" "%s" "%s" &' % (parts, url) + os.system(cmd) + + + return {"status": "Success", "link": url, "parts": parts} diff --git a/main.py b/main.py new file mode 100644 index 0000000..68aa93d --- /dev/null +++ b/main.py @@ -0,0 +1,16 @@ +# This is a sample Python script. + +# Press Shift+F10 to execute it or replace it with your code. +# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings. + + +def print_hi(name): + # Use a breakpoint in the code line below to debug your script. + print(f'Hi, {name}') # Press Ctrl+8 to toggle the breakpoint. + + +# Press the green button in the gutter to run the script. +if __name__ == '__main__': + print_hi('PyCharm') + +# See PyCharm help at https://www.jetbrains.com/help/pycharm/