Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server Port from Environment #122

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

FROM python:alpine

ENV YDL_PORT 8080
ENV YDL_BASE_URL /youtube-dl

RUN apk add --no-cache \
ffmpeg \
tzdata
Expand All @@ -20,8 +23,8 @@ RUN apk --update-cache add --virtual build-dependencies gcc libc-dev make \

COPY . /usr/src/app

EXPOSE 8080
EXPOSE ${YDL_PORT}

VOLUME ["/youtube-dl"]

CMD ["uvicorn", "youtube-dl-server:app", "--host", "0.0.0.0", "--port", "8080"]
CMD ["uvicorn", "youtube-dl-server:app", "--host", "0.0.0.0", "--port", ${YDL_PORT}]
15 changes: 9 additions & 6 deletions youtube-dl-server.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sys
import subprocess
import os

from starlette.status import HTTP_303_SEE_OTHER
from starlette.applications import Starlette
Expand All @@ -12,6 +13,8 @@

from yt_dlp import YoutubeDL

base_url = os.environ.get('YDL_BASE_URL','/')

templates = Jinja2Templates(directory="templates")
config = Config(".env")

Expand All @@ -27,11 +30,11 @@


async def dl_queue_list(request):
return templates.TemplateResponse("index.html", {"request": request})
return templates.TemplateResponse("index.html", {"request": request, "base_url": base_url})


async def redirect(request):
return RedirectResponse(url="/youtube-dl")
return RedirectResponse(url="/"+base_url)


async def q_put(request):
Expand Down Expand Up @@ -127,10 +130,10 @@ def download(url, request_options):

routes = [
Route("/", endpoint=redirect),
Route("/youtube-dl", endpoint=dl_queue_list),
Route("/youtube-dl/q", endpoint=q_put, methods=["POST"]),
Route("/youtube-dl/update", endpoint=update_route, methods=["PUT"]),
Mount("/static", app=StaticFiles(directory="static"), name="static"),
Route(base_url, endpoint=dl_queue_list),
Route(base_url+"/q", endpoint=q_put, methods=["POST"]),
Route(base_url+"/update", endpoint=update_route, methods=["PUT"]),
Mount(base_url+"/static", app=StaticFiles(directory="static"), name="static"),
]

app = Starlette(debug=True, routes=routes)
Expand Down