i am trying to make youtube downloader and make Progressbar i want display progressbar while the video downloading and finish at the same time with video

19 views
Skip to first unread message

Thomas

unread,
Jul 8, 2021, 7:15:35 PM7/8/21
to wxPython-users
I am new user in python and WX
I made an application so I can download videos from YouTube
I made a progress bar, but the problem is that the progress bar ends before the video finishes from the download
I want to end  the download bar with video download end


class Tube(wx.Frame):
   
def __init__(self, *args, **kwargs):
       
super(Tube, self, *args, **kwargs).__init__(parent=None,id=wx.ID_ANY, title="New Frame", size=(600, 400))
       
self.Centre()
       
self.panel = wx.Panel(self, id=wx.ID_ANY, name="New Panel")
       
self.textLink = wx.StaticText(parent=self.panel, id=wx.ID_ANY, label="Edit YouTube URL", pos=(100, 50))
       
self.editLink = wx.TextCtrl(parent=self.panel, id=wx.ID_ANY, size=(200, 25), pos=(250,50))
       
self.downloadButton = wx.Button(parent=self.panel, id=wx.ID_ANY, label="Download Video", pos=(250, 100))
       
self.downloadButton.Bind(event=wx.EVT_BUTTON, handler=self.thread, source=self.downloadButton)
       
self.progress = wx.Gauge(parent=self.panel, id=wx.ID_ANY, range=100,size=(200,25), pos=(200, 200))
       
self.Show()

   
def progressBar(self, *args, **kwargs):
       
for value in range(101):
            wx.CallAfter(
self.progress.SetValue, value)
            sleep(
0.2)

   
def Download(self, *args, **kwargs):
       
self.video = YouTube(self.editLink.GetValue())
       
self.stream = self.video.streams.get_lowest_resolution()
       
self.stream.download()

   
def thread(self, *args, **kwargs):
       
self.threads = []
        
self.thread1 = Thread(target=self.Download)
       
self.thread2 = Thread(target=self.progressBar)
       
self.threads.append(self.thread1)
       
self.threads.append(self.thread2)
       
for thread in self.threads:
            thread.setDaemon(
True)
            thread.start()





if __name__ == '__main__':
    app = wx.App()
    screen = Tube()
    app.MainLoop()

 

Rolf

unread,
Jul 9, 2021, 1:50:55 AM7/9/21
to Thomas, wxPython-users
Thomas, you would need to establish the size of the file prior to the
download and how much you have received, periodically during the
download. Then you could calculate the value to set in the gauge, as a
percentage. As it is, you are simply counting to 101.

It is perhaps simpler, to begin with, if you use the "indeterminate"
option on the gauge by replacing calls to self.progress.SetValue() with
self.progress.Pulse().

In that way the progress bar updates until it is stopped but not in a
specific linear way.



On 03/07/2021 02:58, Thomas wrote:
> I am new user in python and WX
> I made an application so I can download videos from YouTube
> I made a progress bar, but the problem is that the progress bar ends
> before the video finishes from the download
> I want to end  the download bar with video download end
>
>
> class Tube(wx.Frame):
>     def __init__(self*, **args*, ***kwargs):
>         super(Tube*, *self*, **args*,
> ***kwargs).__init__(parent=None*,*id=wx.ID_ANY*, *title="New Frame"*,
> *size=(*600**, **400*))
>         self.Centre()
>         self.panel = wx.Panel(self*, *id=wx.ID_ANY*, *name="New Panel")
>         self.textLink = wx.StaticText(parent=self.panel*,
> *id=wx.ID_ANY*, *label="Edit YouTube URL"*, *pos=(*100**, **50*))
>         self.editLink = wx.TextCtrl(parent=self.panel*,
> *id=wx.ID_ANY*, *size=(*200**, **25*)*, *pos=(*250**,**50*))
>         self.downloadButton = wx.Button(parent=self.panel*,
> *id=wx.ID_ANY*, *label="Download Video"*, *pos=(*250**, **100*))
>         self.downloadButton.Bind(event=wx.EVT_BUTTON*,
> *handler=self.thread*, *source=self.downloadButton)
>         self.progress = wx.Gauge(parent=self.panel*, *id=wx.ID_ANY*,
> *range=*100**,*size=(*200**,**25*)*, *pos=(*200**, **200*))
>         self.Show()
>
>     def progressBar(self*, **args*, ***kwargs):
>         for value in range(*101*):
>             wx.CallAfter(self.progress.SetValue*, *value)
>             sleep(*0.2*)
>
>     def Download(self*, **args*, ***kwargs):
>         self.video = YouTube(self.editLink.GetValue())
>         self.stream = self.video.streams.get_lowest_resolution()
>         self.stream.download()
>
>     def thread(self*, **args*, ***kwargs):
>         self.threads = []
>         self.thread1 = Thread(target=self.Download)
>         self.thread2 = Thread(target=self.progressBar)
>         self.threads.append(self.thread1)
>         self.threads.append(self.thread2)
>         for thread in self.threads:
>             thread.setDaemon(True)
>             thread.start()
>
>
>
>
>
> if __name__ == '__main__':
>     app = wx.App()
>     screen = Tube()
>     app.MainLoop()
>
>  
>
> --
> You received this message because you are subscribed to the Google
> Groups "wxPython-users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to wxpython-user...@googlegroups.com
> <mailto:wxpython-user...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/wxpython-users/78512806-0bb5-4868-bff6-b9dfb582530bn%40googlegroups.com
> <https://groups.google.com/d/msgid/wxpython-users/78512806-0bb5-4868-bff6-b9dfb582530bn%40googlegroups.com?utm_medium=email&utm_source=footer>.
Reply all
Reply to author
Forward
0 new messages