# iTunes Mark Albums Complete. # 2011-03-01, copyright avocadia@gmail.com # This work is offered without warranty. If you use it and it fucks up anything whatsoever, it's your own stupid fault for not having backups. # Use backups. Remember Coding Horror! # This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License for a period of fourteen years. # On 2025-03-01, this work will become public domain require 'win32ole' itunes = WIN32OLE.new('iTunes.Application') library = itunes.LibraryPlaylist is_marked_complete = /svAlbumComplete/ completed_album_flag = 'svAlbumComplete' songs = [] for track in library.Tracks track.Comment = track.Comment.gsub(is_marked_complete, '') if track.Comment =~ is_marked_complete songs << track end filter_albums_in = %('Unknown') << '' songs.reject! do |s| s.TrackCount == '' || filter_albums_in.include?(s.Album) || s.Podcast || s.VideoKind != 0 # VideoKindNone == 0, i.e. not a movie, tv show or music video end albums = songs.inject({}) do |memo, s| key = "#{s.Album}:#{s.Artist}" memo[key] ||= {'album'=>s.Album, 'artist'=>s.Artist, 'totaltracks'=>s.TrackCount, 'tracks' => []} memo[key]['tracks'] << s memo end albums.reject! do |k,v| v['totaltracks'] != v['tracks'].length end albums.each do|k,v| v['tracks'].each do |s| s.Comment += completed_album_flag unless s.Comment =~ is_marked_complete end end