Youtube Downloader
Youtoube Download Window OS์์ Python์ผ๋ก Youtube ์์์ ๋ค์ด๋ก๋ ํ๋ ๋ฐฉ๋ฒ 1. Python Code ์์ฑ yt-dlp ํจํค์ง๋ฅผ ๋ค์ด๋ฐ๋๋ค. pip install yt-dlp ๋ช ๋ น์ผ๋ก ์์ฝ๊ฒ ๋ค์ด๋ก๋ ๊ฐ๋ฅํ๋ค. github ์ฃผ์๋ ๋ค์๊ณผ ๊ฐ๋ค. : https://github.com/yt-dlp/yt-dlp ์ฝ๋๋ฅผ ์์ฑํ๋ค. ์๋๋ ์ํ ์ฝ๋์ด๋ค. import yt_dlp import os import time ########## # ์ค์ ########## # ์ต๋ ์ฌ์๋ ํ์ MAX_RETRIES = 3 # ์ฌ์๋ ์ฌ์ด์ ๋๊ธฐ ์๊ฐ (์ด) RETRY_DELAY = 5 # ๋ค์ด๋ก๋ ๋ฆฌ์คํธ download_lists = [ { "name": 'FOLDER_NAME', # ๋ค์ด๋ก๋ ๋ฐ์ ํด๋ ์ด๋ฆ "url": 'https://www.youtube.com/watch?v=CJuIRe_1c2g&list=RDMM&start_radio=1&rv=R4CecLdF11E', # ๋ค์ด๋ก๋ ํ playlist URL }, { "name": 'SAMPLE2', "url": 'https://www.youtube.com/watch?v=66l5r_IEZrI&list=RDGMEMYH9CUrFO7CfLJpaD7UR85w&start_radio=1&rv=CJuIRe_1c2g', }, ] ########## # ๋ค์ด๋ก๋ ์์ ########## for idx, list in enumerate(download_lists): # 'ํด๋์ด๋ฆ/์์์ ๋ชฉ.ํ์ฅ์' ํ์์ผ๋ก ๋ค์ด๋ก๋ output_dir = os.path.join(f'./{list["name"]}/', '%(title)s.%(ext)s') ydl_opt = { 'outtmpl': output_dir, 'format': 'bestaudio/best', # ๋ค์ด๋ก๋ํ ํฌ๋งท ์ง์ 'download_archive': 'downloaded.txt', # ๋ค์ด๋ก๋ ์์นด์ด๋ธ ํ์ผ ์ง์ (๋ฏธ๋ฆฌ ๋ค์ด๋ฐ์ ํญ๋ชฉ๋ค์ ์ฒดํฌํ์ฌ ์ค๋ณต์ผ๋ก ๋ฐ์ง ์๋๋ก ํ๋ ๊ธฐ๋กํ์ผ) 'postprocessors': [{ 'key': 'FFmpegExtractAudio', 'preferredcodec': 'mp3', # mp3ํฌ๋ฉง์ผ๋ก ๋ณํ 'preferredquality': '192', }], 'verbose': True, # ์์ธํ ๋๋ฒ๊น ์ ๋ณด ์ถ๋ ฅ 'ignoreerrors': True, # ๋ค์ด๋ก๋ ์ค๋ฅ ๋ฌด์ } for attempt in range(1, MAX_RETRIES + 1): try: with yt_dlp.YoutubeDL(ydl_opt) as ydl: ydl.download([ list["url"] ]) print(f'{list["name"]}:: ๋ค์ด๋ก๋ ์๋ฃ') break except Exception as e: print(f'{list["name"]}:: ๋ค์ด๋ก๋ ์คํจ ({attempt}/{MAX_RETRIES}): {e}') if attempt < MAX_RETRIES: print(f'{list["name"]}:: {RETRY_DELAY}์ด ํ ๋ค์ ์๋ํฉ๋๋ค...') time.sleep(RETRY_DELAY) else: print(f'{list["name"]}:: ์ต๋ ์ฌ์๋ ํ์๋ฅผ ์ด๊ณผํ์ต๋๋ค. ๋ค์ด๋ก๋๋ฅผ ์ค๋จํฉ๋๋ค.') print('๋ชจ๋ ํญ๋ชฉ ๋ค์ด๋ก๋ ์๋ฃ') ๋ค๋ฅธ๊ฒ๋ค์ ์์ ํ ํ์ ์๊ณ , download_lists ์ ๋ค์ด๋ก๋ ํ Youtube ์ฌ์๋ชฉ๋ก์ ๋ฃ์ด์ค๋ค. ...