Sep-15-2021, 06:43 PM
in_text = open("playlist.m3u", "r").read()
reads the the file into a string
out_text = ""
creates an empty string for later use
for line in in_text.splitlines(): # read every line if line.startswith("#EXTINF"): out_text += line # take over the whole line name = line.split(",", 1)[1] # split the line at the first comma and use the text after the comma out_text += f'\n{name}.mp3\n' # add newline, name from split and newline to the output else: out_text += f"{line}\n" # if line has no EXTINF use it without splitting with open("new_playlist.m3u", "w") as f: f.write(out_text) f.close()f means f-strings in pyhon
https://realpython.com/python-f-strings/