Created
May 20, 2012 18:53
-
-
Save timvw/2759128 to your computer and use it in GitHub Desktop.
Add missing books to iTunes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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