Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- from tkinter import filedialog, messagebox
- import os
- class M3UConverterApp(tk.Tk):
- def __init__(self):
- super().__init__()
- self.title("Najeeb Text To M3U Converter")
- self.geometry("400x200")
- self.configure(bg="#282C34")
- self.create_widgets()
- def create_widgets(self):
- # Select File Button
- self.select_file_btn = tk.Button(self, text="Select Text File", command=self.select_file, bg='lightblue', fg='black')
- self.select_file_btn.pack(pady=20)
- # Convert Button
- self.convert_btn = tk.Button(self, text="Convert to M3U", command=self.convert_to_m3u, bg='lightgreen', fg='black')
- self.convert_btn.pack(pady=20)
- def select_file(self):
- self.file_path = filedialog.askopenfilename(filetypes=[("Text Files", "*.txt")])
- if self.file_path:
- messagebox.showinfo("File Selected", f"Selected file: {os.path.basename(self.file_path)}")
- def convert_to_m3u(self):
- if not hasattr(self, 'file_path'):
- messagebox.showwarning("No File Selected", "Please select a file first.")
- return
- m3u_content = "#EXTM3U\n"
- with open(self.file_path, 'r', encoding='utf-8') as file:
- for line in file:
- # Assuming the line format is "XXX-VIP http://url.com/path"
- if line.strip():
- name, url = line.split(maxsplit=1)
- m3u_content += f"#EXTINF:-1,{name}\n{url}\n"
- save_path = filedialog.asksaveasfilename(defaultextension=".m3u", filetypes=[("M3U Files", "*.m3u")])
- if save_path:
- with open(save_path, 'w', encoding='utf-8') as m3u_file:
- m3u_file.write(m3u_content)
- messagebox.showinfo("Conversion Complete", f"M3U file saved as {os.path.basename(save_path)}")
- if __name__ == "__main__":
- app = M3UConverterApp()
- app.mainloop()
Add Comment
Please, Sign In to add comment