public static IEnumerable <string> GetFilesWithPerson(this string dir, PicasaPerson picasaPerson) { try { var picasaInis = Directory.EnumerateFiles(dir, @".picasa.ini", SearchOption.AllDirectories); return(picasaInis.SelectMany(ini => ini.WithPersonFromPicasaIni(picasaPerson))); } catch (Exception e) { Console.WriteLine("Error: {0}", e.Message); return(new String[0]); } }
private static bool HasPerson(string sec, ParsedIni parsedIni, PicasaPerson picasaPerson) { var facesValue = parsedIni.TryGetSetting(sec, "faces"); if (facesValue == null) { return(false); } var personIds = facesValue.Split(';') .SelectMany(pairs => pairs.Split(',').Skip(1).Take(1)); return(personIds.Intersect(picasaPerson.FocusIds).Any()); }
private static void Main(string[] args) { var srcDir = @"D:\Fotos"; var videoDestDir = @"D:\FotoMirrors\Videos"; var starredDestDir = @"D:\FotoMirrors\Starred"; var personDestDir = @"D:\FotoMirrors\People"; var persons = new[] { "Sjoerd de Boer", "Pieter de Boer", "Simon de Boer", "Mathijs de Boer", "Bart de Boer", "Maaike de Boer", "Anne-Riet de Boer", "Victoria Flutur", "Liviu Flutur", "Michaela Flutur", "Lorelei de Boer", "Sebbe de Boer", "Sophie de Boer", "Laura Candidatu", "Bogdan Flutur", "Célestine de Boer" }.ToObservable(); var personData = persons.Select( n => new { Name = n, Person = PicasaPerson.TryGetPerson(n), Path = Path.Combine(personDestDir, n) }) .Where(set => set.Person != null); var videoObservable = srcDir.ObserveFileSystem(videoAndThumbnailExtensions) .Select(Path.GetDirectoryName) .ThrottlePerValue(TimeSpan.FromSeconds(15)) .StartWith(srcDir); var picasaObservable = srcDir.ObserveFileSystem(".picasa.ini") .Select(Path.GetDirectoryName) .ThrottlePerValue(TimeSpan.FromSeconds(15)) .StartWith(srcDir).Publish(); var personDisposable = new CompositeDisposable(); personDisposable.Add(personData.Subscribe( on => personDisposable.Add(picasaObservable.Subscribe( pad => UpdateMirror(ini => ini.GetFilesWithPerson(on.Person), pad, on.Path, srcDir))))); using ( videoObservable.Subscribe( pad => UpdateMirror(CollectVideoCandidates, pad, videoDestDir, srcDir))) using ( picasaObservable.Subscribe( pad => UpdateMirror(CollectStarredCandidates, pad, starredDestDir, srcDir))) using (personDisposable) using (picasaObservable.Connect()) { while (!Console.KeyAvailable) { Thread.Sleep(100); } } }
private static IEnumerable <string> WithPersonFromPicasaIni(this string picasaIniPath, PicasaPerson picasaPerson) { var dir = Path.GetDirectoryName(picasaIniPath); try { var parsedIni = new ParsedIni(picasaIniPath); var filesInIni = parsedIni.EnumSections(); var filesWithPerson = filesInIni.Where(sec => HasPerson(sec, parsedIni, picasaPerson)); var fullPathsWithPerson = filesWithPerson.Select(fn => Path.Combine(dir, fn)); var existingPersonFiles = fullPathsWithPerson.Where(File.Exists).ToArray(); return(existingPersonFiles); //return !existingPersonFiles.Any() ? new String[0] : new[] { picasaIniPath }.Concat(existingPersonFiles); } catch (Exception e) { Console.Error.WriteLine("Failed to parse {0}: {1}", picasaIniPath, e); return(new string[0]); } }