Update interface

This commit is contained in:
Firstname Lastname 2019-12-17 21:55:57 +01:00
parent 46fbf89ca1
commit c7c41e7468
3 changed files with 44 additions and 19 deletions

11
core.py
View File

@ -6,6 +6,7 @@ import sys
import argparse
import ydl
import interface
import tkinter as tk
#TODO:
# 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("-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("-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")
args = parser.parse_args()
if __name__ == "__main__":
if args.interface:
print(args.interface)
if not args.interface:
ydlo = ydl.ydl_object(args)
ydlo.print_infos()
ydlo.process_args()
else:
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()

View File

@ -1,4 +1,5 @@
import tkinter as tk
from tkinter import filedialog
import os
class Interface(tk.Frame):
@ -12,6 +13,11 @@ class Interface(tk.Frame):
for key in self.args:
if bool(self.args[key].get()):
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:
print('{}: Option vide'.format(key))
@ -20,37 +26,49 @@ class Interface(tk.Frame):
def process_window(self,command):
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()
for key,value in self.args.items():
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):
#
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.dir = tk.StringVar()
self.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.dir = tk.StringVar()
self.podcast_url = tk.StringVar()
self.simulate = tk.IntVar()
self.feed = 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="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')
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')

4
ydl.py
View File

@ -26,7 +26,7 @@ class ydl_object:
fg.title(self.infos['title'])
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']:
"""
@ -37,7 +37,7 @@ class ydl_object:
fe.id(item['id'])
fe.title(item['title'])
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')
fg.rss_str(pretty=True)