Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- from tkinter import filedialog, messagebox, scrolledtext
- def browse_file():
- filepath = filedialog.askopenfilename(
- title="Open Playlist .txt file",
- filetypes=(("Text Files", "*.txt"), ("All Files", "*.*"))
- )
- if filepath:
- try:
- with open(filepath, 'r', encoding='utf-8') as file:
- content = file.read()
- text_field.delete(1.0, tk.END)
- text_field.insert(tk.END, content)
- except Exception as e:
- messagebox.showerror("Error", f"An error occurred while reading the file: {e}")
- def convert_playlist():
- try:
- content = text_field.get(1.0, tk.END).strip()
- lines = content.split('\n')
- if len(lines) % 2 != 0:
- messagebox.showerror("Error", "Invalid content format. Make sure each URL is preceded by a channel name.")
- return
- m3u_lines = ['#EXTM3U\n']
- for i in range(0, len(lines), 2):
- name_line = lines[i].strip()
- url_line = lines[i + 1].strip()
- m3u_lines.append(f'#EXTINF:-1 group-title="{name_line}"\n{url_line}\n')
- output_filepath = filedialog.asksaveasfilename(
- defaultextension=".m3u",
- filetypes=(("M3U Files", "*.m3u"), ("All Files", "*.*")),
- title="Save Converted Playlist"
- )
- if output_filepath:
- with open(output_filepath, 'w') as output_file:
- output_file.writelines(m3u_lines)
- messagebox.showinfo("Success", f"Playlist successfully saved to {output_filepath}")
- except Exception as e:
- messagebox.showerror("Error", f"An error occurred: {e}")
- root = tk.Tk()
- root.title("Najeeb Playlist Converter")
- root.configure(bg="#4a4a4a")
- frame = tk.Frame(root, padx=5, pady=5, bg="#4a4a4a")
- frame.pack(padx=5, pady=5)
- browse_button = tk.Button(frame, text="Browse .txt File", command=browse_file, bg="#5a5a5a", fg="white")
- browse_button.pack()
- text_frame = tk.Frame(frame)
- text_frame.pack(padx=5, pady=5, fill=tk.BOTH, expand=True)
- scrollbar = tk.Scrollbar(text_frame)
- #scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
- text_field = scrolledtext.ScrolledText(text_frame, wrap=tk.WORD, yscrollcommand=scrollbar.set, height=20, width=110)
- text_field.pack(padx=5, pady=5, fill=tk.BOTH, expand=True)
- scrollbar.config(command=text_field.yview)
- convert_button = tk.Button(frame, text="Convert to .m3u", command=convert_playlist, bg="#5a5a5a", fg="white")
- convert_button.pack(pady=10)
- root.mainloop()
Add Comment
Please, Sign In to add comment