iTunes, Microsoft Store, COM Interface Type Library

Several years ago I’d written a program to manipulate data in the iTunes library using the approved Apple COM API. Part of the way this works in a C program is to include a type library in the headers defining all of the function calls. When iTunes is installed in the traditional way, Apple embedded the type library in the executable, and the executable was installed in a traditional location.

#import "C:/Program Files (x86)/iTunes/iTunes.exe"
using namespace iTunesLib;

With the installation of iTunes from the Microsoft store, the iTunes executable no longer lives in that location. Today my application builds properly with the following import command, but it may change mysteriously with version changes and automatic updates via the store.

#import "C:/Program Files/WindowsApps/AppleInc.iTunes_12093.3.37141.0_x64__nzyj5cx40ttqa/iTunes.exe"
using namespace iTunesLib;

My program builds and runs more reliably than it used to, which I’m assuming is in part due to the fact that I appear to now be using a 64 bit version of iTunes, and all the extra work Apple put in to make iTunes more reliable on windows in general.

Finding the iTunes application itself was the hardest part of the transition. I’m happy the API still exists because Apple no longer hosts easy access to the documentation for the API, and http://www.joshkunz.com/iTunesControl/ seems to be the most complete and searchable information.

Advertisements

iTunes, Microsoft Store, Microsoft Surface

Last year, Apple finally worked enough with Microsoft to get the iTunes program for windows available in the Microsoft Online Store. I’d always had problems with upgrading iTunes in windows in the past, requiring me to completely uninstall, reboot, and install the new version each time I wanted to upgrade. Often I had to not just uninstall iTunes, but search for other helper programs that Apple might have installed and uninstall them before rebooting.¬† I did the complete uninstall before I installed the version from the Microsoft store. Since that time, iTunes has almost magically been up to date on my desktop computer. The Microsoft store updates seem to get installed in downtime on my computer and everything just works.

I’m stuck in my ways a bit as far as music goes. I’ve get a large ripped CD collection, that I keep the originals all in a set of binders including the original paper inserts. My iPhone has 256GB of storage, more than half of which is my music.

I’ve kept my iPhone synchronized with my desktop computer because of the storage requirements of all of the music in the past, but at times have wished I was synchronizing with my Microsoft Surface Pro 4 tablet that I travel with, and use just as much as my desktop. My Surface has 256GB of storage in the internal SSD, and I’ve been using a 256GB micro sd card in the accessible storage slot for the past couple of years. That’s good for movies while traveling, but I didn’t want to allocate over half the space to iTunes.

2019-03-11

The falling price of flash cards recently convinced me to buy a new 512GB flash card to leave in the Surface. I was able to get all of my music transferred over to the SD card and iTunes installed from the Microsoft Store with very little impact on the internal storage on my Surface. I followed the Apple support ducument and had a few issues because my library had never been consolidated from my early MP3 ripping days.

I’ve been running my Surface SSD with between 50 and 70GB free, which from what I’ve read about SSD usage is good for both lifespan and performance. The iTunes directory on my micro SD card consists of 24,169 files and 137,859,861,360 bytes according to a simple dir /s command.

All was looking good until I got around to connecting my iPhone to the new machine and telling it to backup on the new machine. The backup completed correctly, but I then found out that it had used up all the free space on my internal SSD and I was now down to less than 3GB free space.

A quick search on the web led me to this page explaining how to relocate the backups to an external drive in windows. That seemed good, until I realized that the directory described does not exist on my machine. One more change that seems to have happened to iTunes locations in the Microsoft Store move. A search on my machine led me to find the MobileSync directory in my user profile directory. I used robocopy to move the backup directory to an appropriate directory on my flash card, which took a while because it consisted of 58,623 files and 77,743,703,474 bytes. I then created a directory junction from the SSD location to the flash location.

robocopy /COPYALL /E /MOVE C:\Users\Wim\Apple\MobileSync\Backup D:\Wim\Apple\MobileSync\Backup
mklink /J C:\Users\Wim\Apple\MobileSync\Backup D:\Wim\Apple\MobileSync\Backup

After all that had completed I started iTunes and connected my phone, initiating another backup. Everything now appears to be working properly, with iTunes storing both it’s library and device backups on my secondary storage device.

The only drawback I’ve currently run into is that I use Windows Server Essentials 2016 as a home server and it’s device backup feature to backup my machine for emergency file recovery. The microsd card is recognized as removable media, and the backup software doesn’t easily let me include it in the regular backup strategy.

Odd Wildcard Matching in Windows 10

I recently ran into an odd behavior of more files matching a pattern than I expected. I’d used exiftool to modify the dates on files my GoPro produced. It creates backup files of the original images when it modifies the tags. Here’s the command I ran.

exiftool.exe -r "-AllDates+=4:7:6 17:40:00" -ext jpg f:\GoPro\20170807

Now I had about 4000 files with the .JPG extension and another 4000 files with a .JPG_original extension.

I ran my program that parses the directory structure and turns all those images into a time lapse movie, and it seemed to be including both the file extensions, making a very disjointed movie.

I loaded my source code in the debugger and it seemed to be doing a findfirst / findnext specifically looking for .JPG files, and not some other extension, but it was definitely retrieving files both with .JPG and .JPG_original extensions.

I then ran a couple of commands at the windows command prompt and was surprised to find the same results there.

dir F:\GoPro\20170807\372GOPRO\G*.JPG /p
dir F:\GoPro\20170807\372GOPRO\G???????.JPG /p

Each command returned both the JPG and JPG_original files.

dir F:\GoPro\20170807\372GOPRO\G*.JPG_original /p

returned just the JPG_original files.

dir F:\GoPro\20170807\372GOPRO\G??????.JPG /p

had one less question mark and correctly returned no files.

This is all unexpected behavior, though I’m glad to see that it was consistent with the operating system and not something specific to the C runtime. I’d love an explanation of what’s going on.

exiftool to manage DJI media files

DJI Drones don’t seem to remember the image count between formats of a media card. This creates a problem for me when I’m trying to backup and maintain my images and video.

Because the dates are all correct in the media files, retrieved from GPS data, organizing the files by naming them based on the date works for me.

Using ExifTool by Phil Harvey is a great solution for pulling the metadata from the files and renaming the files.

The command line that I was initially using is:

exiftool "-FileName<${CreateDate}.$filetype" -d %Y%m%d-%H%M%S%%-c -ext mp4 -ext dng -ext jpg dji*

It’s problem is that it orphans the SRT subtitle files from my videos that I’d like to keep matching the video files.

I’ve tried this variation to do it in one step but it doesn’t work, because the SRT files get renamed as MP4 files.

exiftool -verbose "-FileName<${CreateDate}" -d %Y%m%d-%H%M%S%%-c.%%le -ext mp4 -ext dng -ext jpg dji* -srcfile %f.srt

If anyone has a suggestion for how to rename all the media files in one directory I’d appreciate it. Even running two commands in sequence would be fine.

Update:

I’ve figured out that running these two commands in sequence will get me the results I am looking for:

exiftool "-FileName<${CreateDate}" -d %Y%m%d-%H%M%S%%-c.srt -ext mp4 -srcfile %f.srt dji*
exiftool "-FileName<${CreateDate}" -d %Y%m%d-%H%M%S%%-c.%%le -ext mp4 -ext dng -ext jpg dji*

I’m still looking for a way of doing it in a single command that may leave less room for error, but this is working for now.

Media Center Content Protection Error

I’ve noticed that I sometimes get errors in windows media center reporting that programs could not be recorded. This generally happens when I’ve left media center running full screen on one of my monitors overnight…

MediaCenterErrorThe strange thing is that if the media center application is not running, or is running in a window, the recording of the programs seems to work properly. I only get these errors coming up when the application is full screen on one of my monitors.