Update interface
This commit is contained in:
		
							parent
							
								
									46fbf89ca1
								
							
						
					
					
						commit
						c7c41e7468
					
				
							
								
								
									
										11
									
								
								core.py
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								core.py
									
									
									
									
									
								
							@ -6,6 +6,7 @@ import sys
 | 
				
			|||||||
import argparse
 | 
					import argparse
 | 
				
			||||||
import ydl
 | 
					import ydl
 | 
				
			||||||
import interface
 | 
					import interface
 | 
				
			||||||
 | 
					import tkinter as tk
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#TODO:
 | 
					#TODO:
 | 
				
			||||||
# offer download video option
 | 
					# offer download video option
 | 
				
			||||||
@ -20,16 +21,22 @@ parser.add_argument("-q","--quiet", help="Very quiet option for youtube-dl",acti
 | 
				
			|||||||
parser.add_argument("-f","--feed", help="Create Podcast feed",action="store_true")
 | 
					parser.add_argument("-f","--feed", help="Create Podcast feed",action="store_true")
 | 
				
			||||||
parser.add_argument("-video", help="Download videos instead of creating audio",action="store_true")
 | 
					parser.add_argument("-video", help="Download videos instead of creating audio",action="store_true")
 | 
				
			||||||
parser.add_argument("-d","--dir", help="Define download directory for files, default value:'~/Vidéos'", default="~/Vidéos")
 | 
					parser.add_argument("-d","--dir", help="Define download directory for files, default value:'~/Vidéos'", default="~/Vidéos")
 | 
				
			||||||
parser.add_argument("-url", help="Define base url for podcasts, default value:'http://podcasts.lutix.org'", default="http://podcasts.lutix.org")
 | 
					parser.add_argument("-url","--podcast_url", help="Define base url for podcasts, default value:'http://podcasts.lutix.org'", default="http://podcasts.lutix.org")
 | 
				
			||||||
parser.add_argument("-yturl","--youtube_url", help="Define youtube url to fetch", default ="https://www.youtube.com/watch?v=xJO5GstqTSY&list=PLxzM9a5lhAumFRpcigmGY1QLDYxb4-P2B")
 | 
					parser.add_argument("-yturl","--youtube_url", help="Define youtube url to fetch", default ="https://www.youtube.com/watch?v=xJO5GstqTSY&list=PLxzM9a5lhAumFRpcigmGY1QLDYxb4-P2B")
 | 
				
			||||||
args = parser.parse_args()
 | 
					args = parser.parse_args()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if __name__ == "__main__":
 | 
					if __name__ == "__main__":
 | 
				
			||||||
    if args.interface:
 | 
					    print(args.interface)
 | 
				
			||||||
 | 
					    if not args.interface:
 | 
				
			||||||
        ydlo = ydl.ydl_object(args)
 | 
					        ydlo = ydl.ydl_object(args)
 | 
				
			||||||
        ydlo.print_infos()
 | 
					        ydlo.print_infos()
 | 
				
			||||||
        ydlo.process_args()
 | 
					        ydlo.process_args()
 | 
				
			||||||
    else:
 | 
					    else:
 | 
				
			||||||
        print('Waiting for interface to be loaded...')
 | 
					        print('Waiting for interface to be loaded...')
 | 
				
			||||||
 | 
					        root = tk.Tk() #create window
 | 
				
			||||||
 | 
					        root.title("Ydl - Youtube downloader")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        app = interface.Interface(master=root) #create all components inside the window
 | 
				
			||||||
 | 
					        app.mainloop()
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										48
									
								
								interface.py
									
									
									
									
									
								
							
							
						
						
									
										48
									
								
								interface.py
									
									
									
									
									
								
							@ -1,4 +1,5 @@
 | 
				
			|||||||
import tkinter as tk
 | 
					import tkinter as tk
 | 
				
			||||||
 | 
					from tkinter import filedialog
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Interface(tk.Frame):
 | 
					class Interface(tk.Frame):
 | 
				
			||||||
@ -12,6 +13,11 @@ class Interface(tk.Frame):
 | 
				
			|||||||
        for key in self.args:
 | 
					        for key in self.args:
 | 
				
			||||||
            if bool(self.args[key].get()):
 | 
					            if bool(self.args[key].get()):
 | 
				
			||||||
                print('{}: Option non vide'.format(key))
 | 
					                print('{}: Option non vide'.format(key))
 | 
				
			||||||
 | 
					                if self.args[key].get() in [0,1]:
 | 
				
			||||||
 | 
					                    value = ''
 | 
				
			||||||
 | 
					                else:
 | 
				
			||||||
 | 
					                    value = '\'{}\''.format(self.args[key].get())
 | 
				
			||||||
 | 
					                command = '{} --{} {}'.format(command,key,value)
 | 
				
			||||||
            else:
 | 
					            else:
 | 
				
			||||||
                print('{}: Option vide'.format(key))
 | 
					                print('{}: Option vide'.format(key))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -20,37 +26,49 @@ class Interface(tk.Frame):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    def process_window(self,command):
 | 
					    def process_window(self,command):
 | 
				
			||||||
        term_window = tk.Toplevel(self.master,height='600',width='600')
 | 
					        term_window = tk.Toplevel(self.master,height='600',width='600')
 | 
				
			||||||
        term_window.title("Process in progress")
 | 
					        term_window.title("YDL: process in progress")
 | 
				
			||||||
        wid = term_window.winfo_id()
 | 
					        wid = term_window.winfo_id()
 | 
				
			||||||
        for key,value in self.args.items():
 | 
					        for key,value in self.args.items():
 | 
				
			||||||
            print('{} : {}'.format(key,value.get()))
 | 
					            print('{} : {}'.format(key,value.get()))
 | 
				
			||||||
        os.system('xterm -into {} -geometry 400x200 -hold -sb -e \'{}\' &'.format(wid,command))
 | 
					        system_command = 'xterm -into {} -geometry 400x200 -hold -sb -e \"{}\" &'.format(wid,command)
 | 
				
			||||||
 | 
					        print(system_command)
 | 
				
			||||||
 | 
					        os.system(system_command)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def select_directory(self):
 | 
				
			||||||
 | 
					        folder_selected = filedialog.askdirectory()
 | 
				
			||||||
 | 
					        self.dir.set(folder_selected)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def create_widgets(self):
 | 
					    def create_widgets(self):
 | 
				
			||||||
#
 | 
					 | 
				
			||||||
        tk.Label(self.master, padx=10,text="Youtube URL",bg="red").grid(row=0)
 | 
					 | 
				
			||||||
        tk.Label(self.master, padx=10,text="Folder").grid(row=1)
 | 
					 | 
				
			||||||
        tk.Label(self.master, padx=10,text="Podcast website root").grid(row=2)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        tk.Label(self.master, padx=10,text="Youtube URL",bg="red").grid(row=0,columnspan='1')
 | 
				
			||||||
 | 
					        tk.Label(self.master, padx=10,text="Folder").grid(row=1,columnspan='1')
 | 
				
			||||||
 | 
					        tk.Label(self.master, padx=10,text="Podcast website root").grid(row=2,columnspan='1')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # Vars attached to args
 | 
				
			||||||
        self.youtube_url = tk.StringVar()
 | 
					        self.youtube_url = tk.StringVar()
 | 
				
			||||||
        self.dir = tk.StringVar()
 | 
					        self.dir = tk.StringVar() 
 | 
				
			||||||
        self.url = tk.StringVar()
 | 
					        self.podcast_url = tk.StringVar()
 | 
				
			||||||
 | 
					 | 
				
			||||||
        tk.Entry(self.master,width=70, textvariable = self.youtube_url).grid(row=0, column=1,columnspan='8')
 | 
					 | 
				
			||||||
        tk.Entry(self.master,width=70, textvariable = self.dir).grid(row=1, column=1,columnspan='8')
 | 
					 | 
				
			||||||
        tk.Entry(self.master,width=70, textvariable = self.url).grid(row=2, column=1,columnspan='8')
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        self.simulate = tk.IntVar()
 | 
					        self.simulate = tk.IntVar()
 | 
				
			||||||
        self.feed = tk.IntVar()
 | 
					        self.feed = tk.IntVar()
 | 
				
			||||||
        self.video = tk.IntVar()
 | 
					        self.video = tk.IntVar()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # Default values
 | 
				
			||||||
 | 
					        # TODO: 
 | 
				
			||||||
 | 
					        self.youtube_url.set('https://www.youtube.com/watch?v=xJO5GstqTSY&list=PLxzM9a5lhAumFRpcigmGY1QLDYxb4-P2B')
 | 
				
			||||||
 | 
					        self.dir.set('~/Vidéos')
 | 
				
			||||||
 | 
					        self.podcast_url.set('podcast.lutix.org')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        tk.Entry(self.master,width=70,textvariable = self.youtube_url).grid(row=0, column=1,columnspan='8',sticky='W')
 | 
				
			||||||
 | 
					        tk.Entry(self.master, textvariable = self.dir).grid(row=1, column=1,columnspan='6',sticky='WE')
 | 
				
			||||||
 | 
					        tk.Entry(self.master,width=70, textvariable = self.podcast_url).grid(row=2, column=1,columnspan='8',sticky='W')
 | 
				
			||||||
        tk.Checkbutton(self.master, text="simulate", variable=self.simulate).grid(row=3,column=1,sticky='WE')
 | 
					        tk.Checkbutton(self.master, text="simulate", variable=self.simulate).grid(row=3,column=1,sticky='WE')
 | 
				
			||||||
        tk.Checkbutton(self.master, text="feed", variable=self.feed).grid(row=3,column=2,sticky='WE')
 | 
					        tk.Checkbutton(self.master, text="feed", variable=self.feed).grid(row=3,column=2,sticky='WE')
 | 
				
			||||||
        tk.Checkbutton(self.master, text="video only", variable=self.video).grid(row=3,column=3,sticky='WE')
 | 
					        tk.Checkbutton(self.master, text="video only", variable=self.video).grid(row=3,column=3,sticky='WE')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self.args = {'youtube_url':self.youtube_url,'dir':self.dir,'url':self.url,'simulate':self.simulate,'feed':self.feed,'video':self.video}
 | 
					        self.args = {'youtube_url':self.youtube_url,'dir':self.dir,'podcast_url':self.podcast_url,'simulate':self.simulate,'feed':self.feed,'video':self.video}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        tk.Button(self.master,text='Interrupt').grid(row=4,column=7,sticky='WE')
 | 
					
 | 
				
			||||||
 | 
					        tk.Button(self.master,text='Choose folder', command = self.select_directory).grid(row=1,column=8,sticky='WE')
 | 
				
			||||||
        tk.Button(self.master,text='Process', command = lambda: self.process_window(self.create_command())).grid(row=4,column=8,sticky='WE')
 | 
					        tk.Button(self.master,text='Process', command = lambda: self.process_window(self.create_command())).grid(row=4,column=8,sticky='WE')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										4
									
								
								ydl.py
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								ydl.py
									
									
									
									
									
								
							@ -26,7 +26,7 @@ class ydl_object:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        fg.title(self.infos['title'])
 | 
					        fg.title(self.infos['title'])
 | 
				
			||||||
        fg.description('none')
 | 
					        fg.description('none')
 | 
				
			||||||
        fg.link(href=self.args.url,rel='self')
 | 
					        fg.link(href=self.args.podcast_url,rel='self')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for item in self.infos['entries']:
 | 
					        for item in self.infos['entries']:
 | 
				
			||||||
            """
 | 
					            """
 | 
				
			||||||
@ -37,7 +37,7 @@ class ydl_object:
 | 
				
			|||||||
            fe.id(item['id'])
 | 
					            fe.id(item['id'])
 | 
				
			||||||
            fe.title(item['title'])
 | 
					            fe.title(item['title'])
 | 
				
			||||||
            fe.description(item['description'])
 | 
					            fe.description(item['description'])
 | 
				
			||||||
            item_full_path = self.args.url +'/'+self.infos['title']+'/'+item['title']+'.mp3'
 | 
					            item_full_path = self.args.podcast_url +'/'+self.infos['title']+'/'+item['title']+'.mp3'
 | 
				
			||||||
            fe.enclosure(item_full_path,str(item['duration']),'audio/mpeg')
 | 
					            fe.enclosure(item_full_path,str(item['duration']),'audio/mpeg')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        fg.rss_str(pretty=True)
 | 
					        fg.rss_str(pretty=True)
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user