Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- from tkinter import ttk, scrolledtext
- import requests
- from tkinter import messagebox
- def save_m3u():
- selected_category = category_combo.get()
- url = categories.get(selected_category)
- if url:
- try:
- response = requests.get(url)
- with open(f"{selected_category}.m3u", "wb") as f:
- f.write(response.content)
- messagebox.showinfo("Success", f"{selected_category}.m3u saved successfully!")
- except requests.RequestException as e:
- messagebox.showerror("Error", f"Failed to save {selected_category}.m3u: {str(e)}")
- else:
- messagebox.showerror("Error", "Invalid category selected.")
- def show_m3u():
- selected_category = category_combo.get()
- url = categories.get(selected_category)
- if url:
- try:
- response = requests.get(url)
- display_m3u(response.content.decode("utf-8"))
- except requests.RequestException as e:
- messagebox.showerror("Error", f"Failed to fetch {selected_category}.m3u: {str(e)}")
- else:
- messagebox.showerror("Error", "Invalid category selected.")
- def display_m3u(contents):
- text.delete(1.0, tk.END)
- text.insert(tk.END, contents)
- # M3U URLs
- categories = {
- "Animation": "https://iptv-org.github.io/iptv/categories/animation.m3u",
- "Auto": "https://iptv-org.github.io/iptv/categories/auto.m3u",
- "Business": "https://iptv-org.github.io/iptv/categories/business.m3u",
- "Classic": "https://iptv-org.github.io/iptv/categories/classic.m3u",
- "Comedy": "https://iptv-org.github.io/iptv/categories/comedy.m3u",
- "Cooking": "https://iptv-org.github.io/iptv/categories/cooking.m3u",
- "Culture": "https://iptv-org.github.io/iptv/categories/culture.m3u",
- "Documentary": "https://iptv-org.github.io/iptv/categories/documentary.m3u",
- "Education": "https://iptv-org.github.io/iptv/categories/education.m3u",
- "Entertainment": "https://iptv-org.github.io/iptv/categories/entertainment.m3u",
- "Family": "https://iptv-org.github.io/iptv/categories/family.m3u",
- "General": "https://iptv-org.github.io/iptv/categories/general.m3u",
- "Kids": "https://iptv-org.github.io/iptv/categories/kids.m3u",
- "Legislative": "https://iptv-org.github.io/iptv/categories/legislative.m3u",
- "Lifestyle": "https://iptv-org.github.io/iptv/categories/lifestyle.m3u",
- "Movies": "https://iptv-org.github.io/iptv/categories/movies.m3u",
- "Music": "https://iptv-org.github.io/iptv/categories/music.m3u",
- "News": "https://iptv-org.github.io/iptv/categories/news.m3u",
- "Outdoor": "https://iptv-org.github.io/iptv/categories/outdoor.m3u",
- "Relax": "https://iptv-org.github.io/iptv/categories/relax.m3u",
- "Religious": "https://iptv-org.github.io/iptv/categories/religious.m3u",
- "Science": "https://iptv-org.github.io/iptv/categories/science.m3u",
- "Series": "https://iptv-org.github.io/iptv/categories/series.m3u",
- "Shop": "https://iptv-org.github.io/iptv/categories/shop.m3u",
- "Sports": "https://iptv-org.github.io/iptv/categories/sports.m3u",
- "Travel": "https://iptv-org.github.io/iptv/categories/travel.m3u",
- "Weather": "https://iptv-org.github.io/iptv/categories/weather.m3u",
- "XXX": "https://iptv-org.github.io/iptv/categories/xxx.m3u",
- "Undefined": "https://iptv-org.github.io/iptv/categories/undefined.m3u"
- }
- # GUI setup
- root = tk.Tk()
- root.title("M3U Playlist Downloader")
- # Frame for categories
- category_frame = ttk.Frame(root)
- category_frame.pack(padx=10, pady=10)
- # Label for category dropdown list
- category_label = ttk.Label(category_frame, text="Categories:")
- category_label.grid(row=0, column=0, padx=5, pady=5)
- # Dropdown list for categories
- category_combo = ttk.Combobox(category_frame, values=list(categories.keys()))
- category_combo.grid(row=0, column=1, padx=5, pady=5)
- category_combo.current(0) # Set default value
- # Button to save M3U file for categories
- save_category_button = tk.Button(category_frame, text="Save M3U", command=save_m3u)
- save_category_button.grid(row=0, column=2, padx=5, pady=5)
- # Button to show M3U file for categories
- show_category_button = tk.Button(category_frame, text="Show M3U", command=show_m3u)
- show_category_button.grid(row=0, column=3, padx=5, pady=5)
- # Text field to display M3U contents
- text = scrolledtext.ScrolledText(root, width=60, height=20)
- text.pack(pady=10)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement