mirror of
https://github.com/omg-xtao/ytdlbot.git
synced 2025-01-30 09:48:35 +00:00
add IPv6 preference option
This commit is contained in:
parent
a215bcf245
commit
fcb01bd140
@ -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**
|
||||
|
10
worker.yml
10
worker.yml
@ -6,6 +6,12 @@ services:
|
||||
env_file:
|
||||
- env/ytdl.env
|
||||
restart: always
|
||||
command: ["/usr/local/bin/supervisord", "-c" ,"/ytdlbot/conf/supervisor_worker.conf"]
|
||||
command: [ "/usr/local/bin/supervisord", "-c" ,"/ytdlbot/conf/supervisor_worker.conf" ]
|
||||
volumes:
|
||||
- ./data/instagram.com_cookies.txt:/ytdlbot/ytdlbot/instagram.com_cookies.txt
|
||||
- ./data/instagram.com_cookies.txt:/ytdlbot/ytdlbot/instagram.com_cookies.txt
|
||||
# network_mode: "host"
|
||||
# deploy:
|
||||
# resources:
|
||||
# limits:
|
||||
# cpus: '0.3'
|
||||
# memory: 1500M
|
@ -197,27 +197,31 @@ 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
|
||||
try:
|
||||
logging.info("Downloading for %s with format %s", url, f)
|
||||
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
|
||||
response["error"] = str(e)
|
||||
except Exception as e:
|
||||
logging.error("UNKNOWN EXCEPTION: %s", e)
|
||||
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, 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
|
||||
response["error"] = str(e)
|
||||
except Exception as e:
|
||||
logging.error("UNKNOWN EXCEPTION: %s", e)
|
||||
|
||||
logging.info("%s - %s", url, response)
|
||||
if response["status"] is False:
|
||||
|
Loading…
Reference in New Issue
Block a user