class MainWindow: def __init__(self): # Silencing the pytube logger logging.getLogger("pytube.__main__").setLevel(logging.WARNING) self.window = tk.Tk() self.x = 600 self.y = 300 self.window.geometry(f"{self.x}x{self.y}") self.window.title("KIH Tata Downloader v.1.0.0") self.window.configure(bg="white") # Namespace placeholders self.video = None self.stream = None self.directory = None # Styles style = Style() style.theme_use('clam') style.configure("white.Horizontal.TProgressbar", foreground='white', background='white') # Logo logo_path = Path(__file__).resolve( ).parent.parent / 'graphics' / 'logo-final-120.png' img = ImageTk.PhotoImage(Image.open(logo_path)) self.panel = tk.Label(self.window, image=img) self.panel.place(x=self.x * 0.5, y=self.y * 0.025, anchor="n") # Link entry section self.entry_y = self.y * 0.55 self.link_entry_label = tk.Label(text="Link do YouYube: ", bg="white") self.link_entry_label.place(x=self.x * 0.04, y=self.entry_y, anchor="w") self.link_entry = tk.Entry(self.window, fg="darkred", bg="white", width=int(self.x * 0.105)) self.link_entry.place(x=self.x * 0.215, y=self.entry_y, anchor="w") self.button_download = tk.Button(command=self.download_video, text="Ściągnij", bg="white", fg="black") self.button_download.place(x=self.x * 0.95, y=self.entry_y, anchor="e") # Progress Bar and Progress Label, it will appear while downloading self.progress_bar = Progressbar(self.window, orient="horizontal", maximum=100, length=382, mode='determinate', style="white.Horizontal.TProgressbar") self.progress_percent = tk.Label(self.window, text="0%", fg="darkred", bg="white", font=("Agency FB", 15)) self.contact = tk.Label( text= "Tatalski, jak coś nie działa to dawaj znać.\n Będziemy naprawiać i rozwijać :)", bg="white", fg="black") self.contact.place(x=self.x * 0.5, y=self.y * 0.85, anchor="center") self.window.mainloop() def download_video(self): self.directory = self.change_download_destination() logging.info(f"Download directory: {self.directory}") yt_link = self.link_entry.get() logging.info(f"Link: {yt_link}") self.video = YouTube(yt_link) logging.info("Connection to the youtube movie established\n") logging.info(f"Title: {self.video.title}") self.stream = self.video.streams.filter( progressive=True, file_extension='mp4').order_by('resolution').desc().first() logging.info(f"Filesize: {round(self.stream.filesize / 1024**2, 1)}MB") self.create_progressbar() threading.Thread(target=self.video.register_on_progress_callback( self.update_progressbar)).start() threading.Thread(target=self.download_start).start() def download_start(self): self.stream.download(self.directory) def change_download_destination(self): root = tk.Tk() root.withdraw() directory = filedialog.askdirectory() return directory def create_progressbar(self): self.progress_bar.place(x=self.x * 0.215, y=self.y * 0.65, anchor="w") self.progress_percent.place(x=self.x * 0.9, y=self.y * 0.65, anchor="center") def remove_progressbar(self): self.progress_bar.place_forget() self.progress_bar['value'] = 0 self.progress_percent.place_forget() self.progress_percent.config(text='0%') def create_info_popup(self, title, text): root = tk.Tk() root.withdraw() TextInfo(root, title, text=text) def update_progressbar(self, stream=None, chunk=None, remaining=None): # Gets the percentage of the file that has been downloaded. percent = int(100 - (100 * (remaining / self.stream.filesize))) if percent < 100: self.progress_percent.config(text=str(percent) + "%") self.progress_bar['value'] = percent else: self.remove_progressbar() messagebox.showinfo( title=None, message=f"Film '{self.video.title}' ściągnięty") logging.info("Movie downloaded")
class Main_window(): def __init__(self, root_window): global window self.file = '' self.window = root_window self.header = Label(self.window, text = "Криптография",font = 'Arial 20') self.header.place(relx = 0.33,rely = 0.05) self.selectfile_label = Label(self.window, text = "Выберите файл",font = 'Arial 14') self.selectfile_label.place(relx = 0.15,rely = 0.25) self.selectfile_button = Button(self.window, text = "Файл",font = 'Arial 14',command=self.file_choise) self.selectfile_button.place(relx = 0.5 ,rely = 0.24) self.file_entried = Label(self.window,font = 'Arial 24') self.file_entried.place(relx = 0.65 ,rely = 0.23) self.key_label = Label(self.window, text = "Введите ключ",font = 'Arial 14') self.key_label.place(relx = 0.15,rely = 0.4) self.showkeybutton = Button(self.window, text = "Показать",font = 'Arial 10',command=self.show_hide) self.showkeybutton.place(relx = 0.75 ,rely = 0.4) self.key_entry = Entry(self.window,font = 'Arial 14',width = 10 ,show="•") # self.key_entry.place(relx = 0.5 ,rely = 0.4) self.hash_method_label = Label(self.window, text = "Метод шифрования",font = 'Arial 14') self.hash_method_label.place(relx = 0.15 ,rely = 0.55) self.selectorVal = StringVar() self.hash_method_list = Combobox(self.window, state='readonly', textvariable = self.selectorVal) self.hash_method_list['values'] = ("Без хэширования", "md5", "sha1", "sha256", "sha224", "sha512", "sha3_224", "sha3_256", "sha3_384" ,"sha3_512") self.hash_method_list.current(0) self.hash_method_list.place(relx = 0.58 ,rely = 0.56) self.but = Button(self.window, text = "Крипто!",font = 'Arial 14',command=self.doit) self.but.place(relx = 0.43 ,rely = 0.67) self.pbar = Progressbar(self.window, length = 300) self.pbar["maximum"]=300 def show_hide(self): if self.showkeybutton['text'] == "Показать": self.showkeybutton['text'] = "Скрыть" self.key_entry['show'] = "" else: self.showkeybutton['text'] = "Показать" self.key_entry['show'] = "•" def doit(self): self.password = self.key_entry.get() if self.password == '': messagebox.showerror("Ошибка!","Введите ключ!") elif self.file == '': messagebox.showerror("Ошибка!","Выберите файл!") else: self.key = self.key_do(self.password) out = self.crypto(self.file, self.key) if isinstance(out, str): messagebox.showinfo("Готово!","Шифрование к файлу {} успешно применено!".format(out)) self.pbar['value'] = 0 self.pbar.place_forget() def crypto(self, file, key): dirictory = os.path.dirname(file) file_name = os.path.basename(file) size = os.path.getsize(file) key = str.encode(key) try: file_body = open(file,'rb') output_body = open(dirictory+"//"+os.path.splitext(file_name)[0]+".slvn",'wb') except: messagebox.showerror("Ошибка!","Невозможно открыть файл!") return False i = 0 if size>300: perc = round(size/300)#получаем кол-во итераций для одного символа self.pbar.place(relx = 0.22 ,rely = 0.85) else: perc = 0 loading_status = 0 counter = 0 for line in file_body: for symbol in line: out_c = symbol^key[i] #out_c = symbol i+=1 if i>=len(key): i = 0 counter+=1 if (perc != 0) and counter>perc: #print(loading_status) counter = 0 loading_status+=1 #ТУТ СДЕЛАЙ ИТЕРАЦИЮ В СТАТУС БАР self.pbar['value'] = loading_status self.pbar.update() #print(self.pbar['value']) #output_body.write(bytearray(out_c)) output_body.write(out_c.to_bytes(1, byteorder='big')) self.pbar['value'] = 300 file_body.close() try: os.remove(file) except: os.remove(dirictory+"//"+os.path.splitext(file_name)[0]+".slvn") output_body.close() messagebox.showerror("Ошибка!","Не используйте файлы во время кодирования!") return False output_body.close() os.rename(dirictory+"//"+os.path.splitext(file_name)[0]+".slvn", file) return file_name def key_do(self, keyin): q = self.hash_method_list.get() if q == "Без хэширования": return keyin elif q == "md5": return hashlib.md5(keyin.encode()).hexdigest() elif q == "sha1": return hashlib.sha1(keyin.encode()).hexdigest() elif q == "sha256": return hashlib.sha256(keyin.encode()).hexdigest() elif q == "sha224": return hashlib.sha224(keyin.encode()).hexdigest() elif q == "sha512": return hashlib.sha512(keyin.encode()).hexdigest() elif q == "sha3_224": return hashlib.sha3_224(keyin.encode()).hexdigest() elif q == "sha3_256": return hashlib.sha3_256(keyin.encode()).hexdigest() elif q == "sha3_384": return hashlib.sha3_384(keyin.encode()).hexdigest() elif q == "sha3_512": return hashlib.sha3_512(keyin.encode()).hexdigest() def file_choise(self): self.file = '' self.file = askopenfilename(filetypes = (("All types", ".*"),)) if self.file != '': self.file_entried['text'] = "✔"