Author Topic: Script to edit MusicBee-Playlists (.mbp)  (Read 4737 times)


  • Newbie
  • *
  • Posts: 3

I had the need to add items to a playlist in MusicBee-format (.mbp), so my external music-downloader can write directly into it. I wrote a PowerShell-script which does exactly this.

It's not thoroughly tested, so use with caution. Also I don't know if offset calculation will work in every case. It's also quite dirty, there's no error handling and it will only work for playlists smaller than 65535 songs. But it works.

Function AddTo-MBP($pls, $song, $top) {
    $endchar = @(0xFF,0xFF,0xFF,0xFF)
    $add = [System.Text.Encoding]::Default.GetString($song.length) + $song
    $add = $add + [System.Text.Encoding]::Default.GetString($endchar)
    $mbp = [System.IO.File]::ReadAllText("$pls", [System.Text.Encoding]::Default)
    $offset = $mbp.LastIndexOf(0x00)+1
    if ($top) {
        $mbp = $mbp.Insert($offset,$add)
    } else {
        $mbp = $mbp.Insert($mbp.Length,$add)
    $bytes = [System.Text.Encoding]::Default.GetBytes($mbp)
    if ($bytes[$offset-4] -eq 0xFF) {
        $bytes[$offset-4] = 0x00
        $bytes[$offset-3] ++
    } else {
        $bytes[$offset-4] ++

AddTo-MBP "D:\Music\_Playlists\2019.mbp" "D:\Music\New-Music\2 Tyme ft. Leanne Brown - My Heart Is Yours (Rare Candy Remix).mp3" $false

AddTo-MBP <fullpath-to-playlist> <fullpath-to-song> <boolean-add-to-top>
($false = insert at bottom, $true = insert at top)

Have fun
Last Edit: January 05, 2019, 01:31:06 PM by icstyle