add IPv6 preference option

This commit is contained in:
BennyThink 2022-03-10 21:46:02 +08:00
parent a215bcf245
commit fcb01bd140
No known key found for this signature in database
GPG Key ID: 6CD0DBDA5235D481
3 changed files with 30 additions and 20 deletions

View File

@ -99,7 +99,7 @@ vim env/ytdl.env
you can configure all the following environment variables:
* PYRO_WORKERS: number of workers for pyrogram, default is 100
* WORKERS: workers count for celery,it'll be doubled.
* WORKERS: workers count for celery
* APP_ID: **REQUIRED**, get it from https://core.telegram.org/
* APP_HASH: **REQUIRED**
* TOKEN: **REQUIRED**

View File

@ -9,3 +9,9 @@ services:
command: [ "/usr/local/bin/supervisord", "-c" ,"/ytdlbot/conf/supervisor_worker.conf" ]
volumes:
- ./data/instagram.com_cookies.txt:/ytdlbot/ytdlbot/instagram.com_cookies.txt
# network_mode: "host"
# deploy:
# resources:
# limits:
# cpus: '0.3'
# memory: 1500M

View File

@ -197,21 +197,25 @@ def ytdl_download(url, tempdir, bm) -> dict:
formats = [
"bestvideo[ext=mp4]+bestaudio[ext=m4a]/bestvideo+bestaudio",
"bestvideo[vcodec^=avc]+bestaudio[acodec^=mp4a]/best[vcodec^=avc]/best",
""
None
]
adjust_formats(chat_id, url, formats)
add_instagram_cookies(url, ydl_opts)
for f in formats:
if f:
ydl_opts["format"] = f
address = ["::", "0.0.0.0"] if os.getenv("ipv6") else [None]
for format_ in formats:
ydl_opts["format"] = format_
for addr in address:
# IPv6 goes first in each format
ydl_opts["source_address"] = addr
try:
logging.info("Downloading for %s with format %s", url, f)
logging.info("Downloading for %s with format %s", url, format_)
with ytdl.YoutubeDL(ydl_opts) as ydl:
ydl.download([url])
response["status"] = True
response["error"] = ""
break
except (ValueError, DownloadError) as e:
logging.error("Download failed for %s ", url)
response["status"] = False