Skip to content

Instantly share code, notes, and snippets.

@641i130
Created October 16, 2023 03:11
Show Gist options
  • Save 641i130/2f1d7a2f8a8bfb0d30bf6f57e11df9e5 to your computer and use it in GitHub Desktop.
Save 641i130/2f1d7a2f8a8bfb0d30bf6f57e11df9e5 to your computer and use it in GitHub Desktop.
m3u to smpl converter
# M3U to Samsung SMPL Playlist Converter
# Written by ChatGPT
# This script converts an M3U playlist file to the Samsung SMPL format. It reads an M3U file, extracts file paths,
# and generates a Samsung SMPL JSON file with a "members" array, where each item represents a file from the M3U playlist.
# Samsung SMPL format is old but used in the samsung music app here: https://github.com/AyraHikari/SamsungMusicPort
import json
import json
def convert_m3u_to_smpl(m3u_file, smpl_file_name):
members = []
with open(m3u_file, "r") as m3u:
order = 0
for line in m3u:
line = line.strip()
if not line or line.startswith("#EXTM3U"):
continue
elif line.startswith("#EXTINF"):
title = line.split(",", 1)[1] if "," in line else ""
else:
file_path = line
members.append({
"artist": "",
"info": file_path,
"order": order,
"title": "", # Samsung music doesn't care for some reason
"type": 65537
})
order += 1
smpl_data = {
"members": members,
"name": "Favorite",
"recentlyPlayedDate": 0,
"sortBy": 4,
"version": 1
}
with open(smpl_file_name, "w") as smpl_file:
json.dump(smpl_data, smpl_file, indent=4)
if __name__ == "__main__":
m3u_file = "out.m3u" # Replace with your M3U file name
smpl_file = "converted_playlist.smpl" # Replace with the desired SMPL file name
convert_m3u_to_smpl(m3u_file, smpl_file)
@Big-mac23
Copy link

When running the file, it showed a UnicodeDecodeError on my device
UnicodeDecodeError: 'charmap' codec can't decode byte 0x90 in position 250: character maps to <undefined>

This error can be rectified by adding the encoding when opening the file

with open(m3u_file, "r") as m3u:
to
with open(m3u_file, "r", encoding="utf8") as m3u:

worked beautifully otherwise, thanks a lot for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment