Compare commits

...

2 Commits

Author SHA1 Message Date
879661a2ac docker 2023-07-22 00:00:06 -07:00
c5e2eb3c37 cache prune interval 2023-07-21 23:59:45 -07:00
4 changed files with 72 additions and 28 deletions

View File

@ -1,32 +1,36 @@
u2b.cx {
import common
route {
@www path / /favicon.ico
redir @www https://www.u2b.cx{uri} permanent
respond /robots.txt "User-agent: *
#edit for deployment
#u2b.cx {
:80 {
log
handle_path /proxy/* {
@gv path_regexp gvurl ^\/([a-z0-9-]+\.googlevideo\.com)
handle @gv {
uri strip_prefix /{re.gvurl.1}
reverse_proxy {
to {re.gvurl.1}:443
header_up Host {re.gvurl.1}
transport http {
tls
}
}
}
handle {
respond 400
}
}
handle {
route {
@www path / /favicon.ico
redir @www https://www.u2b.cx{uri} permanent
respond /robots.txt "User-agent: *
Disallow: /
"
respond /.* 403
@notget not method GET
respond @notget 403
reverse_proxy http://127.29.151.200:52482
}
}
proxy.u2b.cx {
import common
@gv path_regexp gvurl ^\/([a-z0-9-]+\.googlevideo\.com)
handle @gv {
uri strip_prefix /{re.gvurl.1}
#uri strip_prefix {re.gvurl.0} doesn't work for some reason despite that value being equal to /{re.gvurl.1}
reverse_proxy {
to {re.gvurl.1}:443
header_up Host {re.gvurl.1}
transport http {
tls
}
respond /.* 403
@notget not method GET
respond @notget 403
reverse_proxy http://app:8080
}
}
}

9
Dockerfile Normal file
View File

@ -0,0 +1,9 @@
FROM python:3.11
RUN useradd -r -m u2b
RUN apt update && apt install -y ffmpeg
RUN pip install --no-cache-dir python-ffmpeg yt-dlp
COPY . /app
WORKDIR /app
USER u2b
ENV PORT=8080
CMD ["python", "server.py"]

22
docker-compose.yml Normal file
View File

@ -0,0 +1,22 @@
version: "3.8"
name: "u2bcx"
services:
app:
build: .
restart: always
environment:
- PROXY=/proxy/
caddy:
image: caddy:2.6
restart: always
ports:
- "80:80"
- "443:443"
- "443:443/udp"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile
- caddy_data:/data
- caddy_config:/config
volumes:
caddy_data:
caddy_config:

View File

@ -3,8 +3,9 @@ from importlib.metadata import version
print("yt-dlp version", version("yt_dlp"))
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
from urllib.parse import unquote, urlparse, parse_qs
from threading import Event
from threading import Event, Thread
from datetime import datetime, timedelta
from time import sleep
from os import environ
import logging
import re
@ -22,6 +23,14 @@ def get_expire(url):
ctx_cache = {}
ips_running_ytdl = []
def cache_prune_loop():
while True:
sleep(3600)
for query, ctx in ctx_cache:
if datetime.now() >= ctx['expire']:
del ctx[query]
Thread(target=cache_prune_loop).start()
class Handler(BaseHTTPRequestHandler):
def address_string(self):
return getattr(self, 'headers', {}).get('X-Forwarded-For', '').split(',')[0] or self.client_address[0]