1010
1111# =- delete all .mp4 and .jpg
1212system ('rm *.mp4' )
13- system ('rm video_image/*.jpg' )
13+ # system('rm video_image/*.jpg')
1414
1515
1616class Fr_videos (ttk .Frame ):
1717 def __init__ (self , parent , link ) -> None :
1818 super ().__init__ (parent )
19- self .yt = YouTube (link , on_progress_callback = self .progress )
20-
19+ self .yt = YouTube (link )
20+ self .link = link
21+
2122 self .yt_title = self .yt .title
22- util .download_image (thumbnail_url = self .yt .thumbnail_url , name = self .yt_title )
23+ # util.download_image(thumbnail_url=self.yt.thumbnail_url, name=self.yt_title)
2324
2425 self .image = Image .open (f'./video_image/{ self .yt_title } .jpg' )
2526 self .image = self .image .resize ((180 , 100 ), Image .LANCZOS )
@@ -28,20 +29,23 @@ def __init__(self, parent, link) -> None:
2829
2930 self .lb_image = ttk .Label (self , image = self .imageTk )
3031
31- self .title1 = ttk .Label (self , text = 'title:' )
3232 self .title2 = ttk .Label (self , text = self .yt_title )
3333 self .progressBar = ttk .Progressbar (self , length = 300 , maximum = 100 , mode = DETERMINATE , value = 0 )
3434
35+ # size_video = self.yt.streams.get_by_itag(17).filesize
36+ size_highResolution = self .yt .streams .get_highest_resolution ().filesize
37+ size_highResolution = util .format_bytes (size_highResolution )
38+ self .lb_size = ttk .Label (self , text = f'size:{ size_highResolution } ' )
3539
3640
3741
3842 self .lb_image .grid (row = 0 , column = 0 , rowspan = 2 )
39- self .title1 .grid (row = 0 , column = 1 )
4043 self .title2 .grid (row = 0 , column = 2 )
44+ self .lb_size .grid (row = 0 , column = 3 )
45+
4146 self .progressBar .grid (row = 1 , column = 1 , columnspan = 2 )
4247
4348
44- # def progress(self, n1, n2, n3):
4549 def progress (self , stream , chunk , bytes_remaining ):
4650 total_size = stream .filesize
4751 bytes_downloaded = total_size - bytes_remaining
@@ -56,9 +60,18 @@ def progress(self, stream, chunk, bytes_remaining):
5660
5761
5862 def startDownload (self ):
59- print ('start download' )
60- video = self .yt .streams .get_highest_resolution ()
63+ yt = YouTube (self .link , on_progress_callback = self .progress )
64+
65+ video = yt .streams .get_highest_resolution ()
6166 video .download ()
67+
68+ def start (self ):
69+ th = Thread (target = self .startDownload )
70+ th .start ()
71+
72+
73+
74+
6275
6376
6477
@@ -69,24 +82,21 @@ def startDownload(self):
6982
7083 def start ():
7184
72- th1 = Thread (target = fr1 .startDownload ())
73- th2 = Thread (target = fr2 .startDownload ())
74- th3 = Thread (target = fr3 .startDownload ())
75- th1 .start ()
76- th2 .start ()
77- th3 .start ()
78-
85+ fr1 .start ()
86+ # fr2.start()
87+ # fr3.startDownload()
88+
7989 window = ttk .Window ()
8090 link1 = 'https://www.youtube.com/watch?v=_p2NvO6KrBs'
8191 link2 = 'https://www.youtube.com/watch?v=ZQ80_j3CXJQ'
82- link3 = 'https://www.youtube.com/watch?v=ytIZGsm1NXo'
92+ # link3 = 'https://www.youtube.com/watch?v=ytIZGsm1NXo'
8393
8494 fr1 = Fr_videos (window , link1 )
85- fr2 = Fr_videos (window , link2 )
86- fr3 = Fr_videos (window , link3 )
95+ # fr2 = Fr_videos(window, link2)
96+ # fr3 = Fr_videos(window, link3)
8797 fr1 .pack (ipadx = 200 )
88- fr2 .pack (ipadx = 200 )
89- fr3 .pack (ipadx = 200 )
98+ # fr2.pack(ipadx=200)
99+ # fr3.pack(ipadx=200)
90100
91101 bt_download = ttk .Button (window , text = 'Download' , bootstyle = SUCCESS , command = start )
92102 bt_download .pack ()
0 commit comments