public static void SetVideoMetaData(this MediaItem item, DmapData metaData) { MediaItemAspect.SetAttribute(item.Aspects, MediaAspect.ATTR_TITLE, metaData.Title); MediaItemAspect.SetCollectionAttribute(item.Aspects, VideoAspect.ATTR_ACTORS, metaData.Actors); MediaItemAspect.SetCollectionAttribute(item.Aspects, VideoAspect.ATTR_GENRES, metaData.Genres); MediaItemAspect.SetCollectionAttribute(item.Aspects, VideoAspect.ATTR_DIRECTORS, metaData.Directors); }
public static void AddMetaDataToMediaItem(this MediaItem item, string metaData) { if (metaData == null) { return; } string coverUrl; DmapData dmapData = Utils.ExtractMetaDataFromDidlLite(metaData, out coverUrl); if (item.Aspects.ContainsKey(AudioAspect.ASPECT_ID)) { item.SetAudioMetaData(dmapData); } if (item.Aspects.ContainsKey(VideoAspect.ASPECT_ID)) { item.SetVideoMetaData(dmapData); } if (item.Aspects.ContainsKey(ImageAspect.ASPECT_ID)) { item.SetImageMetaData(dmapData); } if (!String.IsNullOrEmpty(coverUrl)) { item.SetCover(Utils.DownloadImage(coverUrl)); } }
public static void SetAudioMetaData(this MediaItem item, DmapData metaData) { MediaItemAspect.SetAttribute(item.Aspects, MediaAspect.ATTR_TITLE, metaData.Title); MediaItemAspect.SetAttribute(item.Aspects, AudioAspect.ATTR_ALBUM, metaData.Album); MediaItemAspect.SetCollectionAttribute(item.Aspects, AudioAspect.ATTR_ARTISTS, metaData.Artists); MediaItemAspect.SetCollectionAttribute(item.Aspects, AudioAspect.ATTR_GENRES, metaData.Genres); MediaItemAspect.SetAttribute(item.Aspects, AudioAspect.ATTR_TRACK, metaData.OriginalTrackNumber); MediaItemAspect.SetAttribute(item.Aspects, AudioAspect.ATTR_NUMDISCS, metaData.OriginalDiscCount); }
public static void SetVideoMetaData(this MediaItem item, DmapData metaData) { MediaItemAspect.SetAttribute(item.Aspects, MediaAspect.ATTR_TITLE, metaData.Title); MediaItemAspect.SetCollectionAttribute(item.Aspects, VideoAspect.ATTR_ACTORS, metaData.Actors); foreach (string genre in metaData.Genres) { MultipleMediaItemAspect genreAspect = MediaItemAspect.CreateAspect(item.Aspects, GenreAspect.Metadata); genreAspect.SetAttribute(GenreAspect.ATTR_GENRE, genre); } MediaItemAspect.SetCollectionAttribute(item.Aspects, VideoAspect.ATTR_DIRECTORS, metaData.Directors); }
public static void SetAudioMetaData(this MediaItem item, DmapData metaData) { MediaItemAspect.SetAttribute(item.Aspects, MediaAspect.ATTR_TITLE, metaData.Title); MediaItemAspect.SetAttribute(item.Aspects, AudioAspect.ATTR_ALBUM, metaData.Album); MediaItemAspect.SetCollectionAttribute(item.Aspects, AudioAspect.ATTR_ARTISTS, metaData.Artists); foreach (string genre in metaData.Genres) { MultipleMediaItemAspect genreAspect = MediaItemAspect.CreateAspect(item.Aspects, GenreAspect.Metadata); genreAspect.SetAttribute(GenreAspect.ATTR_GENRE, genre); } MediaItemAspect.SetAttribute(item.Aspects, AudioAspect.ATTR_TRACK, metaData.OriginalTrackNumber); MediaItemAspect.SetAttribute(item.Aspects, AudioAspect.ATTR_NUMDISCS, metaData.OriginalDiscCount); }
public static void SetImageMetaData(this MediaItem item, DmapData metaData) { MediaItemAspect.SetAttribute(item.Aspects, MediaAspect.ATTR_TITLE, metaData.Title); }
public static DmapData ExtractMetaDataFromDidlLite(string metaData, out string coverUrl) { if (string.IsNullOrEmpty(metaData)) { coverUrl = string.Empty; return null; } DmapData dmapData = new DmapData(); List<string> directors = new List<string>(); List<string> artists = new List<string>(); List<string> actors = new List<string>(); List<string> genres = new List<string>(); coverUrl = string.Empty; // there is a bug in the xmlreader when there is no newline in the xml document // https://social.msdn.microsoft.com/Forums/silverlight/en-US/04cd225d-6c09-427b-9586-f81848b22e08/xml-parsing-problem-xmlrearderreadtofollowing-causes-problem?forum=silverlightnet /* Hi Steve, Thank you very much. I could solve my problem. The cause was that my xml did not contain any line breaks. When I rewrote the xml adding line breaks, the Xml.Reader.ReadToFollowing method could successfully find the all elements. Again, thank you very much for your help! */ using (XmlReader reader = XmlReader.Create(new StringReader(metaData))) { while (reader.Read()) { Logger.Debug("Name: {0} - Value: {1}", reader.Name, reader.Value); if (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { // DIDL-Lite // DC: http://www.upnp.org/schemas/av/didl-lite-v2.xsd case "dc:title": reader.Read(); if (reader.Value != string.Empty) { dmapData.Title = reader.Value; Logger.Debug("Title value: {0}", dmapData.Title); } break; case "dc:description": reader.Read(); if (reader.Value != string.Empty) { dmapData.Description = reader.Value; Logger.Debug("Description value: {0}", dmapData.Description); } break; case "dc:creator": reader.Read(); if (reader.Value != string.Empty) { dmapData.Creator = reader.Value; Logger.Debug("Creator value: {0}", dmapData.Creator); } break; // UPnP: http://www.upnp.org/schemas/av/upnp.xsd // Contributor Related Properties case "upnp:director": reader.Read(); if (reader.Value != string.Empty) { directors.Add(reader.Value); Logger.Debug("Director value: {0}", directors.Last()); } break; case "upnp:artist": reader.Read(); if (reader.Value != string.Empty) { artists.Add(reader.Value); Logger.Debug("Artists value: {0}", artists.Last()); } break; case "upnp:actor": reader.Read(); if (reader.Value != string.Empty) { actors.Add(reader.Value); Logger.Debug("Actors value: {0}", actors.Last()); } break; // missing: author, producer //Affiliation Related Properties case "upnp:album": reader.Read(); if (reader.Value != string.Empty) { dmapData.Album = reader.Value; Logger.Debug("Album value: {0}", dmapData.Album); } break; case "upnp:genre": reader.Read(); if (reader.Value != string.Empty) { genres.Add(reader.Value); Logger.Debug("Genres value: {0}", genres.Last()); } break; // missing: playlist // Associated Resources Properties case "upnp:albumArtURI": reader.Read(); if (reader.Value != string.Empty) { coverUrl = reader.Value; Logger.Debug("CoverURL value: {0}", coverUrl); } break; // missing: artistDiscographyURI, lyricsURI // missing: Storage Related Properties, General Description Properties, Recorded Object Related Properties, User Channel and EPG Related Properties // Radio Broadcast Properties, Video Broadcast Properties, Physical Tuner Status-related Properties, Bookmark Related Properties // Foreign Metadata Related Properties, Miscellaneous Properties, Object Tracking Properties, Content Protection Properties // Base Properties, Contributor Related Properties, Affiliation Related Properties, User Channel and EPG Related Properties // Video Broadcast Properties, ... to the end case "upnp:originalTrackNumber": reader.Read(); if (reader.Value != string.Empty) { int number; dmapData.OriginalTrackNumber = int.TryParse(reader.Value, out number) ? number : 0; Logger.Debug("OriginalTrackNumber value: {0}", dmapData.OriginalTrackNumber); } break; case "upnp:originalDiscNumber": reader.Read(); if (reader.Value != string.Empty) { int number; dmapData.OriginalDiscNumber = int.TryParse(reader.Value, out number) ? number : 0; Logger.Debug("OriginalDiscNumber value: {0}", dmapData.OriginalDiscNumber); } break; case "upnp:originalDiscCount": reader.Read(); if (reader.Value != string.Empty) { int number; dmapData.OriginalDiscCount = int.TryParse(reader.Value, out number) ? number : 0; Logger.Debug("OriginalDiscCount value: {0}", dmapData.OriginalDiscCount); } break; } } } /*reader.ReadToFollowing("dc:title"); dmapData.Title = reader.ReadElementContentAsString(); reader.ReadToFollowing("upnp:artist"); dmapData.Artists = new[] { reader.ReadElementContentAsString() }; reader.ReadToFollowing("upnp:albumArtURI"); coverUrl = reader.ReadElementContentAsString();*/ } dmapData.Directors = directors.ToArray(); dmapData.Artists = artists.ToArray(); dmapData.Actors = actors.ToArray(); dmapData.Genres = genres.ToArray(); return dmapData; }