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.

Revisions

  1. 641i130 created this gist Oct 16, 2023.
    48 changes: 48 additions & 0 deletions run.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,48 @@
    # 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)