Conditions | 13 |
Total Lines | 60 |
Code Lines | 48 |
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----------------------------------------- |
||
71 | def get_fetch(): |
||
72 | resolution = Rvideo.get() |
||
73 | Select = A_Video.get() |
||
74 | Selection = A_Audio.get() |
||
75 | # pb.start() |
||
76 | try: |
||
77 | if var1 is None: |
||
78 | print("error") |
||
79 | dirname = filedialog.askdirectory(parent=tab1, initialdir="/", |
||
80 | title='Please select a directory') |
||
81 | if dirname: |
||
82 | try: |
||
83 | # Video with Resolution |
||
84 | if resolution <= 3: |
||
85 | yt = pytube.YouTube(var1.get()) |
||
86 | if resolution == 1: |
||
87 | pb_bar() |
||
88 | messagebox.showinfo("Download", |
||
89 | "Downloading.. Please Wait for a Minute.") |
||
90 | video = yt.streams.get_by_itag(136) |
||
91 | video.download(dirname) |
||
92 | # messagebox.showinfo(" Downloading.. ", "Thank You.") |
||
93 | elif resolution == 2: |
||
94 | # messagebox.showinfo("Download","Downloading...") |
||
95 | video = yt.streams.first() |
||
96 | video.download(dirname) |
||
97 | # messagebox.showinfo(" Downloading.. ", "Thank You.") |
||
98 | elif resolution == 3: |
||
99 | # messagebox.showinfo("Download","Downloading...") |
||
100 | video = yt.streams.get_by_itag(160) |
||
101 | video.download(dirname) |
||
102 | # messagebox.showinfo(" Downloading.. ", "Thank You.") |
||
103 | |||
104 | # Download Playlist |
||
105 | if Select == 1: |
||
106 | playlist = pytube.Playlist(var1.get()) |
||
107 | playlist.populate_video_urls() # To load bulk list |
||
108 | messagebox.showinfo("Download", "Downloading...") |
||
109 | playlist.download_all(dirname) |
||
110 | |||
111 | # Audio files |
||
112 | if Selection <= 2: |
||
113 | link = YouTube(var1.get()) |
||
114 | format_a = link.streams.filter(only_audio=True).all() |
||
115 | if Selection == 1: # mp4 |
||
116 | messagebox.showinfo("Download", "Downloading...") |
||
117 | format_a[0].download(dirname) |
||
118 | elif Selection == 2: # webm |
||
119 | messagebox.showinfo("Download", "Downloading...") |
||
120 | format_a[1].download(dirname) |
||
121 | pb_bar.stop() |
||
122 | messagebox.showinfo("Downloading.. ", "Thank You.") |
||
123 | except: |
||
124 | pb_bar.stop() |
||
125 | messagebox.showwarning(" FYI.. ", "Failed") |
||
126 | else: |
||
127 | messagebox.showwarning(" FYI. ", "Cancelled") |
||
128 | except: |
||
129 | messagebox.showwarning(" FYI. ", "Cancelled") |
||
130 | sys.exit() |
||
131 | |||
204 |