Created
June 7, 2023 16:22
-
-
Save limboinf/062083702529c90bead2ff0a45776c41 to your computer and use it in GitHub Desktop.
yt-dlp 快速下载YouTube视频
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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