Sunday, July 22, 2012

How to removed broken files "!" (Exclamation) from itunes (with iTunes match)

I needed some free hard drive space the other day and started deleting stuff. I backed up my photos to another drive and started deleting folders. My documents are all backed up on google drive so the only thing on my computer is video games and music. I bought iTunes match so all my music is in the cloud right? Well sort of.

I deleted a few folders that I thought where backed up and copied to my music when I imported them into iTunes but I was mistaken. 

Thankfully my second backup was in place I had the files in iTunes match. The problem is iTunes won't mark them as not downloaded it simply marks them as broken.

I had 9700 missing song.

I found this: http://www.makeuseof.com/tag/effectively-remove-duplicate-tracks-itunes-windows as none of the other playlist hacks worked.

Near the bottom it references a script that will delete all the broken files. The problem is that with iTunes match it asks me every time if I want to delete it from iTunes match also (No I do not).  Animated popup, hitting enter to confirm , repeat 9700 times.  No thank you I'd need to buy a new keyboard by the time I was done.

So I got hacking. It turns out iTunes has a decent api that seems to be terribly if at all documented.

The best documentation I could find was a wonderful script for generating stats on your itunes library http://www.yanoff.org/music/iTunesStats.shtml. I from there I found I could locate and update the rating on a song in my iTunes library.

So I tweaked the apple provided script. to change the line currTrack.Delete();  To currTrack.Rating = 20;

This gives every broken song a rating of 1 star. It also took about 20 minutes.

Now I just have to go into iTunes. Sort by rating and select the 1 star songs and delete them all with a single button press.

Once you've deleted the songs you can select all and right click to re-download them. I was unable to download many of the songs (thank you iTunes match for sucking) and My ISP probably hates me for downloading 10,000 songs (I was missing a few for other reasons) but what's 40 GB between friends.

Of note I never rate songs 1 star. If I dislike a song that much I'll just delete the song completely.

The original source of the script is in the examples folder in the SDK download https://connect.apple.com/cgi-bin/WebObjects/MemberSite.woa/wa/getSoftware?bundleID=20139 You might need to be a developer to download that but I like to share my sources.

Script starts here, copy this into a .js file and double click it in windows:


/*
    File: RemoveDeadTracks.js
   
    Version: 1.0

    Disclaimer: IMPORTANT:  This Apple software is supplied to you by Apple Computer, Inc.
                ("Apple") in consideration of your agreement to the following terms, and your
                use, installation, modification or redistribution of this Apple software
                constitutes acceptance of these terms.  If you do not agree with these terms,
                please do not use, install, modify or redistribute this Apple software.

                In consideration of your agreement to abide by the following terms, and subject
                to these terms, Apple grants you a personal, non-exclusive license, under AppleÕs
                copyrights in this original Apple software (the "Apple Software"), to use,
                reproduce, modify and redistribute the Apple Software, with or without
                modifications, in source and/or binary forms; provided that if you redistribute
                the Apple Software in its entirety and without modifications, you must retain
                this notice and the following text and disclaimers in all such redistributions of
                the Apple Software.  Neither the name, trademarks, service marks or logos of
                Apple Computer, Inc. may be used to endorse or promote products derived from the
                Apple Software without specific prior written permission from Apple.  Except as
                expressly stated in this notice, no other rights or licenses, express or implied,
                are granted by Apple herein, including but not limited to any patent rights that
                may be infringed by your derivative works or by other works in which the Apple
                Software may be incorporated.

                The Apple Software is provided by Apple on an "AS IS" basis.  APPLE MAKES NO
                WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
                WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
                PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
                COMBINATION WITH YOUR PRODUCTS.

                IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
                CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
                GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
                OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
                (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
                ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

    Copyright © 2004 Apple Computer, Inc., All Rights Reserved
*/


var ITTrackKindFile = 1;
var iTunesApp = WScript.CreateObject("iTunes.Application");
var deletedTracks = 0;
var mainLibrary = iTunesApp.LibraryPlaylist;
var tracks = mainLibrary.Tracks;
var numTracks = tracks.Count;
var i;

while (numTracks != 0)
{
var currTrack = tracks.Item(numTracks);

// is this a file track?
if (currTrack.Kind == ITTrackKindFile)
{
// yes, does it have an empty location?
if (currTrack.Location == "")
{
// yes, delete it
//currTrack.Delete();
currTrack.Rating = 20;
deletedTracks++;
}
}

numTracks--;
}

if (deletedTracks > 0)
{
if (deletedTracks == 1)
{
WScript.Echo("Removed 1 dead track.");
}
else
{
WScript.Echo("Removed " + deletedTracks + " dead tracks.");
}
}
else
{
WScript.Echo("No dead tracks were found.");
}



3 comments:

  1. How to login into the casino in 2021
    Here worrione is how to do this: Step 1. 바카라 사이트 Go to the website. · Click on the “Login” link on the right-hand side. · https://vannienailor4166blog.blogspot.com/ Click on the “Login” button to enter a live chat number. 출장마사지 · https://tricktactoe.com/ Enter the

    ReplyDelete
  2. This is an actual alternative for voters to consider about|to contemplate} where slot machine income comes from. Also, since slot machines are probably the most addictive type of playing, Massachusetts voters should think about the supply of playing revenues, and whether slot machines are truthful to gamblers. “I’m seeing myself from behind,” he recalled, “and truly have} in my hand.” All through 1990, he’d been trying to find a approach to cheat https://vjtmxmzkwlsh.com/ the latest slot machines. He wanted model new} tool, one thing to replace the clumsy old instrument that had landed him in the penitentiary. Night and day in his Vegas house, he toiled on a Fortune One video poker machine. But it doesn't matter what} he tried, some riddle in the guts of the unit would thwart him.

    ReplyDelete