Skip to content

Instantly share code, notes, and snippets.

@limboinf
Created June 7, 2023 16:22
Show Gist options
  • Save limboinf/062083702529c90bead2ff0a45776c41 to your computer and use it in GitHub Desktop.
Save limboinf/062083702529c90bead2ff0a45776c41 to your computer and use it in GitHub Desktop.
yt-dlp 快速下载YouTube视频
import os
import subprocess
import multiprocessing
from colorama import Fore, Back, Style
def download_url(url):
flag = f'PID: {os.getpid()} --> 下载: {url}'
print(Fore.CYAN + f'--> {flag}'+ Style.RESET_ALL)
process = subprocess.Popen([
"yt-dlp",
"--proxy",
"socks5://127.0.0.1:7890",
"--write-auto-subs",
"-f",
"bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best",
"-o",
"videos/%(title)s.%(ext)s",
url
], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
while True:
output = process.stdout.readline()
if output == b'' and process.poll() is not None:
break
if output:
print(f' ... {flag}' + output.decode().strip())
process.wait()
print(Fore.GREEN + f'<-- [DONE]{flag}'+ Style.RESET_ALL)
def main():
with open('list.txt') as f:
urls = f.readlines()
pool = multiprocessing.Pool(processes=8)
pool.map(download_url, urls)
pool.close()
pool.join()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment