Najeebsk

RADIOS-M3U.py

Mar 21st, 2024
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.41 KB | None | 0 0
  1. import tkinter as tk
  2. from tkinter import filedialog
  3. from tkinter import ttk  # Import ttk module for themed scrollbar
  4. import vlc
  5.  
  6. def open_radio():
  7.     selected_radio = listbox.curselection()
  8.     if selected_radio:
  9.         index = int(selected_radio[0])
  10.         selected_radio_title = radio_titles[index]
  11.         selected_radio_url = radio_urls[index]
  12.         textfield.delete(1.0, tk.END)
  13.         textfield.insert(tk.END, selected_radio_title)
  14.         media = instance.media_new(selected_radio_url)
  15.         player.set_media(media)
  16.         player.play()
  17.  
  18. def load_radios():
  19.     file_path = filedialog.askopenfilename(filetypes=[("M3U files", "*.m3u")])
  20.     if file_path:
  21.         with open(file_path, 'r', encoding='utf-8') as f:
  22.             global radio_titles, radio_urls
  23.             radio_titles, radio_urls = [], []
  24.             for line in f:
  25.                 if line.startswith('#EXTINF:'):
  26.                     title = line.split(',')[-1].strip()
  27.                     radio_titles.append(title)
  28.                 elif line.strip() and not line.startswith('#'):
  29.                     radio_urls.append(line.strip())
  30.             for title in radio_titles:
  31.                 listbox.insert(tk.END, title)
  32.  
  33. # Create main window
  34. root = tk.Tk()
  35. root.title("Najeeb Radio Player")
  36. root.geometry("600x230")
  37. # Define colors
  38. background_color = 'lightgreen'
  39. text_color = '#FFFFFF'
  40. button_color = '#4CAF50'
  41. button_text_color = '#FFFFFF'
  42.  
  43. root.config(bg=background_color)
  44.  
  45. # Create VLC instance and player
  46. instance = vlc.Instance('--no-xlib')
  47. player = instance.media_player_new()
  48.  
  49. # Create and pack widgets
  50. textfield = tk.Text(root, height=1, width=100)
  51. textfield.pack(pady=10, padx=10)
  52.  
  53. listbox_frame = tk.Frame(root)
  54. listbox_frame.pack(padx=10, pady=5)
  55.  
  56. scrollbar = ttk.Scrollbar(listbox_frame, orient=tk.VERTICAL)
  57. listbox = tk.Listbox(listbox_frame, selectmode=tk.SINGLE, height=6, width=48, font=("Time New Roman", 16, "bold"), yscrollcommand=scrollbar.set)
  58. scrollbar.config(command=listbox.yview)
  59. scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
  60. listbox.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
  61.  
  62. load_button = tk.Button(root, text="Load Radios", command=load_radios, bg=button_color, fg=button_text_color)
  63. load_button.pack(side=tk.LEFT, padx=10)
  64.  
  65. play_button = tk.Button(root, text="Play Radio", command=open_radio, bg=button_color, fg=button_text_color)
  66. play_button.pack(side=tk.RIGHT, padx=10)
  67.  
  68. root.mainloop()
  69.  
Add Comment
Please, Sign In to add comment