Last active
July 20, 2021 09:38
-
-
Save mikan-megane/74a7cd7cb03a01751c5e0b1eb9444c12 to your computer and use it in GitHub Desktop.
プレイリスト名をコメントに入れる奴 for windows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Write-Progress -Id 1 -Activity "iTunes起動中・・・" | |
$iTunes = New-Object -comObject iTunes.Application | |
$Comments = @{} | |
$Tracks = $iTunes.LibraryPlaylist.Tracks | |
Write-Progress -Id 1 -Activity "コメント取得中" -Status "3/1" -PercentComplete (1 / 3 * 100) | |
$max = $Tracks.Count | |
$i = 0 | |
foreach ($track in $Tracks) { | |
Write-Progress -Id 2 -Activity $track.Name -Status "$max/$i" -PercentComplete (++$i / $max * 100) | |
$Comments[$track.TrackDatabaseID] = ($track.Comment -replace '(\r\n|\n|\r)*\$\$PlayList\$\$(.|\r\n|\n|\r)*$',"") + "`r`n" + '$$PlayList$$' | |
} | |
$Playlists = @() | |
foreach($playlist in $iTunes.Sources[1].Playlists) { | |
if ($playlist.SpecialKind -eq 0) { | |
$Playlists += $playlist | |
} | |
} | |
function getPlaylistName { | |
param ( $playlist ) | |
if ($playlist.Parent) { | |
return (getPlaylistName -playlist $playlist.Parent) + "/" + $playlist.name | |
} else { | |
return $playlist.name | |
} | |
} | |
Write-Progress -Id 1 -Activity "プレイリスト取得中" -Status "3/2" -PercentComplete (2 / 3 * 100) | |
$maxP = $Playlists.Count | |
$p = 0 | |
foreach ($playlist in $Playlists) { | |
$playlistName = getPlaylistName -playlist $playlist | |
$max = $playlist.Tracks.Count | |
$i = 0 | |
Write-Progress -Id 2 -Activity $playlistName -Status "$maxP/$p" -PercentComplete (++$p / $maxP * 100) | |
foreach ($track in $playlist.Tracks) { | |
Write-Progress -Id 3 -Activity $track.Name -Status "$max/$i" -PercentComplete (++$i / $max * 100) | |
if ($Comments.ContainsKey($track.TrackDatabaseID)) { | |
$Comments[$track.TrackDatabaseID] += "`r`n" + $playlistName | |
} | |
} | |
} | |
Write-Progress -Id 3 -Activity "end" -Complete | |
Write-Progress -Id 1 -Activity "コメント書き込み中" -Status "3/3" -PercentComplete (3 / 3 * 100) | |
$ErrorCount = 0 | |
$max = $Tracks.Count | |
$i = 0 | |
foreach ($track in $Tracks) { | |
try { | |
Write-Progress -Id 2 -Activity $track.Name -Status "$max/$i" -PercentComplete (++$i / $max * 100) -CurrentOperation "ErrorCount $ErrorCount" | |
if ($Comments[$track.TrackDatabaseID] -ne $track.Comment) { | |
$track.Comment = $Comments[$track.TrackDatabaseID] | |
} | |
} catch { | |
$ErrorCount++ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
macOS用はこちら