Advertisement
Najeebsk

IPTV-GITHUB-CATEGORIES.pyw

Apr 16th, 2024
656
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.40 KB | None | 0 0
  1. import tkinter as tk
  2. from tkinter import ttk, scrolledtext
  3. import requests
  4. from tkinter import messagebox
  5.  
  6. def save_m3u():
  7.     selected_category = category_combo.get()
  8.     url = categories.get(selected_category)
  9.     if url:
  10.         try:
  11.             response = requests.get(url)
  12.             with open(f"{selected_category}.m3u", "wb") as f:
  13.                 f.write(response.content)
  14.             messagebox.showinfo("Success", f"{selected_category}.m3u saved successfully!")
  15.         except requests.RequestException as e:
  16.             messagebox.showerror("Error", f"Failed to save {selected_category}.m3u: {str(e)}")
  17.     else:
  18.         messagebox.showerror("Error", "Invalid category selected.")
  19.  
  20. def show_m3u():
  21.     selected_category = category_combo.get()
  22.     url = categories.get(selected_category)
  23.     if url:
  24.         try:
  25.             response = requests.get(url)
  26.             display_m3u(response.content.decode("utf-8"))
  27.         except requests.RequestException as e:
  28.             messagebox.showerror("Error", f"Failed to fetch {selected_category}.m3u: {str(e)}")
  29.     else:
  30.         messagebox.showerror("Error", "Invalid category selected.")
  31.  
  32. def display_m3u(contents):
  33.     text.delete(1.0, tk.END)
  34.     text.insert(tk.END, contents)
  35.  
  36. # M3U URLs
  37. categories = {
  38.     "Animation": "https://iptv-org.github.io/iptv/categories/animation.m3u",
  39.     "Auto": "https://iptv-org.github.io/iptv/categories/auto.m3u",
  40.     "Business": "https://iptv-org.github.io/iptv/categories/business.m3u",
  41.     "Classic": "https://iptv-org.github.io/iptv/categories/classic.m3u",
  42.     "Comedy": "https://iptv-org.github.io/iptv/categories/comedy.m3u",
  43.     "Cooking": "https://iptv-org.github.io/iptv/categories/cooking.m3u",
  44.     "Culture": "https://iptv-org.github.io/iptv/categories/culture.m3u",
  45.     "Documentary": "https://iptv-org.github.io/iptv/categories/documentary.m3u",
  46.     "Education": "https://iptv-org.github.io/iptv/categories/education.m3u",
  47.     "Entertainment": "https://iptv-org.github.io/iptv/categories/entertainment.m3u",
  48.     "Family": "https://iptv-org.github.io/iptv/categories/family.m3u",
  49.     "General": "https://iptv-org.github.io/iptv/categories/general.m3u",
  50.     "Kids": "https://iptv-org.github.io/iptv/categories/kids.m3u",
  51.     "Legislative": "https://iptv-org.github.io/iptv/categories/legislative.m3u",
  52.     "Lifestyle": "https://iptv-org.github.io/iptv/categories/lifestyle.m3u",
  53.     "Movies": "https://iptv-org.github.io/iptv/categories/movies.m3u",
  54.     "Music": "https://iptv-org.github.io/iptv/categories/music.m3u",
  55.     "News": "https://iptv-org.github.io/iptv/categories/news.m3u",
  56.     "Outdoor": "https://iptv-org.github.io/iptv/categories/outdoor.m3u",
  57.     "Relax": "https://iptv-org.github.io/iptv/categories/relax.m3u",
  58.     "Religious": "https://iptv-org.github.io/iptv/categories/religious.m3u",
  59.     "Science": "https://iptv-org.github.io/iptv/categories/science.m3u",
  60.     "Series": "https://iptv-org.github.io/iptv/categories/series.m3u",
  61.     "Shop": "https://iptv-org.github.io/iptv/categories/shop.m3u",
  62.     "Sports": "https://iptv-org.github.io/iptv/categories/sports.m3u",
  63.     "Travel": "https://iptv-org.github.io/iptv/categories/travel.m3u",
  64.     "Weather": "https://iptv-org.github.io/iptv/categories/weather.m3u",
  65.     "XXX": "https://iptv-org.github.io/iptv/categories/xxx.m3u",
  66.     "Undefined": "https://iptv-org.github.io/iptv/categories/undefined.m3u"
  67. }
  68.  
  69. # GUI setup
  70. root = tk.Tk()
  71. root.title("M3U Playlist Downloader")
  72.  
  73. # Frame for categories
  74. category_frame = ttk.Frame(root)
  75. category_frame.pack(padx=10, pady=10)
  76.  
  77. # Label for category dropdown list
  78. category_label = ttk.Label(category_frame, text="Categories:")
  79. category_label.grid(row=0, column=0, padx=5, pady=5)
  80.  
  81. # Dropdown list for categories
  82. category_combo = ttk.Combobox(category_frame, values=list(categories.keys()))
  83. category_combo.grid(row=0, column=1, padx=5, pady=5)
  84. category_combo.current(0)  # Set default value
  85.  
  86. # Button to save M3U file for categories
  87. save_category_button = tk.Button(category_frame, text="Save M3U", command=save_m3u)
  88. save_category_button.grid(row=0, column=2, padx=5, pady=5)
  89.  
  90. # Button to show M3U file for categories
  91. show_category_button = tk.Button(category_frame, text="Show M3U", command=show_m3u)
  92. show_category_button.grid(row=0, column=3, padx=5, pady=5)
  93.  
  94. # Text field to display M3U contents
  95. text = scrolledtext.ScrolledText(root, width=60, height=20)
  96. text.pack(pady=10)
  97.  
  98. root.mainloop()
  99.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement