Python初學特訓班-ch09\tkdownload.py |
|
bruce
更新時間:2018/3/1 下午 11:51:08 |
|
執行後發生以下錯誤訊息,請問是什麼原因: Traceback (most recent call last): File "C:/Workspace/tkdownload.py", line 66, in <module> yt = YouTube() File "C:\VirtualEnv\VirtualEnv for Workspace\lib\site-packages\pytube\__main__.py", line 68, in __init__ self.video_id = extract.video_id(url) File "C:\VirtualEnv\VirtualEnv for Workspace\lib\site-packages\pytube\extract.py", line 43, in video_id return regex_search(r'(?:v=|\/)([0-9A-Za-z_-]{11}).*', url, group=1) File "C:\VirtualEnv\VirtualEnv for Workspace\lib\site-packages\pytube\helpers.py", line 35, in regex_search results = regex.search(string) TypeError: expected string or bytes-like object |
|
|
|
|
bruce
更新時間:2018/3/2 下午 10:16:32 |
|
您好, 目前已經可以呼叫出介面,但是當我比照課程貼上阿夾魔術教室 隱形橡皮筋的youtube網址,並且按下確認,存檔路徑為C:\Workspace,此位置與tkdownload.py位置相同,然後選擇第一個檔案格式,再選擇下載影片後出現以下錯誤訊息
Exception in Tkinter callback Traceback (most recent call last): File "C:\Python3.6.4\Lib\tkinter\__init__.py", line 1699, in __call__ return self.func(*args) File "C:/Workspace/tkdownload.py", line 43, in clickDown getvideo.download(vpath) #下載影片 AttributeError: 'str' object has no attribute 'download'
請問line 43哪出現錯誤呢?
|
|
|
|
文淵閣工作室
更新時間:2018/3/5 上午 05:41:31 |
|
這是 pytube 本身的 bug:(3gp 144p)會產生錯誤,(3gp 240p)雖可下載,但會讓程式當掉。 若一定需要 3gp,建議下載 mp4 或 webm 再轉檔 (例如「格式工場」)。 |
|
|
|
林劭謙
更新時間:2019/1/11 下午 02:49:45 |
|
執行後發生下列問題: Traceback (most recent call last):
File "<ipython-input-57-ce1367c6b937>", line 1, in <module> runfile('C:/Users/user/Desktop/python (1)/09/untitled24.py', wdir='C:/Users/user/Desktop/python (1)/09')
File "C:\Users\user\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 668, in runfile execfile(filename, namespace)
File "C:\Users\user\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 108, in execfile exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/user/Desktop/python (1)/09/untitled24.py", line 68, in <module> yt=pytube.YouTube()
File "C:\Users\user\Anaconda3\lib\site-packages\pytube\__main__.py", line 70, in __init__ self.video_id = extract.video_id(url)
File "C:\Users\user\Anaconda3\lib\site-packages\pytube\extract.py", line 63, in video_id return regex_search(r'(?:v=|\/)([0-9A-Za-z_-]{11}).*', url, group=1)
File "C:\Users\user\Anaconda3\lib\site-packages\pytube\helpers.py", line 61, in regex_search results = regex.search(string)
TypeError: expected string or bytes-like object |
|
|
|
文淵閣工作室
更新時間:2019/1/14 上午 06:38:05 |
|
依錯誤訊息是 68 列「yt=pytube.YouTube()」出錯,照書上應是「yt=YouTube()」。
|
|
|
|
林劭謙
更新時間:2019/1/14 上午 09:40:52 |
|
Traceback (most recent call last):
File "<ipython-input-5-f84d9914be91>", line 1, in <module> runfile('C:/Users/user/Desktop/python (1)/09/tkdownload.py', wdir='C:/Users/user/Desktop/python (1)/09')
File "C:\Users\user\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 668, in runfile execfile(filename, namespace)
File "C:\Users\user\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 108, in execfile exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/user/Desktop/python (1)/09/tkdownload.py", line 68, in <module> yt=YouTube()
File "C:\Users\user\Anaconda3\lib\site-packages\pytube\__main__.py", line 70, in __init__ self.video_id = extract.video_id(url)
File "C:\Users\user\Anaconda3\lib\site-packages\pytube\extract.py", line 63, in video_id return regex_search(r'(?:v=|\/)([0-9A-Za-z_-]{11}).*',url, group=1)
File "C:\Users\user\Anaconda3\lib\site-packages\pytube\helpers.py", line 61, in regex_search results = regex.search(string)
TypeError: expected string or bytes-like object
|
|
|
|
林劭謙
更新時間:2019/1/14 上午 09:42:40 |
|
import tkinter as tk from pytube import YouTube
win=tk.Tk() win.geometry("450x320") win.title("下載Youtube影片") getvideo = "" strftype = "" listvideo = [] listradio = [] video = tk.IntVar() url = tk.StringVar() path = tk.StringVar() filename = tk.StringVar() yt=YouTube() 更改之後還是如此,請問發生什麼問題 |
|
|
|
文淵閣工作室
更新時間:2019/1/15 上午 06:12:08 |
|
如此無法看出問題,請將程式寄到 service@e-happy.com.tw 給我們測試。 |
|
|
|
林劭謙
更新時間:2019/1/15 下午 06:09:52 |
|
def clickUrl(): global listvideo, listradio labelMsg.config(text="") if(url.get()==""): labelMsg.config(text="網址欄位必須輸入!") else: try: yt.url = url.get() print(url.get()) rbvalue = 1 filename.set(yt.filename) for v1 in yt.get_videos(): listvideo.append(v1) for v2 in listvideo: rbtem = tk.Radiobutton(frame3, text=v2, variable=video, value=rbvalue, command=rbVideo) if(rbvalue==1): rbtem.select() listradio.append(rbtem) rbtem.grid(row=rbvalue-1, column=0, sticky="w") rbvalue += 1 btnDown.config(state="normal") except: labelMsg.config(text="找不到此 Youtube 影片!") def rbVideo(): global getvideo, strftype labelMsg.config(text="") strvideo = str(listvideo[video.get()-1]) start1 = strvideo.find("(.") end1 = strvideo.find(")") strftype = strvideo[start1+2 : end1] end2 = strvideo.rfind(" - ") strresolution = strvideo[end1+4 : end2] getvideo = yt.get(strftype, strresolution) print(strftype, strresolution) def clickDown(): global getvideo, strftype, listradio labelMsg.config(text="") fpath = path.get() #取得輸入存檔資料夾 fpath = fpath.replace("\\", "\\\\") #將「\」轉換為「\\」 yt.set_filename(filename.get()) getvideo.download(fpath) for r in listradio: #移除選項按鈕 r.destroy() listradio.clear() #清除串列 listvideo.clear() url.set("") #清除輸入框 filename.set("") btnDown.config(state="disabled") #設定「下載影片」按鈕無效 import tkinter as tk from pytube import YouTube
win=tk.Tk() win.geometry("450x320") #設定主視窗解析度 win.title("下載Youtube影片") getvideo = "" #影片格式 strftype = "" #影片型態 listvideo = [] #影片格式串列 listradio = [] #選項按鈕串列 video = tk.IntVar() #選項按鈕值 url = tk.StringVar() #影片網址 path = tk.StringVar() #存檔資料夾 filename = tk.StringVar() #存檔名稱 yt=YouTube()
frame1 = tk.Frame(win, width=450) frame1.pack() label1=tk.Label(frame1, text="Youtube網址:") entryUrl = tk.Entry(frame1, textvariable=url) entryUrl.config(width=40) btnUrl = tk.Button(frame1, text="確定", command=clickUrl) label1.grid(row=0, column=0, sticky="e") entryUrl.grid(row=0, column=1) btnUrl.grid(row=0, column=2)
label2=tk.Label(frame1, text="存檔路徑:") entryPath = tk.Entry(frame1, textvariable=path) entryPath.config(width=40) label2.grid(row=1, column=0, pady=6, sticky="e") entryPath.grid(row=1, column=1)
label3=tk.Label(frame1, text="檔案名稱:") entryFile = tk.Entry(frame1, textvariable=filename) entryFile.config(width=40) label3.grid(row=2, column=0, pady=3, sticky="e") entryFile.grid(row=2, column=1)
frame2 = tk.Frame(win) frame2.pack() btnDown = tk.Button(frame2, text="下載影片", command=clickDown) btnDown.pack(pady=6) btnDown.config(state="disabled") #開始時設定「下載影片」按鈕無效
labelMsg = tk.Label(win, text="", fg="red") #訊息標籤 labelMsg.pack()
frame3 = tk.Frame(win) #選項按鈕區塊 frame3.pack() win.mainloop() 執行後跑錯誤訊息,不知道出了什麼問題 |
|
|
|
文淵閣工作室
更新時間:2019/1/16 上午 07:52:28 |
|
我們測試程式執行正常下載影片。 你有照上面安裝 pytube 6.4.2 版嗎? |
|
|
|
Temis
更新時間:2019/4/30 下午 03:22:29 |
|
你好,請問該如何知道已經正確安裝pytube6.4.2 ? |
|
|
|
Temis
更新時間:2019/4/30 下午 03:38:10 |
|
好 確定pytube為6.4.2了,但是輸入正確的網址卻都顯示查無該影片,該怎麼辦? |
|
|
|
|
|
|
|