Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- from tkinter import scrolledtext
- import subprocess
- import webbrowser
- from imdb import IMDb
- def search_movies():
- keyword = entry_search.get()
- ia = IMDb()
- movies = ia.search_movie(keyword)
- result_text.delete('1.0', tk.END)
- if not movies:
- result_text.insert(tk.END, "No results found.")
- else:
- for movie in movies[:10]: # Displaying the first 10 results
- title = movie['title']
- year = movie.get('year', 'N/A') # Get the year if available, otherwise use 'N/A'
- result_text.insert(tk.END, f"{title} ({year})\n")
- if 'imdb_id' in movie:
- link = f"https://www.imdb.com/title/{movie['imdb_id']}/"
- result_text.insert(tk.END, f"Link: {link}\n\n")
- else:
- result_text.insert(tk.END, "\n")
- def open_browser():
- selected_text = result_text.tag_ranges(tk.SEL)
- if selected_text:
- selected_movie_link = result_text.get(*selected_text).strip()
- if selected_movie_link.startswith("http://") or selected_movie_link.startswith("https://"):
- webbrowser.open(selected_movie_link)
- else:
- # Assuming selected_movie_link is the movie title and we construct the m4ufree link
- m4ufree_link = f"https://m4ufree.vip/search/{selected_movie_link}.html"
- webbrowser.open(m4ufree_link)
- # GUI
- root = tk.Tk()
- root.title("Movie Search")
- # Define colors
- background_color = '#333333'
- text_color = '#FFFFFF'
- button_color = '#4CAF50'
- button_text_color = '#FFFFFF'
- root.config(bg=background_color)
- frame_search = tk.Frame(root, bg=background_color)
- frame_search.pack(pady=10)
- label_search = tk.Label(frame_search, text="Enter Movie Name:", bg=background_color, fg=text_color)
- label_search.pack(side=tk.LEFT)
- entry_search = tk.Entry(frame_search, width=30)
- entry_search.pack(side=tk.LEFT)
- button_search = tk.Button(frame_search, text="Search", command=search_movies, bg=button_color, fg=button_text_color)
- button_search.pack(side=tk.LEFT, padx=10)
- frame_result = tk.Frame(root, bg=background_color)
- frame_result.pack(pady=10)
- result_text = scrolledtext.ScrolledText(frame_result, width=50, height=20, bg=background_color, fg=text_color)
- result_text.pack(side=tk.LEFT)
- button_open_browser = tk.Button(frame_search, text="Open in Browser", command=open_browser, bg=button_color, fg=button_text_color)
- button_open_browser.pack(side=tk.LEFT)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement