public override bool CanPlay(string filename) { if (filename == null) { return(false); } return(MusicHelper.IsMusic(filename)); }
public override void ResolveEntity(IMediaLocation location, out BaseItemFactory factory, out IEnumerable <InitializationParameter> setup) { factory = null; setup = null; if (!(location is IFolderMediaLocation) && !MusicHelper.IsHidden(location.Path) && MusicHelper.IsMusic(location.Path)) { factory = BaseItemFactory <Song> .Instance; } }
protected IEnumerable <string> GetChildFiles(IFolderMediaLocation location) { if (location.Path.EndsWith("$RECYCLE.BIN")) { yield break; } foreach (var child in location.Children) { if (MusicHelper.IsMusic(child.Path)) { yield return(child.Path); } else if (child is IFolderMediaLocation) { foreach (var grandChild in GetChildFiles(child as IFolderMediaLocation)) { yield return(grandChild); } } } }
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); }