mirror of
https://github.com/SpotX-Official/SpotX.git
synced 2026-04-14 04:38:24 +10:00
- Fixed slow client startup if cache purge was set - Now there is a log file (Spotify/cache/log.txt) in which you can find information about the script to clear the cache. - A little code optimization
43 lines
1.7 KiB
PowerShell
43 lines
1.7 KiB
PowerShell
<#
|
||
Name: Clear Spotify Cache.
|
||
|
||
Description: The script clears outdated cache from the listened music in Spotify.
|
||
Fires every time you completely close the client (If the client was minimized to tray then the script will not work).
|
||
|
||
For the APPDATA\Spotify\Data folder, the rule is that all cache files that are not used
|
||
by the customer more than the specified number of days will be deleted.
|
||
|
||
#>
|
||
|
||
$day = 7 # Number of days after which the cache is considered stale
|
||
|
||
# Clear the \Data folder if it finds an outdated cache
|
||
|
||
try {
|
||
If (!(Test-Path -Path $env:LOCALAPPDATA\Spotify\Data)) {
|
||
"$(Get-Date -uformat ‘%D %T’) Folder Local\Spotify\Data not found" | Out-File log.txt -append
|
||
exit
|
||
}
|
||
$check = Get-ChildItem $env:LOCALAPPDATA\Spotify\Data -File -Recurse | Where-Object lastaccesstime -lt (get-date).AddDays(-$day)
|
||
if ($check.Length -ge 1) {
|
||
|
||
$count = $check
|
||
$sum = $count | Measure-Object -Property Length -sum
|
||
if ($sum.Sum -ge 104434441824) {
|
||
$gb = "{0:N2} Gb" -f (($check | Measure-Object Length -s).sum / 1Gb)
|
||
"$(Get-Date -uformat ‘%D %T’) Removed $gb obsolete cache" | Out-File log.txt -append
|
||
}
|
||
else {
|
||
$mb = "{0:N2} Mb" -f (($check | Measure-Object Length -s).sum / 1Mb)
|
||
"$(Get-Date -uformat ‘%D %T’) Removed $mb obsolete cache" | Out-File log.txt -append
|
||
}
|
||
Get-ChildItem $env:LOCALAPPDATA\Spotify\Data -File -Recurse | Where-Object lastaccesstime -lt (get-date).AddDays(-$day) | Remove-Item
|
||
}
|
||
if ($check.Length -lt 1) {
|
||
"$(Get-Date -uformat ‘%D %T’) Stale cache not found" | Out-File log.txt -append
|
||
}
|
||
}
|
||
catch {
|
||
"$(Get-Date -uformat ‘%D %T’) $error[0].Exception" | Out-File log.txt -append
|
||
}
|
||
exit |