Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- from tkinter import filedialog, messagebox, scrolledtext
- class IPTVEditor(tk.Tk):
- def __init__(self):
- super().__init__()
- self.title("Najeeb IPTV Playlist Duplicate Editor")
- self.geometry("800x600")
- self.configure(bg="#4a4a4a")
- self.playlist = []
- self.duplicates = []
- self.create_widgets()
- def create_widgets(self):
- # Frame for buttons
- frame = tk.Frame(self, bg="#4a4a4a")
- #frame = tk.Frame(self)
- frame.pack(fill=tk.X, padx=10, pady=10)
- load_button = tk.Button(frame, text="Browse IPTV", command=self.load_file, bg="#5a5a5a", fg="white")
- load_button.pack(side=tk.LEFT, padx=5)
- remove_button = tk.Button(frame, text="Remove Duplicates", command=self.remove_duplicates, bg="#5a5a5a", fg="white")
- remove_button.pack(side=tk.LEFT, padx=5)
- save_button = tk.Button(frame, text="Save .m3u", command=self.save_m3u, bg="#5a5a5a", fg="white")
- save_button.pack(side=tk.LEFT, padx=5)
- # Text field for displaying the playlist
- self.text_area = scrolledtext.ScrolledText(self, wrap=tk.WORD)
- self.text_area.pack(fill=tk.BOTH, expand=True, padx=10, pady=10)
- self.text_area.config(state=tk.DISABLED)
- def load_file(self):
- file_path = filedialog.askopenfilename(filetypes=[("Playlist files", "*.m3u *.m3u8 *.txt")])
- if file_path:
- with open(file_path, 'r', encoding='utf-8') as file:
- self.playlist = file.readlines()
- self.find_duplicates()
- self.display_playlist()
- def find_duplicates(self):
- url_set = set()
- self.duplicates = []
- i = 0
- while i < len(self.playlist):
- line = self.playlist[i]
- if line.startswith("http"):
- if line in url_set:
- self.duplicates.append((self.playlist[i-1], line)) # Add both the #EXTINF and URL
- else:
- url_set.add(line)
- i += 1
- def display_playlist(self):
- self.text_area.config(state=tk.NORMAL)
- self.text_area.delete(1.0, tk.END)
- i = 0
- while i < len(self.playlist):
- line = self.playlist[i]
- if line.startswith("#EXTINF:"):
- next_line = self.playlist[i+1] if i+1 < len(self.playlist) else ''
- if (line, next_line) in self.duplicates:
- self.text_area.insert(tk.END, line, "duplicate")
- self.text_area.insert(tk.END, next_line, "duplicate")
- i += 2
- continue
- self.text_area.insert(tk.END, line)
- i += 1
- self.text_area.tag_config("duplicate", background="yellow")
- self.text_area.config(state=tk.DISABLED)
- def remove_duplicates(self):
- seen_urls = set()
- new_playlist = []
- i = 0
- while i < len(self.playlist):
- line = self.playlist[i]
- if line.startswith("http"):
- if line not in seen_urls:
- seen_urls.add(line)
- new_playlist.extend([self.playlist[i-1], line]) # Add both the #EXTINF and URL
- i += 1
- else:
- if i == 0 or not (i+1 < len(self.playlist) and self.playlist[i+1].startswith("http")):
- new_playlist.append(line)
- i += 1
- self.playlist = new_playlist
- self.find_duplicates()
- self.display_playlist()
- def save_m3u(self):
- file_path = filedialog.asksaveasfilename(defaultextension=".m3u", filetypes=[("M3U files", "*.m3u")])
- if file_path:
- with open(file_path, 'w', encoding='utf-8') as file:
- file.writelines(self.playlist)
- messagebox.showinfo("Save", "Playlist saved successfully")
- if __name__ == "__main__":
- app = IPTVEditor()
- app.mainloop()
Add Comment
Please, Sign In to add comment