pytube는 dependency가 없는 youtube 비디오를 다운로드할 수 있는 라이브러리다.
pytube — pytube 12.1.0 documentation
from tkinter import * from tkinter import messagebox from pytube import YouTube import glob import os.path import subprocess # set root = Tk() root.title("my converter") root.geometry("500x200") root.resizable(False, False) DOWNLOAD_FOLDER = "D:\\youtube\\" #convert def convert(): #유튜브 전용 인스턴스 생성 par = lnk.get() print(par) yt = YouTube(par) print("start!") if(Radiovar.get() == 1): print("type: mp4") yt.streams.filter(file_extension='mp4') yt.streams.get_highest_resolution().download(DOWNLOAD_FOLDER) #yt.streams.filter().first().download(DOWNLOAD_FOLDER) else: print("type: mp3") yt.streams.filter(only_audio=True).all() yt.streams.filter(only_audio=True).first().download(DOWNLOAD_FOLDER) print("success") src = yt.streams.first().default_filename[:-4] + 'mp4' print(src) print(DOWNLOAD_FOLDER, src[:-3]+'mp3') # mp4에서 mp3로 변환 subprocess.call(['ffmpeg', '-i', os.path.join(DOWNLOAD_FOLDER, src), os.path.join(DOWNLOAD_FOLDER, src[0:-3]+'mp3')]) # 변환되기 전 mp4파일 삭제 os.remove(os.path.join(DOWNLOAD_FOLDER, src)) messagebox.showinfo("success","converted!") #메시지 박스를 띄운다. #main lbl = Label(root, text="YouTube Converter!") lbl.pack() lnk = Entry(root) lnk.pack(fill="x") st = StringVar() Radiovar = IntVar() Radio_button1 = Radiobutton(text="mp4",variable=Radiovar,value=1) Radio_button2 = Radiobutton(text="mp3(default)",variable=Radiovar,value=2) Radio_button1.pack() Radio_button2.pack() place = Label(root, text="\n") place.pack() btn = Button(root, text="convert",command=convert) btn.pack() root.mainloop() |
Ignoring exception in on_message Traceback (most recent call last): File "/.local/lib/python3.9/site-packages/pytube/__main__.py", line 177, in fmt_streams extract.apply_signature(stream_manifest, self.vid_info, self.js) File "/.local/lib/python3.9/site-packages/pytube/extract.py", line 409, in apply_signature cipher = Cipher(js=js) File "/.local/lib/python3.9/site-packages/pytube/cipher.py", line 33, in __init__ raise RegexMatchError(pytube.exceptions.RegexMatchError: __init__: could not find match for ^\\w+\\W |
cipher.py var_regex = re.compile(r"^\w+\W") => var_regex = re.compile(r"^\$*\w+\W") |
'지식 > Python' 카테고리의 다른 글
Python - jupyter notebook 설치 (0) | 2024.06.15 |
---|---|
Jupyter Notebook - 기본 디렉토리 변경 (0) | 2023.04.10 |
Windows10 에 ffmpeg 설치하기 (0) | 2022.05.29 |
Python - 웹크롤링 (0) | 2021.06.28 |
Python - Anaconda 설치 및 Notepad++로 실행하기 (0) | 2020.10.05 |
댓글