Skip to content

Instantly share code, notes, and snippets.

@marios8543
Created November 28, 2018 21:48
Show Gist options
  • Save marios8543/ecf01003b126b9a46c3131a3be2b698d to your computer and use it in GitHub Desktop.
Save marios8543/ecf01003b126b9a46c3131a3be2b698d to your computer and use it in GitHub Desktop.
A python tool to convert ASF playlists to M3U playlists. Also performs path decoding...
import xml.etree.ElementTree as et
from urllib.parse import unquote
import tkinter as tk
from tkinter import filedialog,messagebox
outstr = "#EXTM3U\n"
infile = filedialog.askopenfile(filetypes=(("ASF Playlists","*.asf"),))
f = et.parse(infile).getroot()
count = 0
for i in f.findall("entry"):
length = 0
link = unquote(i.find("ref").get("href"))
try:
title = i.find("title").text
except Exception:
title = ""
try:
artist = i.find("author").text
except Exception:
artist = ""
outstr+="#EXTINF:{},{}{}\n{}\n".format(length,artist+" - " if artist else "",title,link)
count+=1
with filedialog.asksaveasfile(filetypes=(("M3U Playlists","*.m3u"),)) as ofile:
ofile.write(outstr)
ofile.close()
messagebox.showinfo("Done", "Processed {} songs".format(count))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment