Jofthomas commited on
Commit
a061382
·
1 Parent(s): 48bc221
Files changed (3) hide show
  1. Dockerfile +5 -0
  2. app.py +8 -0
  3. docker-entrypoint.sh +24 -0
Dockerfile CHANGED
@@ -18,6 +18,11 @@ COPY . .
18
  ENV YT_AUDIO_DIR=/tmp/ytdl
19
  RUN mkdir -p /tmp/ytdl /app/downloads && chmod 777 /tmp/ytdl /app/downloads
20
 
 
 
 
 
 
21
  EXPOSE 7860
22
 
23
  ENV PORT=7860
 
18
  ENV YT_AUDIO_DIR=/tmp/ytdl
19
  RUN mkdir -p /tmp/ytdl /app/downloads && chmod 777 /tmp/ytdl /app/downloads
20
 
21
+ # Add entrypoint to allow runtime DNS/Proxy configuration
22
+ COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
23
+ RUN chmod +x /usr/local/bin/docker-entrypoint.sh
24
+ ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
25
+
26
  EXPOSE 7860
27
 
28
  ENV PORT=7860
app.py CHANGED
@@ -30,6 +30,10 @@ def download_youtube_audio(url: HttpUrl, audio_format: Literal["mp3", "m4a", "wa
30
  - audio_format: Desired audio format (requires ffmpeg in the container)
31
 
32
  The file will be saved under /app/downloads. Ensure the container has write access.
 
 
 
 
33
  """
34
  # Ensure output directory exists
35
  output_dir = "/app/downloads"
@@ -55,6 +59,10 @@ def download_youtube_audio(url: HttpUrl, audio_format: Literal["mp3", "m4a", "wa
55
  "nocheckcertificate": True,
56
  }
57
 
 
 
 
 
58
  info_title: Optional[str] = None
59
  downloaded_id: Optional[str] = None
60
 
 
30
  - audio_format: Desired audio format (requires ffmpeg in the container)
31
 
32
  The file will be saved under /app/downloads. Ensure the container has write access.
33
+
34
+ Networking:
35
+ - If outbound DNS is restricted, set env DNS_SERVERS (space-separated, e.g. "8.8.8.8 1.1.1.1").
36
+ - To route via a proxy, set env YT_PROXY (e.g. http://user:pass@proxy:port).
37
  """
38
  # Ensure output directory exists
39
  output_dir = "/app/downloads"
 
59
  "nocheckcertificate": True,
60
  }
61
 
62
+ proxy_url = os.environ.get("YT_PROXY")
63
+ if proxy_url:
64
+ ydl_opts["proxy"] = proxy_url
65
+
66
  info_title: Optional[str] = None
67
  downloaded_id: Optional[str] = None
68
 
docker-entrypoint.sh ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/sh
2
+ set -e
3
+
4
+ # Optionally configure DNS servers at runtime if provided
5
+ if [ -n "$DNS_SERVERS" ]; then
6
+ {
7
+ for s in $DNS_SERVERS; do
8
+ echo "nameserver $s"
9
+ done
10
+ } > /etc/resolv.conf 2>/dev/null || true
11
+ fi
12
+
13
+ # Optionally configure proxy for outbound requests
14
+ if [ -n "$YT_PROXY" ]; then
15
+ export HTTPS_PROXY="$YT_PROXY"
16
+ export HTTP_PROXY="$YT_PROXY"
17
+ fi
18
+
19
+ # Ensure output directory exists and is writable
20
+ OUTDIR="${YT_AUDIO_DIR:-/tmp/ytdl}"
21
+ mkdir -p "$OUTDIR" 2>/dev/null || true
22
+ chmod 777 "$OUTDIR" 2>/dev/null || true
23
+
24
+ exec "$@"