Wednesday, August 29, 2012

FileDater Update

At the beginning of this year I launched a utility called FileDater that would scan a folder and copy or move files based on the dates in the file names. Today I announce version 2.0 that extends the original with a few new commands. All of these commands work on the current set of objects so if called after a FILTER will work on the filtered set.

ONLY
Example: ONLY 10
This will take every 10th file

SKIP
Example: SKIP 10
This will skip every 10th file so if you have 100 files to start you will end up with 90.

RESET
Undoes all filtering. This is useful if you want to move all the files on Sundays to one folder and Saturdays to another.

INVERT
This inverts the selection for if you have selected all your weekend files to move someone you can invert it and grab all weekday file.


For more information see the original post on FileDater

Download FileDater

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.");
}



Friday, January 27, 2012

FileDater

File Dater is a utility for working with files that have the date in the filename such as log files or images automatically captured by a camera. It can preform a copy, a move or just display lists.

Example:

FileDater commands.fd

comands.fd is a file dater command file like:
FORMAT 'QRTRYWAY2_'yyyy-MM-dd_HH-mm'.jpg'
FOLDER C:\temp\QRTRWAY2\
AFTER 7:00
BEFORE 19:00
EXCLUDE dddd Saturday
EXCLUDE dddd Sunday
NEWER 70 days
OLDER 69 days
FILTER
SHOW
MOVE C:\temp\qtr4\ image Count
#comment

Each line of the file is processed one at a time to get the results you want. The first two lines are always FORMAT and FOLDER.

FORMAT FilenameFormat
This command establishes the format for the file you will be working with and example filename from above would have been QRTRYWAY2_2012-01-20_13-40.jpg

FOLDER Folder
This is your source folder.

AFTER DateTime
BEFORE DateTime
This will include or exclude files after a Date or Time. if DateTime only includes a time then it will use that as time of day so in the example above I am grabbing files furring the day from 7 am to 7 pm.

EXCLUDE DateFormatString value
This will exclude any files where the date formatted as per DateFormatString == value. In the above eexample this will exclude weekends but this could almost be used to exclude every file marked with the 3rd of  the month.

INCLUDE DateFormatString value
Similar to exclude but will exclude all files that don't match so this could be used to say only grab the file dates 5 minutes after the hour. Having more that one INCLUDE will return very few results you can't include Sunday and Saturday to get the weekend you need to EXCLUDE the entire work week.

NEWER TimeSpan
OLDER TimeSpan
This will exclude any files that are not dated newer than or older than a given date. In my example I'm looking for NEWER 70 days and OLDER 69 so I want all new files in the last 70 days that are atleast 69 days old. This gives me 24 hours worth of files. A use for this is to find the newest files and copy them somewhere or find old files like log files over a month old and move them somewhere. You could setup a script to move old log files to a folder then zip it up.

FILTER
This will preform all the above operations on every found file.

SHOW Optional Format String
This will show the files found. It will show the new filename, so if you call this before a copy you get the original file name, after you get the new file names. A format string is separated by spaces and can contain the following keywords "Count",  the number for the file in the result set, OriginalFilename, NewFilename. You can also include a % followed immediately by and date format string.  The above file names could be recreated as "QRTRYWAY2_ yyyy-MM-dd_HH-mm .jpg to print the file name, almost. All options are spaced apart so you would get QRTRYWAY2_ 2012-01-20_13-40 .jpg.

COPY DestinationFolder format
MOVE DestinationFolder format
Copies or moves the resulting files to a destination folder. This could be the same folder with a different file name structure. This way you can use Move like a copy. Warning: Copy and move will replace any files in the target location that have matching names without warning you. The example line "MOVE C:\temp\qtr4\ image Count" will move all the matched filed to a new folder and rename then to image0001.jpg for example. The number of digits in Count is based on how big the result set is but is always fixed length. This is useful if you later want to sort the file by name. File extensions are preserved.

Please note the application does very little error checking and might just crash. If you have questions or requested feature please let me know.

Download