Conditions | 13 |
Total Lines | 60 |
Code Lines | 47 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Complex classes like Main.get_fetch() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
1 | #------------------Import Files------------------------------------------------- |
||
53 | def get_fetch(): |
||
54 | resolution = Rvideo.get() |
||
55 | Select = A_Video.get() |
||
56 | Selection = A_Audio.get() |
||
57 | #pb.start() |
||
58 | try: |
||
59 | if var1 is None: |
||
60 | print("error") |
||
61 | dirname = filedialog.askdirectory(parent=tab1, initialdir="/", title='Please select a directory') |
||
62 | if (dirname): |
||
63 | try: |
||
64 | # Video with Resolution |
||
65 | if (resolution <= 3): |
||
66 | yt = pytube.YouTube(var1.get()) |
||
67 | if(resolution == 1): |
||
68 | progress_bar = ttk.Progressbar(tab1, orient = 'horizontal', length = 286, mode = 'determinate') |
||
69 | progress_bar.place(x=60,y=140) |
||
70 | progress_bar.start() |
||
71 | messagebox.showinfo("Download","Please Wait for a Minute and Give Ok") |
||
72 | video = yt.streams.get_by_itag(136) |
||
73 | video.download(dirname) |
||
74 | |||
75 | #messagebox.showinfo(" Downloading.. ", "Thank You.") |
||
76 | elif(resolution == 2): |
||
77 | #messagebox.showinfo("Download","Downloading...") |
||
78 | video = yt.streams.first() |
||
79 | video.download(dirname) |
||
80 | #messagebox.showinfo(" Downloading.. ", "Thank You.") |
||
81 | elif(resolution ==3): |
||
82 | #messagebox.showinfo("Download","Downloading...") |
||
83 | video = yt.streams.get_by_itag(160) |
||
84 | video.download(dirname) |
||
85 | #messagebox.showinfo(" Downloading.. ", "Thank You.") |
||
86 | |||
87 | #----Download Playlist----# |
||
88 | if (Select == 1): |
||
89 | playlist = pytube.Playlist(var1.get()) |
||
90 | playlist.populate_video_urls() # To load bulk list |
||
91 | messagebox.showinfo("Download","Downloading...") |
||
92 | playlist.download_all(dirname) |
||
93 | |||
94 | #------Audio------# |
||
95 | if(Selection <= 2): |
||
96 | link=YouTube(var1.get()) |
||
97 | format_a=link.streams.filter(only_audio=True).all() |
||
98 | if(Selection==1): #mp4 |
||
99 | messagebox.showinfo("Download","Downloading...") |
||
100 | format_a[0].download(dirname) |
||
101 | elif(Selection==2): #webm |
||
102 | messagebox.showinfo("Download","Downloading...") |
||
103 | format_a[1].download(dirname) |
||
104 | progress_bar.stop() |
||
|
|||
105 | messagebox.showinfo(" Downloading.. ", "Thank You.") |
||
106 | except: |
||
107 | messagebox.showwarning(" FYI.. ", "Failed") |
||
108 | else: |
||
109 | messagebox.showwarning(" FYI. ", "Cancelled") |
||
110 | except: |
||
111 | messagebox.showwarning(" FYI. ", "Cancelled") |
||
112 | sys.exit() |
||
113 | |||
157 |