New Ribbon
Canva+AI創意設計與品牌應用250招:從商業技巧、社群祕技到AI圖文影音特效 快快樂樂學威力導演2024.影音剪輯與AI精彩創作 文淵閣工作室祝福大家新年快樂.龍年吉祥 Power Automate自動化超效率工作術 Midjourney AI圖像魔導書:搭配ChatGPT魔法加倍 超人氣FB+IG+LINE社群經營與行銷力(第二版) 翻倍效率工作術:不會就太可惜的 Excel × ChatGPT 自動化應用 AppInventor2零基礎入門班中文版(第六版) Python零基礎入門班(第四版) C語言學習聖經 用Canva設計超快超質感:平面、網頁、電子書、簡報、影片製作與AI繪圖最速技 PHP8/MySQL網頁程式設計自學聖經 翻倍效率工作術 - 不會就太可惜的Power BI大數據視覺圖表設計與分析(第三版) 社群經營一定要會的影音剪輯與動畫製作術 Notion高效管理250招:筆記×資料庫×團隊協作,數位生活與工作最佳幫手 Office 2021高效實用範例必修16課(附500分鐘影音教學/範例檔) Excel自學聖經(第二版):從完整入門到職場活用的技巧與實例大全 網路開店×拍賣王:蝦皮來了(第二版) 專家都在用的Google最強實戰:表單、文件、試算、簡報、遠距與線上會議 超人氣 Instagram 視覺行銷力(第二版):小編不敗,經營 IG 品牌人氣王的 120 個秘技!

 

  Python初學特訓班-ch09\tkdownload.py

bruce

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

文淵閣工作室

文淵閣工作室
更新時間:2018/3/2 上午 07:50:09

 

pytube 從 7.0.0 版開始語法大幅改變,需安裝 7.0.0 以前版本的 pytube,方法:
pip uninstall pytube
pip install -v pytube==6.4.2
因套件中檔案方式略有變更,請將 <tkdownload.py> 範例檔程式 42 及 43 列修正為:
yt.set_filename(filename.get())
getvideo.download(fpath)  #下載影片
或由下列網址下載更新檔:
https://drive.google.com/file/d/1szO92bplYIR_AsGLFHrslZkBVOyIxYSm/view?usp=sharin

bruce

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

Temis
更新時間:2019/4/30 下午 03:22:29

 

你好,請問該如何知道已經正確安裝pytube6.4.2 ?

Temis

Temis
更新時間:2019/4/30 下午 03:38:10

 

好 確定pytube為6.4.2了,但是輸入正確的網址卻都顯示查無該影片,該怎麼辦?

文淵閣工作室

文淵閣工作室
更新時間:2019/5/2 上午 10:10:32

 

解決方法較複雜,將其寫成部落格,請參考:
http://blog.e-happy.com.tw/pytube%E7%84%A1%E6%B3%95%E4%B8%8B%E8%BC%89%E5%BD%B1%E7%89%87%E4%BF%AE%E6%AD%A320190501/




 

 

Re:Python初學特訓班-ch09\tkdownload.py

請輸入姓名。

已超出字元數目的最大值。


請輸入電子郵件。

格式無效。


請輸入內容。