Advertisement
Najeebsk

MOVEIS-SEARCH.py

Mar 15th, 2024
669
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.47 KB | None | 0 0
  1. import tkinter as tk
  2. from tkinter import scrolledtext
  3. import subprocess
  4. import webbrowser
  5. from imdb import IMDb
  6.  
  7. def search_movies():
  8.     keyword = entry_search.get()
  9.     ia = IMDb()
  10.     movies = ia.search_movie(keyword)
  11.     result_text.delete('1.0', tk.END)
  12.     if not movies:
  13.         result_text.insert(tk.END, "No results found.")
  14.     else:
  15.         for movie in movies[:10]:  # Displaying the first 10 results
  16.             title = movie['title']
  17.             year = movie.get('year', 'N/A')  # Get the year if available, otherwise use 'N/A'
  18.             result_text.insert(tk.END, f"{title} ({year})\n")
  19.             if 'imdb_id' in movie:
  20.                 link = f"https://www.imdb.com/title/{movie['imdb_id']}/"
  21.                 result_text.insert(tk.END, f"Link: {link}\n\n")
  22.             else:
  23.                 result_text.insert(tk.END, "\n")
  24.  
  25. def open_browser():
  26.     selected_text = result_text.tag_ranges(tk.SEL)
  27.     if selected_text:
  28.         selected_movie_link = result_text.get(*selected_text).strip()
  29.         if selected_movie_link.startswith("http://") or selected_movie_link.startswith("https://"):
  30.             webbrowser.open(selected_movie_link)
  31.         else:
  32.             # Assuming selected_movie_link is the movie title and we construct the m4ufree link
  33.             m4ufree_link = f"https://m4ufree.vip/search/{selected_movie_link}.html"
  34.             webbrowser.open(m4ufree_link)
  35.  
  36. # GUI
  37. root = tk.Tk()
  38. root.title("Movie Search")
  39.  
  40. # Define colors
  41. background_color = '#333333'
  42. text_color = '#FFFFFF'
  43. button_color = '#4CAF50'
  44. button_text_color = '#FFFFFF'
  45.  
  46. root.config(bg=background_color)
  47.  
  48. frame_search = tk.Frame(root, bg=background_color)
  49. frame_search.pack(pady=10)
  50.  
  51. label_search = tk.Label(frame_search, text="Enter Movie Name:", bg=background_color, fg=text_color)
  52. label_search.pack(side=tk.LEFT)
  53.  
  54. entry_search = tk.Entry(frame_search, width=30)
  55. entry_search.pack(side=tk.LEFT)
  56.  
  57. button_search = tk.Button(frame_search, text="Search", command=search_movies, bg=button_color, fg=button_text_color)
  58. button_search.pack(side=tk.LEFT, padx=10)
  59.  
  60. frame_result = tk.Frame(root, bg=background_color)
  61. frame_result.pack(pady=10)
  62.  
  63. result_text = scrolledtext.ScrolledText(frame_result, width=50, height=20, bg=background_color, fg=text_color)
  64. result_text.pack(side=tk.LEFT)
  65.  
  66. button_open_browser = tk.Button(frame_search, text="Open in Browser", command=open_browser, bg=button_color, fg=button_text_color)
  67. button_open_browser.pack(side=tk.LEFT)
  68.  
  69. root.mainloop()
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement