2024-04-27, 12:07 AM
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.
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"
}