diff --git a/README.md b/README.md index 91f589a..28c102d 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,8 @@ Welcome to celaigia an app to gently query youtube music, and possibly download only if you don't have already locally - -- gitignore music -- standardize postprocess -- parametrize and make config -- fix ui and reduce number of searches -- add direct download with url -- place query on ui -- document \ No newline at end of file +# TODO +- explore the db +- nicer ui +- contenerize +- mobile diff --git a/database.py b/database.py index 32a0b7e..0627e0b 100644 --- a/database.py +++ b/database.py @@ -24,3 +24,14 @@ class Database: if entry['id'] == idx or entry['title'] == title: return False return True + + def get_all_entries(self): + return self.data + + def update_entry(self, entry_id, new_data): + for entry in self.data: + if entry['id'] == entry_id: + entry.update(new_data) + with open(self.file_path, 'w') as file: + json.dump(self.data, file, indent=4) + return diff --git a/requirements.txt b/requirements.txt index e69de29..b21e42f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -0,0 +1 @@ +yt-dlp \ No newline at end of file diff --git a/ui.py b/ui.py index c1ac7fb..6ed7198 100644 --- a/ui.py +++ b/ui.py @@ -12,11 +12,21 @@ class UIEngine: self.root.title("celaigia") self.root.geometry("400x300") # Set a fixed size - self.status_label = tk.Label(self.root, text="Ready") + # Create a PanedWindow to split the UI vertically + self.paned_window = tk.PanedWindow(self.root, orient=tk.VERTICAL) + self.paned_window.pack(expand=True, fill='both') + + # Create the top part of the UI + self.top_frame = ttk.Frame(self.paned_window) + self.paned_window.add(self.top_frame) + + self.status_label = tk.Label(self.top_frame, text="Ready") self.status_label.pack() - self.search_frame = ttk.Frame(self.root) + self.search_frame = ttk.Frame(self.top_frame) self.search_frame.pack() + self.download_frame = ttk.Frame(self.top_frame) + self.download_frame.pack() self.search_status_label = tk.Label(self.search_frame, text="Enter search query:") self.search_status_label.grid(row=0, column=0) @@ -25,15 +35,51 @@ class UIEngine: self.search_button = tk.Button(self.search_frame, text="Search", command=lambda: self.search_and_display()) self.search_button.grid(row=0, column=2) - self.results_frame = ttk.Frame(self.root) + self.download_status_label = tk.Label(self.download_frame, text="Enter URL to download:") + self.download_status_label.grid(row=0, column=0) + self.download_entry = tk.Entry(self.download_frame) + self.download_entry.grid(row=0,column=1) + self.download_button = tk.Button(self.download_frame, text="Download", command=lambda: self.handle_download(self.download_entry.get())) + self.download_button.grid(row=0, column=2) + + # Create the bottom part of the UI with tabs + self.bottom_frame = ttk.Frame(self.paned_window) + self.paned_window.add(self.bottom_frame) + + self.notebook = ttk.Notebook(self.bottom_frame) + self.notebook.pack(fill='both', expand=True) + + self.create_search_tab() + self.create_database_tab(db) + + def create_search_tab(self): + search_tab = ttk.Frame(self.notebook) + self.notebook.add(search_tab, text='Search&Download') + self.status_label = tk.Label(search_tab, text="Ready") + self.status_label.pack() + + # Create a frame for displaying search results + self.results_frame = ttk.Frame(search_tab) self.results_frame.pack() - self.download_status_label = tk.Label(self.root, text="Enter URL to download:") - self.download_status_label.pack() - self.download_entry = tk.Entry(self.root) - self.download_entry.pack() - self.download_button = tk.Button(self.root, text="Download", command=lambda: self.handle_download(self.download_entry.get())) - self.download_button.pack() + def create_database_tab(self, db): + database_tab = ttk.Frame(self.notebook) + self.notebook.add(database_tab, text='Database') + + tree = ttk.Treeview(database_tab, columns=("title", "artist", "filename", "tags", "timestamp")) + tree.heading("#0", text="ID") + tree.heading("title", text="Title") + tree.heading("artist", text="Artist") + tree.heading("filename", text="Filename") + tree.heading("tags", text="Tags") + tree.heading("timestamp", text="Timestamp") + + # Populate the treeview with data from the database + for entry in db.get_all_entries(): + tree.insert("", "end", text=entry["id"], values=(entry["title"], entry["artist"], entry["filename"], ", ".join(entry["tags"]), entry["timestamp"])) + + tree.pack(fill='both', expand=True) + def search_and_display(self): self.set_status("searching") @@ -49,10 +95,15 @@ class UIEngine: self.status_label.config(text=status) self.root.update() # Force GUI update + # Modify the display_results method to use the results_frame in the search_tab def display_results(self, results): for i, result in enumerate(results): - result_button = ttk.Button(self.results_frame, text=result['title'], command=lambda url=result['webpage_url'], filename=result['title']: self.handle_download(url, filename)) - result_button.pack() + if self.db.downloadable(result['webpage_url'], result['title']): + result_button = ttk.Button(self.results_frame, text=result['title'], command=lambda url=result['webpage_url'], filename=result['title']: self.handle_download(url, filename)) + result_button.pack() + else: + result_button = tk.Label(self.results_frame, text=f"celaigia: {result['title']}") + result_button.pack() def handle_download(self, url, filename):