From 99454a3c39621445de0718ec3f3d943249ded064 Mon Sep 17 00:00:00 2001 From: Nik Rozman Date: Wed, 7 May 2025 19:41:16 +0200 Subject: [PATCH] Add support for normal Spotify installs --- clear-spotify-cache.ps1 | 48 ++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/clear-spotify-cache.ps1 b/clear-spotify-cache.ps1 index 1070897..23057cd 100644 --- a/clear-spotify-cache.ps1 +++ b/clear-spotify-cache.ps1 @@ -1,27 +1,49 @@ # Description: This script fixes Spotify playlist caching issues. -# get spotify path - might be different, i installed thru ms store -$spotifyBasePath = Join-Path $env:LOCALAPPDATA "Packages\SpotifyAB.SpotifyMusic_zpdnekdrzrea0\LocalState\Spotify\Users" +# Define paths for both MS Store and regular installations +$msStorePath = Join-Path $env:LOCALAPPDATA "Packages\SpotifyAB.SpotifyMusic_zpdnekdrzrea0\LocalState\Spotify\Users" +$regularPath = Join-Path $env:APPDATA "Spotify\Users" -if (Test-Path $spotifyBasePath) { - # i had multiple users, loop thru all of them - $userDirs = Get-ChildItem -Path $spotifyBasePath -Directory -Filter "*-user" +$foundUsers = $false +# Check MS Store installation +if (Test-Path $msStorePath) { + Write-Host "Found Microsoft Store Spotify installation" + $userDirs = Get-ChildItem -Path $msStorePath -Directory -Filter "*-user" foreach ($userDir in $userDirs) { - # primary.ldb is a folder, not a file for some reason + $foundUsers = $true $ldbPath = Join-Path $userDir.FullName "primary.ldb" - if (Test-Path $ldbPath -PathType Container) { try { Remove-Item -Path $ldbPath -Recurse -Force - Write-Host "Deleted: $ldbPath" + Write-Host "✓ Cleared cache for user in: $($userDir.Name)" } catch { - Write-Warning "Failed to delete $ldbPath: $_" + Write-Warning "Failed to clear cache in $($userDir.Name): $_" } - } else { - Write-Host "No primary.ldb folder found at $ldbPath" } } -} else { - Write-Warning "Spotify user directory not found at $spotifyBasePath" +} + +# Check regular installation +if (Test-Path $regularPath) { + Write-Host "Found regular Spotify installation" + $userDirs = Get-ChildItem -Path $regularPath -Directory -Filter "*-user" + foreach ($userDir in $userDirs) { + $foundUsers = $true + $ldbPath = Join-Path $userDir.FullName "primary.ldb" + if (Test-Path $ldbPath -PathType Container) { + try { + Remove-Item -Path $ldbPath -Recurse -Force + Write-Host "✓ Cleared cache for user in: $($userDir.Name)" + } catch { + Write-Warning "Failed to clear cache in $($userDir.Name): $_" + } + } + } +} + +if (-not $foundUsers) { + Write-Warning "No Spotify users found in either location:`n- $msStorePath`n- $regularPath" +} else { + Write-Host "`nDone! Restart Spotify to rebuild the cache." }