Compare commits
2 Commits
f9fab223e8
...
879661a2ac
Author | SHA1 | Date | |
---|---|---|---|
879661a2ac | |||
c5e2eb3c37 |
58
Caddyfile
58
Caddyfile
@ -1,32 +1,36 @@
|
|||||||
u2b.cx {
|
#edit for deployment
|
||||||
import common
|
#u2b.cx {
|
||||||
route {
|
:80 {
|
||||||
@www path / /favicon.ico
|
log
|
||||||
redir @www https://www.u2b.cx{uri} permanent
|
handle_path /proxy/* {
|
||||||
|
@gv path_regexp gvurl ^\/([a-z0-9-]+\.googlevideo\.com)
|
||||||
respond /robots.txt "User-agent: *
|
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: /
|
Disallow: /
|
||||||
"
|
"
|
||||||
respond /.* 403
|
respond /.* 403
|
||||||
@notget not method GET
|
@notget not method GET
|
||||||
respond @notget 403
|
respond @notget 403
|
||||||
|
|
||||||
reverse_proxy http://127.29.151.200:52482
|
reverse_proxy http://app:8080
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
9
Dockerfile
Normal file
9
Dockerfile
Normal 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
22
docker-compose.yml
Normal 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:
|
11
server.py
11
server.py
@ -3,8 +3,9 @@ from importlib.metadata import version
|
|||||||
print("yt-dlp version", version("yt_dlp"))
|
print("yt-dlp version", version("yt_dlp"))
|
||||||
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
||||||
from urllib.parse import unquote, urlparse, parse_qs
|
from urllib.parse import unquote, urlparse, parse_qs
|
||||||
from threading import Event
|
from threading import Event, Thread
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
from time import sleep
|
||||||
from os import environ
|
from os import environ
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
@ -22,6 +23,14 @@ def get_expire(url):
|
|||||||
ctx_cache = {}
|
ctx_cache = {}
|
||||||
ips_running_ytdl = []
|
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):
|
class Handler(BaseHTTPRequestHandler):
|
||||||
def address_string(self):
|
def address_string(self):
|
||||||
return getattr(self, 'headers', {}).get('X-Forwarded-For', '').split(',')[0] or self.client_address[0]
|
return getattr(self, 'headers', {}).get('X-Forwarded-For', '').split(',')[0] or self.client_address[0]
|
||||||
|
Loading…
Reference in New Issue
Block a user