Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#
- file named - Itunes_Disable-AlbumAutoRating.ps1
- *****
- since there is NO WAY to disable album auto-rating in itunes, this script takes
- advantage of the way ratings are represented.
- - no stars = 0
- - one star = 20
- - two stars = 40
- - three stars = 60
- - four stars = 80
- - five stars = 100
- a side effect of the above is that a rating of 1 is treated as a rating of "no stars" in the
- rating and album-rating tests for smart playlists.
- it also disables the album auto-rating function which only acts on items that have not
- been manually rated.
- *****
- currently runs 1000 tracks in ~ 10 minutes if they all need to be changed.
- currently runs 1000 tracks in ~ 5 seconds if none need to be changed.
- that seems to be fast enuf to auto-run weekly with task scheduler.
- #>
- # function list start
- # set powershell window title
- function SetWindowTitle([String]$text)
- {
- $Host.UI.RawUI.WindowTitle = $text
- }
- # function list end
- $StartTime = Get-Date
- SetWindowTitle($myinvocation.mycommand.name)
- $ItunesAlreadyRunning = (Get-Process | Where-Object {$_.ProcessName -eq "iTunes"}) -match "iTunes"
- $iTunesApp = New-Object -comObject iTunes.Application
- $iMainLibrary = $iTunesApp.LibraryPlaylist
- $iTracks = $iMainLibrary.Tracks
- $NumTracks = $iTracks.Count
- # if you use AlbumRating, then swap these two items
- $UseAlbumRating = $False
- #$UseAlbumRating = $True
- # if the album rating was manually set, then AlbumRatingKind = 0
- $AlbumRatingSetAutomatically = 1
- # itunes no longer uses "1" to represent ONLY the audio file "kind".
- # - that also is used for books and possibly other file "kind" info.
- # - switched to using "KindAsString" instead of "Kind" value for media type test.
- # - possible values seem to be "AAC audio file", "Protected AAC audio file", and "MPEG audio file".
- # - they all seem to contain "audio file" and that is what is tested for.
- # - i say "seem to" because all of my tracks are MPEG files, so i can't test for other types.
- $AudioTrackType = "*audio file"
- $LogFile = -join ($Env:Temp, "\", $myinvocation.mycommand.name, "_", $StartTime.ToString("yyyy-MM-dd"), ".log")
- # swap these two when you wanna test just a few tracks
- #$x = 10
- $x = $NumTracks
- $ProcessedCount = 0
- $ChangedCount = 0
- while($x -gt 0)
- {
- $ProcessedCount ++
- $iCurrentItem = $iTracks.Item($x)
- Write-Output ("track index = {0,6:N0} of {1,6:N0}" -f $x, $NumTracks)
- if(($iCurrentItem.KindAsString -like $AudioTrackType) -and (
- (($UseAlbumRating -eq $True) -and ($iCurrentItem.AlbumRatingKind -eq $AlbumRatingSetAutomatically)) -or (
- ($UseAlbumRating -eq $False) -and ($iCurrentItem.AlbumRating -gt 1)))
- )
- {
- $Location = $iCurrentItem.Location
- $OldAlbumRating = $iCurrentItem.AlbumRating
- $NewAlbumRating = $iCurrentItem.AlbumRating = 1
- $ChangedCount ++
- # show what was done
- Write-Output ("OLD track AlbumRating = $OldAlbumRating")
- Write-Output ("NEW track AlbumRating = $NewAlbumRating")
- Write-Output ("track location = $Location")
- Write-Output ("")
- }
- $x --
- }
- # if itunes was NOT already running
- # and itunes is NOT currently playing
- # then we started it and we are not using it, so shut it down
- if((-not $ItunesAlreadyRunning) -and ($itunesApp.Playerstate -eq "0"))
- {
- $iTunesApp.Quit()
- }
- $StopTime = Get-Date
- $TotalTime = $StopTime - $StartTime
- Add-Content -path $LogFile -value ("") -PassThru
- Add-Content -path $LogFile -value ("started at = $StartTime") -PassThru
- Add-Content -path $LogFile -value ("stopped at = $StopTime") -PassThru
- Add-Content -path $LogFile -value ("total time = $($TotalTime.ToString())") -PassThru
- Add-Content -path $LogFile -value ("processed = {0,6:N0}" -f $ProcessedCount) -PassThru
- Add-Content -path $LogFile -value ("changed = {0,6:N0}" -f $ChangedCount) -PassThru
- Add-Content -path $LogFile -value ("log file = $LogFile") -PassThru
- Add-Content -path $LogFile -value ("") -PassThru
- # delay so the final output block can be read
- Write-Output ("Pausing for 30 seconds ...")
- Start-Sleep -Seconds 30
Add Comment
Please, Sign In to add comment