Conditions | 13 |
Total Lines | 75 |
Code Lines | 65 |
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----------------------------------------- |
||
94 | def get_fetch(): |
||
95 | resolution = Rvideo.get() |
||
96 | Select = A_Video.get() |
||
97 | Selection = A_Audio.get() |
||
98 | # pb.start() |
||
99 | try: |
||
100 | if var1 is None: |
||
101 | print("error") |
||
102 | dirname = filedialog.askdirectory(parent=tab1, initialdir="/", |
||
103 | title='Please select a directory') |
||
104 | if dirname: |
||
105 | try: |
||
106 | # Video with Resolution |
||
107 | if resolution <= 3: |
||
108 | yt = pytube.YouTube(var1.get()) |
||
109 | if resolution == 1: |
||
110 | progress_bar = ttk.Progressbar(tab1, orient = 'horizontal', length = 500, mode = 'determinate') |
||
111 | progress_bar.place(x=60,y=140) |
||
112 | progress_bar.start() |
||
113 | messagebox.showinfo("Download", |
||
114 | "Downloading.. Please Wait for a Minute.") |
||
115 | video = yt.streams.get_by_itag(22) |
||
116 | video.download(dirname) |
||
117 | elif resolution == 2: |
||
118 | progress_bar = ttk.Progressbar(tab1, orient = 'horizontal', length = 500, mode = 'determinate') |
||
119 | progress_bar.place(x=60,y=140) |
||
120 | progress_bar.start() |
||
121 | messagebox.showinfo("Download","Downloading...") |
||
122 | video = yt.streams.first() |
||
123 | video.download(dirname) |
||
124 | elif resolution == 3: |
||
125 | progress_bar = ttk.Progressbar(tab1, orient = 'horizontal', length = 500, mode = 'determinate') |
||
126 | progress_bar.place(x=60,y=140) |
||
127 | progress_bar.start() |
||
128 | messagebox.showinfo("Download","Downloading...") |
||
129 | video = yt.streams.get_by_itag(36) |
||
130 | video.download(dirname) |
||
131 | # Download Playlist |
||
132 | if Select == 1: |
||
133 | playlist = pytube.Playlist(var1.get()) |
||
134 | progress_bar = ttk.Progressbar(tab1, orient = 'horizontal', length = 500, mode = 'determinate') |
||
135 | progress_bar.place(x=60,y=140) |
||
136 | progress_bar.start() |
||
137 | playlist.populate_video_urls() # To load bulk list |
||
138 | messagebox.showinfo("Download", "Downloading...") |
||
139 | playlist.download_all(dirname) |
||
140 | |||
141 | # Audio files |
||
142 | if Selection <= 2: |
||
143 | link = YouTube(var1.get()) |
||
144 | format_a = link.streams.filter(only_audio=True).all() |
||
145 | if Selection == 1: |
||
146 | # mp4 |
||
147 | progress_bar = ttk.Progressbar(tab1, orient = 'horizontal', length = 500, mode = 'determinate') |
||
148 | progress_bar.place(x=60,y=140) |
||
149 | progress_bar.start() |
||
150 | messagebox.showinfo("Download", "Downloading...") |
||
151 | format_a[0].download(dirname) |
||
152 | elif Selection == 2: # webm |
||
153 | progress_bar = ttk.Progressbar(tab1, orient = 'horizontal', length = 500, mode = 'determinate') |
||
154 | progress_bar.place(x=60,y=140) |
||
155 | progress_bar.start() |
||
156 | messagebox.showinfo("Download", "Downloading...") |
||
157 | format_a[1].download(dirname) |
||
158 | |||
159 | messagebox.showinfo("Downloading.. ", "Thank You.") |
||
160 | except Exception as a: |
||
161 | messagebox.showwarning(" FYI.. ", "Failed") |
||
162 | else: |
||
163 | messagebox.showwarning(" FYI. ", "Cancelled") |
||
164 | except Exception as a: |
||
165 | |||
166 | messagebox.showwarning(" FYI. ", "Cancelled") |
||
167 | #print(a) |
||
168 | sys.exit() |
||
169 | |||
270 |