Youtube video downloader

Aynur Jumageldiyeva
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()

I have got an error here

Should I make some variables intager

If you see this question can you explain it basic

Cause my English is not good

Thanks

It gives an Type error

I am new to Tkinter

I checked my code again, but there was no problem in my opinion

Thanks to all StackOverflow community

Below is the errror

 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'

Aviv Yaniv

The remaining argument passed to progress method is None.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

youtube video downloader with php

分類Dev

Embeded youtube video error

分類Dev

Set youtube video on background

分類Dev

Problems embedding youtube video

分類Dev

Responsive youtube video with iframe

分類Dev

YouTube video in video_player package

分類Dev

How to autoplay a YouTube video in a UIWebView

分類Dev

How to loop an embeded YouTube video?

分類Dev

YouTube video regex in MySQL query

分類Dev

Autostart a youtube video from Javascript

分類Dev

regex to extract youtube video id?

分類Dev

Youtube Video feeds link not working

分類Dev

How do I get a YouTube video thumbnail from the YouTube API?

分類Dev

Get youtube video id from youtube url in smarty template?

分類Dev

youtube-dl - download video from YouTube with subtitles - Tutorial

分類Dev

Displaying a YouTube video with iframe full width of page

分類Dev

Displaying a YouTube video with iframe full width of page

分類Dev

Displaying a YouTube video with iframe full width of page

分類Dev

Youtube v3 API video language

分類Dev

react-native-video playVimeoとYouTube

分類Dev

CSS - 100% width of Youtube embed video

分類Dev

Enabling and disabling comments on youtube video through api

分類Dev

How to stop a youtube video from playing

分類Dev

How to show downloading progress of youtube video on frontend

分類Dev

Display and autoplay youtube video in popup on document load

分類Dev

youtube video in android without hardware acceleration

分類Dev

how to build video playlist having youtube videos?

分類Dev

Youtube jquery get video page html

分類Dev

How to embed youtube video in firefox os webapp?

Related 関連記事

ホットタグ

アーカイブ