Part 2
--------------
$Script:TrackErr = 0
$Changes = 0
$LstChanges = 0
$TracksChanged = 0
$LstLocation = $Null
$Trackstat_ItemsCount = 0
Msg "Checking for deltas with iTunes ..."
foreach ($Trackstat_Item in $Trackstat_Items) { # Loop over
Trackstat items
$Trackstat_ItemsCount += 1
if (Test-Path -LiteralPath $Trackstat_Item.location) { #
File exists at Trackstat Location
$Index = $Null
$Index = $HashTable[$Trackstat_Item.location]
If ($Index) {
$Itunes_Track = $Null
$Itunes_Track = $Itunes_Tracks[$Index] # Get the
iTunes ComObject Track from hash
if ($Itunes_Track) {
if ($Trackstat_Item.title -eq
$Itunes_Track.Name) {
if ($Trackstat_Item.change -eq 'rated') { #
rated
if ($Itunes_Track.Rating -ne
[int]$Trackstat_Item.rating) {
Msg "[$($Trackstat_Item.location)]
Rating change from [$($Itunes_Track.Rating)] to
[$([int]$Trackstat_Item.rating)]" $True 'DarkCyan'
if (-not $debug) {
$Itunes_Track.Rating = [int]$Trackstat_Item.rating }
$Changes += 1
} # rating changed
} # change is 'rated'
elseif ($Trackstat_Item.change -eq 'played')
{ # played
$PlayedDate =
([Datetime]::ParseExact($Trackstat_Item.playedDate, 'yyyyMMddHHmmss',
$null))
if ($PlayedDate -gt
($Itunes_Track.PlayedDate.AddHours(2))) { # PlayedDate TrackStat >
iTunes
# PlayedDate
Msg "[$($Trackstat_Item.location)]
PlayedDate change from [$($Itunes_Track.PlayedDate.ToString())] to
[$($PlayedDate.ToString())]" $True 'DarkCyan'
if (-not $debug) {
$Itunes_Track.PlayedDate = $PlayedDate.AddHours(-2) } # Dont now why
this is necessary, Timezone Germany
$Changes += 1
# Unplayed
if ($Itunes_Track.Unplayed) {
if (-not $debug) {
$Itunes_Track.Unplayed = $False }
Msg
"[$($Trackstat_Item.location)] Unplayed set to false, is:
[$($Itunes_Track.Unplayed)]" $True 'DarkCyan'
$Changes += 1
} # iTunes Unplayed
# PlayedCount
if ([int]$Trackstat_Item.PlayedCount
-gt 0) { # PlayedCount mit übergeben
if ($Itunes_Track.PlayedCount) {
# iTunes has PlayedCount
if
([int]$Trackstat_Item.PlayedCount -gt $Itunes_Track.PlayedCount) {
Msg
"[$($Trackstat_Item.location)] PlayedCount change from
[$($Itunes_Track.PlayedCount)] to [$([int]$Itunes_Track.PlayedCount)]"
$True 'DarkCyan'
if (-not $debug) {
$Itunes_Track.PlayedCount = [int]$Trackstat_Item.playedCount }
$Changes += 1
} # iTunes has PlayedCount
else { # iTunes has no
PlayedCount
if (-not $debug) {
$Itunes_Track.PlayedCount = 1 }
Msg
"[$($Trackstat_Item.location)] PlayedCount set to 1, is:
[$($Itunes_Track.PlayedCount)]" $True 'DarkCyan'
$Changes += 1
} # iTunes has no PlayedCount
} # Trackstat counts more played
than iTunes
} # Trackstat delivers PlayedCount >
0
else { # Trackstat do not deliver
PlayedCount > 0
if ($Itunes_Track.PlayedCount) {
# iTunes hat PlayedCount > 0
Msg
"[$($Trackstat_Item.location)] PlayedCount increment from
[$($Itunes_Track.PlayedCount)] to [$($Itunes_Track.PlayedCount+1)]"
$True 'DarkCyan'
if (-not $debug) {
$Itunes_Track.PlayedCount = $Itunes_Track.PlayedCount+1 }
$Changes += 1
} # iTunes hat PlayedCount > 0
else { # iTunes hat kein
PlayedCount > 0
if (-not $debug) {
$Itunes_Track.PlayedCount = 1 }
Msg
"[$($Trackstat_Item.location)] PlayedCount set to 1, is:
[$($Itunes_Track.PlayedCount)]" $True 'DarkCyan'
$Changes += 1
} # iTunes has no PlayCount > 0
} # Trackstat do not deliver
PlayedCount > 0
} # TrackStat Playeddate is newer then
iTunes PlayedDate
} # Change is 'played'
else {
Msg "Unknown Change Type:
[$($Trackstat_Item.change)]" $True 'Red'
$Script:TrackErr += 1
}
} # Title match
else {
Msg "Title Mismach on Track
[$($Trackstat_Item.location)] Trackstst:[$($Trackstat_Item.title)]
iTunes:[$($Itunes_Track.Name))]" $True 'Red'
$Script:TrackErr += 1
}
} # Found Track Location in HashTable
else {
Msg "iTunes Track with Index [$index] not found:
[$($Trackstat_Item.location)]" $True 'Red'
$Script:TrackErr += 1
}
} # Index ok
elseif (
$Trackstat_Item.location.StartsWith($ItunesMediaFolder,'CurrentCultureIgnoreCase')
) {
Msg "[$($Trackstat_Item.location)] not found in
iTunes Hashtable" $True 'Red'
$Script:TrackErr += 1
} # File in ItunesMediaFolder but not Indexed
else { # File not indexed and but not in
ItunesMediaFolder
Msg "[$($Trackstat_Item.location)] not in iTunes
iTunesMediaFolder, ignored." $False 'Yellow'
} # File not indexed and but not in ItunesMediaFolder
} # File exists at Trackstat Location
else {
Msg "Cannot find File at Trackstat Location:
[$($Trackstat_Item.location)]" $True 'Red'
$Script:TrackErr += 1
}
# Some Statistics
if (($Changes -gt $LstChanges) -and
($Trackstat_Item.location -ne $LstLocation )){
$TracksChanged += 1
if ( ($TracksChanged % 3000) -eq 0 ) { # Alle 3000
Tracks eine Pause machen, damit iTunes wegschreiben kann, Fehler traten
ab ca. 5000 auf.
msg "Sleeping for 60 s (every 3000 tracks changed)
for giving iTunes a chance to save Changes ..."
sleep 60
}# Alle 3000 Änderungen eine Pause machen, damit iTunes
wegschreiben kann, Fehler traten ab ca. 5000 auf.
} # New Track
$LstLocation = $Trackstat_Item.location
$LstChanges = $Changes
} # Loop over Trackstat items
Msg "Finished syncing $Trackstat_ItemsCount Trackstat Items.
$Changes Changes on $TracksChanged Tracks to iTunes, $Script:TrackErr
Track-Error(s)."
#if ((-not $debug) -and (-not $Script:TrackErr)) {
if (-not ($debug -and $Script:TrackErr)) {
msg "Removing $iTunes_Update_file"
Remove-Item "$iTunes_Update_file"
} # Import File löschen außer Debug und kein Fehler aufgetreten
# Save change Date of iTunes Library
$global:LstHTtime = (Get-Date).AddMinutes(1) #(Get-Item
$iTunes.LibraryXMLPath).LastWriteTime
Msg "HashTable Timestamp set to
$($global:LstHTtime.ToString())"
<#
if (-not $Script:TrackErr -and (Test-Path -LiteralPath
$TrackStat_Workfilename)) {
Msg "Remove $TrackStat_Workfilename"
Remove-item $TrackStat_Workfilename
} # cleanup
#>
Msg "Disposing iTunes ComObject"
$null =
[System.Runtime.InteropServices.Marshal]::ReleaseComObject([System.__ComObject]$itunes)
[gc]::Collect()
Remove-Variable itunes
} # Something todo, Trackstat -> iTunes File exists
#else {Msg "No Change"}
} until (-not $Loop -or $debug) # Loop
Msg "$ScriptName finished." $True
------------------------
EO Part 2
------------------------------------------------------------------------
Aki7's Profile: http://forums.slimdevices.com/member.php?userid=67596
View this thread: http://forums.slimdevices.com/showthread.php?t=93450
_______________________________________________
plugins mailing list
[email protected]
http://lists.slimdevices.com/mailman/listinfo/plugins