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.

WimTiVoServer reasons for existence.

I had multiple reasons for writing this program.

I wanted to work with the XMLLite library for XML processing which Microsoft has included as part of their operating system for several years. http://msdn.microsoft.com/en-us/library/windows/desktop/ms752838(v=vs.85).aspx I’ve used XML as my data storage and transfer medium for years but most of the time have manually processed the XML as opposed to using a prebuilt library. My reasoning behind my own parsing and generation was that I was building cross platform solutions that ran on embedded systems working with windows programs. It was easier to build the same code to run on both platforms and assure compatibility than to deal with the overhead and maintenance of third party libraries. I’ve still not formed a full opinion on using the library for reading XML, but it certainly makes creating XML easier by making sure tags are properly closed and nested, and the option of auto indentation in the formatting is nice.

I wanted experience using FFMPEG and its associated video processing libraries. With the release of FFMPEG v1 late last year it became much more capable in dealing with all of the container formats and encoding types that I was interested in, including the WTV containers that Windows Media Center uses and the MKV containers that are common on the internet for high definition files. In my functioning version of my server, I’m using the libraries directly linked into the program to parse the media files for metadata, but spawning a full copy of FFMPEG to do the required transcoding to send the proper format to the TiVo. I’m considering migrating entirely to the spawned FFMPEG process to simplify licensing if I want to make my program publicly available. It would also simplify future support for codecs and containers that FFMPEG may support if my service itself didn’t need to be relinked with updated libraries.

I’ve been frustrated with the state of the TiVo Desktop software provided by the TiVo company. It was designed so that it plugs into the windows video codec stack for video transcoding, as well as the apple protocol stack for Bonjour protocol support. Both of those lead to complications when upgrading programs. Apple regularly releases updates to iTunes. Whenever an update to iTunes needed to be installed, it caused problems because the TiVo service was running and keeping some of the apple services locked in use. It essentially required a full uninstall and reinstall of iTunes every time I needed to update it, with several machine reboots in that process.  Somehow I’d managed to get a codec installed on my machine that allowed the TiVo desktop to support the MKV container. Duplicating that installation on a new machine or server was not something I wanted to attempt. Since the modern FFMPEG supports MKV, I get that support without manipulating a video codec stack in windows.

The TiVo Desktop software only runs as a user process, when a user is logged in. Files are not served from a background service. This is an issue when I’d like to run the process on a headless server. There are ways around the issue, but my program solves it simply by being a pure service. The TiVo Desktop both announces itself via the UDP beacon process on port 2190 and also listens for other servers on the same port. Because my program is purely a server I saw no reason to listen for incoming beacons, and so I do not tie up the UDP port for receiving. This allows secondary programs to be started at the users discretion to listen for TiVo processes on the network.