首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Youtube视频下载器

Youtube视频下载器
EN

Stack Overflow用户
提问于 2020-08-30 12:00:59
回答 1查看 674关注 0票数 1
代码语言:javascript
复制
from tkinter import *
from tkinter import ttk
from tkinter import filedialog
from pytube import YouTube
FolderName = ''
fileSizeInBytes = 0
MaxFileSize = 0


def openDirectory():
    global FolderName
    FolderName = filedialog.askdirectory()
    if (len(FolderName)> 1):
        fileLocationLabelError.config(text=FolderName,
                                      fg='green')
    else:
        fileLocationLabelError.config(text='Please Choose Folder',
                                      fg='red')



def DownloadFile():
    global MaxFileSize,fileSizeInBytes


    choice = youtubeChoices.get()
    video = youtubeEntry.get()


    if (len(video)>1):
        youtubeEntryError.config(text='')
        print(video,'at',FolderName)
        yt = YouTube(video,on_progress_callback=progress)
        print('video name is:\n\n',yt.title)

        if (choice == downloadChoices[0]):
            print('1080p video is downloading...')
            loadingLabel.config(text='1080p video file downloading...')
            selectVideo =yt.streams.filter(progressive=True).first()

        elif (choice == downloadChoices[1]):
            print('720p video is downloading...')
            loadingLabel.config(text='720p video file downloading...')
            selectVideo =yt.streams.filter(progressive=True).first()

        elif (choice == downloadChoices[2]):
            print('480p video is downloading...')
            loadingLabel.config(text='480p video file downloading...')
            selectVideo = yt.streams.filter(progressive=True,
                                            file_extension='mp4').last
        elif (choice == downloadChoices[3]):
            print('3gp file is downloading...')
            selectVideo = yt.streams.filter(file_extension='3gp').first()

        elif (choice == downloadChoices[4]):
            print('Audio file is downloading...')
            selectVideo = yt.streams.filter(only_audio=True).first()

        fileSizeInBytes = selectVideo.filesize
        MaxFileSize = fileSizeInBytes / 1024000
        MB = str(MaxFileSize) + 'MB'
        print('File size = : {:00.00f}'.format(MaxFileSize))
        #download
        selectVideo.download(FolderName)
        print('Downloaded on : {}'.format(FolderName))
        complete()
    else:
        youtubeEntryError.config(text='Please paste youtube link',
                              fg='red')

def progress(stream= None, chunk=None, file_handle = None, remaining=None):
    percent = (100 * (fileSizeInBytes - remaining)) / fileSizeInBytes
    print('{00.0f}% downloaded'.format(percent))

def complete():
    loadingLabel.config(text='Download completed')




root = Tk()
root.title('YouTube video Downloader')
root.grid_columnconfigure(0,weight=1)
youtubeLinkLabel = Label(root,text='Please paste youtube link here..',
                         fg='blue',font=('Agency FB',30))
youtubeLinkLabel.grid()
youtubeEntryvar = StringVar()
youtubeEntry = Entry(root,width=50, textvariable=youtubeEntryvar)
youtubeEntry.grid(pady=(0,20))
youtubeEntryError = Label(root,fg='red', text='',font=('Agency FB',20))
youtubeEntryError.grid(pady=(0,10))
SaveLabel = Label(root,text='Where to download file?',fg='blue',font=('Agency FB',20,'bold'))
SaveLabel.grid()
SaveEntry = Button(root,width=20,bg='green',fg='white',
                   text='Choose folder',font=('Arial',15),
                   command=openDirectory)
SaveEntry.grid()
fileLocationLabelError = Label(root,text='',font=('Agency FB',20))
fileLocationLabelError.grid(pady=(0,0))
youtubeChooseLabel = Label(root,text='Please choose what to download:',
                           font=('Agency FB',20))
youtubeChooseLabel.grid()
downloadChoices = ['Mp4 1080p',
                   'Mp4 720p',
                   'Mp4 480p',
                   'Video 3gp',
                   'song mp3']
youtubeChoices = ttk.Combobox(root,values=downloadChoices)
youtubeChoices.grid()
downloadButton = Button(root,text='Download',width=15,bg='green',
                        command=DownloadFile)
downloadButton.grid()


loadingLabel = ttk.Label(root,text='App developed by |> CID',
                         font=('Agency FB',20))
loadingLabel.grid()
root.mainloop()

我这里有个错误

我该做些变量吗?

如果你看到这个问题,你能解释一下基本问题吗?

因为我的英语不好

谢谢

它给出一个类型错误

我是Tkinter的新手

我再次检查了我的代码,但在我看来没有问题。

感谢所有的StackOverflow社区

下面是错误

代码语言:javascript
复制
 Video downloader app । using Python and Pytube
1080p video is downloading...
File size = : 97
Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\Toshiba\AppData\Local\Programs\Python\Python37\lib\tkinter\__init__.py", line 1705, in __call__
    return self.func(*args)
  File "C:/Users/Toshiba/Desktop/python_temelleri/youtube video downloader.py", line 64, in DownloadFile
    selectVideo.download(FolderName)
  File "C:\Users\Toshiba\Desktop\python_temelleri\venv\lib\site-packages\pytube\streams.py", line 241, in download
    self.on_progress(chunk, fh, bytes_remaining)
  File "C:\Users\Toshiba\Desktop\python_temelleri\venv\lib\site-packages\pytube\streams.py", line 302, in on_progress
    self._monostate.on_progress(self, chunk, bytes_remaining)
  File "C:/Users/Toshiba/Desktop/python_temelleri/youtube video downloader.py", line 72, in progress
    percent = (100 * (fileSizeInBytes - remaining)) / fileSizeInBytes
TypeError: unsupported operand type(s) for -: 'int' and 'NoneType'
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-08-30 12:10:47

传递给progress方法的progress参数是None

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63657201

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档