Skip to content

Instantly share code, notes, and snippets.

@timvw
Created May 20, 2012 18:53
Show Gist options
  • Save timvw/2759128 to your computer and use it in GitHub Desktop.
Save timvw/2759128 to your computer and use it in GitHub Desktop.
Add missing books to iTunes
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using iTunesLib;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
AddMissingBooksToItunes();
}
private static void AddMissingBooksToItunes()
{
var app = new iTunesApp();
foreach (var missingBook in AvailableBooksNotInItunes())
{
app.LibraryPlaylist.AddFile(missingBook);
}
}
private static IEnumerable<string> BooksInItunes()
{
var app = new iTunesApp();
return app.LibraryPlaylist.Tracks
.OfType<IITFileOrCDTrack>()
.Where(track => track.Location.EndsWith("*.pdf"))
.Select(track => track.Location);
}
private static string[] AvailbleBooks()
{
return Directory.GetFiles(@"C:\Users\timvw\Dropbox\ebooks", "*.pdf");
}
private static IEnumerable<string> AvailableBooksNotInItunes()
{
var availableBooks = AvailbleBooks();
var booksInItunes = BooksInItunes().ToArray();
return availableBooks.Where(book => !booksInItunes.Contains(book));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment