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----------------------------------------- |
||
60 | def get_fetch(): |
||
61 | resolution = Rvideo.get() |
||
62 | Select = A_Video.get() |
||
63 | Selection = A_Audio.get() |
||
64 | # pb.start() |
||
65 | try: |
||
66 | if var1 is None: |
||
67 | print("error") |
||
68 | dirname = filedialog.askdirectory(parent=tab1, initialdir="/", |
||
69 | title='Please select a directory') |
||
70 | if dirname: |
||
71 | try: |
||
72 | # Video with Resolution |
||
73 | if resolution <= 3: |
||
74 | yt = pytube.YouTube(var1.get()) |
||
75 | if resolution == 1: |
||
76 | progress_bar = ttk.Progressbar(tab1, orient = 'horizontal', length = 500, mode = 'determinate') |
||
77 | progress_bar.place(x=60,y=140) |
||
78 | progress_bar.start() |
||
79 | messagebox.showinfo("Download", |
||
80 | "Downloading.. Please Wait for a Minute.") |
||
81 | video = yt.streams.get_by_itag(22) |
||
82 | video.download(dirname) |
||
83 | elif resolution == 2: |
||
84 | progress_bar = ttk.Progressbar(tab1, orient = 'horizontal', length = 500, mode = 'determinate') |
||
85 | progress_bar.place(x=60,y=140) |
||
86 | progress_bar.start() |
||
87 | messagebox.showinfo("Download","Downloading...") |
||
88 | video = yt.streams.first() |
||
89 | video.download(dirname) |
||
90 | elif resolution == 3: |
||
91 | progress_bar = ttk.Progressbar(tab1, orient = 'horizontal', length = 500, mode = 'determinate') |
||
92 | progress_bar.place(x=60,y=140) |
||
93 | progress_bar.start() |
||
94 | messagebox.showinfo("Download","Downloading...") |
||
95 | video = yt.streams.get_by_itag(36) |
||
96 | video.download(dirname) |
||
97 | # Download Playlist |
||
98 | if Select == 1: |
||
99 | playlist = pytube.Playlist(var1.get()) |
||
100 | progress_bar = ttk.Progressbar(tab1, orient = 'horizontal', length = 500, mode = 'determinate') |
||
101 | progress_bar.place(x=60,y=140) |
||
102 | progress_bar.start() |
||
103 | playlist.populate_video_urls() # To load bulk list |
||
104 | messagebox.showinfo("Download", "Downloading...") |
||
105 | playlist.download_all(dirname) |
||
106 | |||
107 | # Audio files |
||
108 | if Selection <= 2: |
||
109 | link = YouTube(var1.get()) |
||
110 | format_a = link.streams.filter(only_audio=True).all() |
||
111 | if Selection == 1: |
||
112 | # mp4 |
||
113 | progress_bar = ttk.Progressbar(tab1, orient = 'horizontal', length = 500, mode = 'determinate') |
||
114 | progress_bar.place(x=60,y=140) |
||
115 | progress_bar.start() |
||
116 | messagebox.showinfo("Download", "Downloading...") |
||
117 | format_a[0].download(dirname) |
||
118 | elif Selection == 2: # webm |
||
119 | progress_bar = ttk.Progressbar(tab1, orient = 'horizontal', length = 500, mode = 'determinate') |
||
120 | progress_bar.place(x=60,y=140) |
||
121 | progress_bar.start() |
||
122 | messagebox.showinfo("Download", "Downloading...") |
||
123 | format_a[1].download(dirname) |
||
124 | |||
125 | messagebox.showinfo("Downloading.. ", "Thank You.") |
||
126 | except Exception as a: |
||
127 | #print(a) |
||
128 | messagebox.showwarning(" FYI.. ", "Failed") |
||
129 | else: |
||
130 | messagebox.showwarning(" FYI. ", "Cancelled") |
||
131 | except Exception as a: |
||
132 | messagebox.showwarning(" FYI. ", "Cancelled") |
||
133 | #print(a) |
||
134 | sys.exit() |
||
135 | |||
205 |