static void ReadFileImage(iTunesAlbum folder, iTunesSong song) { if (folder.HasImage) { return; } string uncFilePath = GetUncFileName(song.Path); string folderPath = ResolveImage(uncFilePath, "folder", false); if (System.IO.File.Exists(folderPath)) { folder.PrimaryImagePath = folderPath; } string backPath = ResolveImage(uncFilePath, "backdrop", true); if (System.IO.File.Exists(backPath)) { folder.BackdropImagePath = backPath; } backPath = ResolveImage(Directory.GetParent(Path.GetDirectoryName(uncFilePath)).FullName, "backdrop", false); if (System.IO.File.Exists(backPath)) { if (folder.Parent != null) { folder.Parent.BackdropImagePath = backPath; } } }
private static iTunesSong BuildSong(iTunesArtist childArtistFolder, iTunesAlbum childAlbumFolder, Dictionary <string, string> data) { iTunesSong newSong = new iTunesSong(); newSong.SongName = data["Name"]; newSong.Name = data["Name"]; newSong.Path = GetUncFileName(data["Location"]); newSong.Id = newSong.Path.GetMD5(); childAlbumFolder.Songs.Add(newSong); childAlbumFolder.Parent = childArtistFolder; return(newSong); }
private static iTunesAlbum BuildAlbum(Dictionary <string, iTunesAlbum> dictionaryAlbum, iTunesArtist childArtistFolder, Dictionary <string, string> data) { iTunesAlbum childAlbumFolder; if (dictionaryAlbum.ContainsKey(string.Concat(data["Artist"], data["Album"]))) { childAlbumFolder = dictionaryAlbum[string.Concat(data["Artist"], data["Album"])]; } else { childAlbumFolder = new iTunesAlbum(); childAlbumFolder.Name = data["Album"]; childAlbumFolder.AlbumName = data["Album"]; childAlbumFolder.Id = string.Concat(data["Artist"], data["Album"]).GetMD5(); childArtistFolder.Albums.Add(childAlbumFolder); childAlbumFolder.Parent = childArtistFolder; dictionaryAlbum.Add(string.Concat(data["Artist"], data["Album"]), childAlbumFolder); } return(childAlbumFolder); }
public static iTunesMusicLibrary GetDetailsFromXml(iTunesMusicLibrary existingLibrary) { string path = Settings.Instance.iTunesLibraryXMLPath; if (!File.Exists(path)) { throw new FileNotFoundException("iTunesLibraryXMLPath " + path + " not found!"); } XPathDocument doc = new XPathDocument(path); XPathNavigator nav = doc.CreateNavigator(); // Move to plist, then master library and tracks nav.MoveToChild("plist", ""); nav.MoveToChild("dict", ""); nav.MoveToChild("dict", ""); Dictionary <string, iTunesArtist> dictionaryArtist = new Dictionary <string, iTunesArtist>(); Dictionary <string, iTunesAlbum> dictionaryAlbum = new Dictionary <string, iTunesAlbum>(); Dictionary <string, iTunesAlbum> dictionaryUniqueAlbum = new Dictionary <string, iTunesAlbum>(); Dictionary <string, iTunesGenre> dictionaryGenre = new Dictionary <string, iTunesGenre>(); iTunesArtist childArtistFolder; iTunesAlbum childAlbumFolder; iTunesGenre childGenreFolder = null; iTunesAlbum childUniqueAlbumFolder; // Move to first track info bool success = nav.MoveToChild("dict", ""); //int count = 0; // Read each song until we have enough or no more iTunesMusicLibrary folder; if (existingLibrary == null) { folder = new iTunesMusicLibrary(); } else { folder = existingLibrary; ClearCache(folder); } folder.LastUpdate = DateTime.Now; while (success) { success = nav.MoveToFirstChild(); // Read each piece of information about the song Dictionary <string, string> data = new Dictionary <string, string>(); while (success) { string key = nav.Value; nav.MoveToNext(); data[key] = nav.Value; success = nav.MoveToNext(); } if (!data.ContainsKey("Name")) { data.Add("Name", ""); } if (!data.ContainsKey("Artist")) { data.Add("Artist", ""); } if (!data.ContainsKey("Album")) { data.Add("Album", ""); } if (!data.ContainsKey("Genre")) { data.Add("Genre", ""); } string uncPath = GetUncFileName(data["Location"]); if (string.IsNullOrEmpty(data["Artist"]) || string.IsNullOrEmpty(data["Album"])) { success = NewElement(nav, success); continue; } #if !DEBUG else if (!File.Exists(uncPath)) { Logger.ReportError(string.Format("MusicPlugin, file {0} does not exist, not added to iTunes Library", uncPath)); success = NewElement(nav, success); continue; } #endif else if (!MusicHelper.IsMusic(uncPath)) { Logger.ReportError(string.Format("MusicPlugin, file {0} is not supported, not added to iTunes Library", uncPath)); success = NewElement(nav, success); continue; } childGenreFolder = BuildGenre(dictionaryGenre, childGenreFolder, folder, data); childArtistFolder = BuildArtist(dictionaryArtist, childGenreFolder, folder, data); childAlbumFolder = BuildAlbum(dictionaryAlbum, childArtistFolder, data); iTunesSong newSong = BuildSong(childArtistFolder, childAlbumFolder, data); ReadFileImage(childAlbumFolder, newSong); if (dictionaryUniqueAlbum.ContainsKey(data["Album"])) { childUniqueAlbumFolder = dictionaryUniqueAlbum[data["Album"]]; } else { childUniqueAlbumFolder = new iTunesAlbum(); childUniqueAlbumFolder.Name = data["Album"]; childUniqueAlbumFolder.AlbumName = data["Album"]; childUniqueAlbumFolder.Id = childUniqueAlbumFolder.AlbumName.GetMD5(); folder.Albums.Add(childUniqueAlbumFolder); dictionaryUniqueAlbum.Add(data["Album"], childUniqueAlbumFolder); } childUniqueAlbumFolder.Songs.Add(newSong); childUniqueAlbumFolder.PrimaryImagePath = childAlbumFolder.PrimaryImagePath; childUniqueAlbumFolder.BackdropImagePath = childAlbumFolder.BackdropImagePath; success = NewElement(nav, success); } if (Settings.Instance.ShowPlaylistAsFolder) { AddSpecialMusicFolder(folder); } return(folder); }