import tkinter as tk
import tkinter.filedialog as tk_fd
import subprocess

ffmpeg_path = "C:\\Users\\username\\Downloads\\ffmpeg-20160428-git-78baa45-win64-static\\bin\\ffmpeg.exe"

class Application(tk.Frame):
    """Application class docstring"""

    def __init__(self, master=None):
        """init method docstring"""
        super().__init__(master)
        self.pack()
        
        self.mp3_path = ''
        self.pic_path = ''
        self.output_path = ''
        
        self.create_widgets()
                
    def create_widgets(self):
        self.Source1 = tk.Button(self, text = "mp3", command = lambda: self.open_mp3()).pack()
        self.Sourse2 = tk.Button(self, text = "pic", command = lambda: self.open_pic()).pack()
        self.Start = tk.Button(self, text="Start", fg="red",command= lambda: self.start()).pack()

    def open_mp3(self):
        """mp3 method docstring"""
        op = tk_fd.askopenfile(mode='rb',title='Choose a mp3', filetypes = [("music", "*.mp3")])
        path = r''.replace('',(str(op.name).replace("""/""","""\\"""))) 
        print("Path to mp3 is - " + path)
        self.mp3_path = path
    
    def open_pic(self):
        op = tk_fd.askopenfile(mode='rb',title='Choose a picture', filetypes = [("picture", "*.jpeg; *.bmp; *.jpg; *.png")])
        path = r''.replace('',(str(op.name).replace("""/""","""\\"""))) 
        print("Path to pic is - " + path)
        self.pic_path = path
        
    def start(self):
        op = tk_fd.asksaveasfilename(title = "Choose where to save", filetypes = [("webm", "*.webm;")])
        path = r''.replace('',(str(op).replace("""/""","""\\""")+(".webm"))) 
        print("Path to webm is - " + path)
        self.output_path = path
        
        subprocess.call(ffmpeg_path + self.parse_setting())
        
    def parse_setting(self):
        #there must be smth to parse when settings will be done
        settings = u" -r 1 -loop 1 -i {} -i {} -c:v vp8 -c:a opus -b:a 128k -b:v 0 -crf 16 -g 360 -shortest {} ".format((self.pic_path), (self.mp3_path), (self.output_path))
        print((ffmpeg_path + settings))
        return(settings)


root = tk.Tk()
root.geometry("800x600")
root.title("mp3 + pic = webm GUI")
app = Application(master=root)
app.mainloop()