Jellyfin Forum
Help with playlist script windows - Printable Version

+- Jellyfin Forum (https://forum.jellyfin.org)
+-- Forum: Off Topic (https://forum.jellyfin.org/f-off-topic)
+--- Forum: General Discussion (https://forum.jellyfin.org/f-general-discussion)
+--- Thread: Help with playlist script windows (/t-help-with-playlist-script-windows)



Help with playlist script windows - robyn - 2024-04-25

So far I have been able to get as far as generating an updated XML file in the playlists folder here

C:\ProgramData\Jellyfin\Server\data\playlists\<name of playlist>\playlist.xml

I can replace the file but nothing seems to update in jellyfin itself. If I update the playlist from within jellyfin it will overwrite the content of the file but I can't seem to update the other way around.
I have tried restarting the jellyfin service, and refreshing the metadata but nothing changes when I look at the playlist from the web interface.

Anyone have any suggestions on what to look at next to get jellyfin to reingest the file?


RE: Help with playlist script windows - TheDreadPirate - 2024-04-25

I can't answer your specific question other than stating that when I copied my main music playlist from my stable Jellyfin to unstable for testing, it didn't immediately show up with no explanation as for why. Then a couple days later I noticed that my playlist was there....again, no explanation.


RE: Help with playlist script windows - robyn - 2024-04-27

ended up abandoning updating the xml files it just wouldn't read the updates in. Decided to go a different route and wrote a script to make PLS files instead. Along the way I noticed these will break if you have any weird characters in your file names. I cleaned mine with advanced renamer. It will also break if you have non playable files (like album art) and have code to account for that.

save the text below as a file with the extension of .ps1 and run on the machine hosting your files. update the paths and playlist names. I now have this running as a daily scheduled task.

Code:
# Function to filter audio files
function Is-AudioFile {
    param ([string]$filePath)
    $audioExtensions = @(".mp3", ".wav", ".ogg", ".flac")  # Add more audio file extensions if needed
    $extension = [System.IO.Path]::GetExtension($filePath).ToLower()
    return $audioExtensions -contains $extension
}

# Define array of paths, playlist names, and destination folders
$pathsAndPlaylists = @(
    @{ Path = "D:\DATA\Music\Music\folder1"; PlaylistName = "folder1 "; Destination = "D:\DATA\Music\Music\Playlists" },
    @{ Path = "D:\DATA\Music\Music\folder2 "; PlaylistName = "folder2"; Destination = "D:\DATA\Music\Music\Playlists" },
    @{ Path = "D:\DATA\Music\Music\ folder3"; PlaylistName = "folder3"; Destination = "D:\DATA\Music\Music\Playlists" },
    @{ Path = "D:\DATA\Music\Music\ folder4"; PlaylistName = "folder4"; Destination = "D:\DATA\Music\Music\Playlists" },
    @{ Path = "D:\DATA\Music\Music\ folder5"; PlaylistName = "folder5"; Destination = "D:\DATA\Music\Music\Playlists" }

)


# Loop through each path, playlist name, and destination
foreach ($item in $pathsAndPlaylists) {
    $folderPath = $item.Path
    $playlistName = $item.PlaylistName
    $destinationFolder = $item.Destination

    # Check if the folder exists
    if (-not (Test-Path $folderPath -PathType Container)) {
        Write-Host "Folder '$folderPath' doesn't exist. Skipping."
        continue
    }

    # Get all audio files in the folder and its subfolders
    $filePaths = Get-ChildItem -Path $folderPath -File -Recurse | Where-Object { Is-AudioFile $_.FullName } | Select-Object -ExpandProperty FullName

    # Check if there are any audio files
    if ($filePaths.Count -eq 0) {
        Write-Host "No audio files found in folder '$folderPath'. Skipping."
        continue
    }

    # Create PLS playlist content
    $playlistContent = "[playlist]`n"
    foreach ($filePath in $filePaths) {
        $entry = "File" + ($filePaths.IndexOf($filePath) + 1) + "=" + $filePath
        $playlistContent += $entry + "`n"
    }
    $playlistContent += "NumberOfEntries=" + $filePaths.Count + "`nVersion=2"

    # Determine the playlist file path
    $playlistFilePath = Join-Path -Path $destinationFolder -ChildPath ($playlistName + ".pls")

    # Save playlist to file
    Set-Content -Path $playlistFilePath -Value $playlistContent -Encoding UTF8

    Write-Host "Playlist '$playlistName' has been created at $playlistFilePath"
}