public bool GetPlayData(out string mimeType, out string mediaItemTitle) { mimeType = null; mediaItemTitle = null; SingleMediaItemAspect mediaAspect = null; if (!MediaItemAspect.TryGetAspect(this.Aspects, MediaAspect.Metadata, out mediaAspect)) { return(false); } IList <MultipleMediaItemAspect> resourceAspects = null; if (!MediaItemAspect.TryGetAspects(this.Aspects, ProviderResourceAspect.Metadata, out resourceAspects)) { return(false); } foreach (MultipleMediaItemAspect pra in resourceAspects) { if (pra.GetAttributeValue <bool?>(ProviderResourceAspect.ATTR_PRIMARY) == true) { mimeType = (string)pra[ProviderResourceAspect.ATTR_MIME_TYPE]; mediaItemTitle = (string)mediaAspect[MediaAspect.ATTR_TITLE]; return(true); } } return(false); }
private static IEnumerable <MultipleMediaItemAspect> GetExternalIdentifierAspectsForType(IDictionary <Guid, IList <MediaItemAspect> > aspects, string externalIdType) { IList <MultipleMediaItemAspect> externalAspects; if (!MediaItemAspect.TryGetAspects(aspects, ExternalIdentifierAspect.Metadata, out externalAspects)) { return(null); } return(externalAspects.Where(a => a.GetAttributeValue <string>(ExternalIdentifierAspect.ATTR_TYPE) == externalIdType)); }
public static bool MergeVideoResourceAspects(IDictionary <Guid, IList <MediaItemAspect> > extractedAspects, IDictionary <Guid, IList <MediaItemAspect> > existingAspects) { //Extracted aspects IList <MultipleMediaItemAspect> providerResourceAspects; if (!MediaItemAspect.TryGetAspects(extractedAspects, ProviderResourceAspect.Metadata, out providerResourceAspects)) { return(false); } string accessorPath = (string)providerResourceAspects.First().GetAttributeValue(ProviderResourceAspect.ATTR_RESOURCE_ACCESSOR_PATH); ResourcePath resourcePath = ResourcePath.Deserialize(accessorPath); IList <MultipleMediaItemAspect> videoAspects; MediaItemAspect.TryGetAspects(extractedAspects, VideoStreamAspect.Metadata, out videoAspects); IList <MultipleMediaItemAspect> videoAudioAspects; MediaItemAspect.TryGetAspects(extractedAspects, VideoAudioStreamAspect.Metadata, out videoAudioAspects); IList <MultipleMediaItemAspect> subtitleAspects; MediaItemAspect.TryGetAspects(extractedAspects, SubtitleAspect.Metadata, out subtitleAspects); //Existing aspects IList <MultipleMediaItemAspect> existingProviderResourceAspects; MediaItemAspect.TryGetAspects(existingAspects, ProviderResourceAspect.Metadata, out existingProviderResourceAspects); Dictionary <int, int> resourceIndexMap = new Dictionary <int, int>(); int newResourceIndex = -1; if (existingProviderResourceAspects != null) { foreach (MultipleMediaItemAspect providerResourceAspect in existingProviderResourceAspects) { int resouceIndex = providerResourceAspect.GetAttributeValue <int>(ProviderResourceAspect.ATTR_RESOURCE_INDEX); if (newResourceIndex < resouceIndex) { newResourceIndex = resouceIndex; } } } newResourceIndex++; bool resourceExists = false; //Resource might already be added in the initial add foreach (MultipleMediaItemAspect providerResourceAspect in providerResourceAspects) { if (existingProviderResourceAspects != null) { accessorPath = (string)providerResourceAspect.GetAttributeValue(ProviderResourceAspect.ATTR_RESOURCE_ACCESSOR_PATH); foreach (MultipleMediaItemAspect exisitingProviderResourceAspect in existingProviderResourceAspects) { string existingAccessorPath = (string)exisitingProviderResourceAspect.GetAttributeValue(ProviderResourceAspect.ATTR_RESOURCE_ACCESSOR_PATH); if (accessorPath.Equals(existingAccessorPath, StringComparison.InvariantCultureIgnoreCase)) { resourceExists = true; break; } } } if (resourceExists) { continue; } int resouceIndex = providerResourceAspect.GetAttributeValue <int>(ProviderResourceAspect.ATTR_RESOURCE_INDEX); if (!resourceIndexMap.ContainsKey(resouceIndex)) { resourceIndexMap.Add(resouceIndex, newResourceIndex); } newResourceIndex++; MultipleMediaItemAspect newPra = MediaItemAspect.CreateAspect(existingAspects, ProviderResourceAspect.Metadata); newPra.SetAttribute(ProviderResourceAspect.ATTR_RESOURCE_INDEX, resourceIndexMap[resouceIndex]); newPra.SetAttribute(ProviderResourceAspect.ATTR_TYPE, providerResourceAspect.GetAttributeValue(ProviderResourceAspect.ATTR_TYPE)); newPra.SetAttribute(ProviderResourceAspect.ATTR_MIME_TYPE, providerResourceAspect.GetAttributeValue(ProviderResourceAspect.ATTR_MIME_TYPE)); newPra.SetAttribute(ProviderResourceAspect.ATTR_SIZE, providerResourceAspect.GetAttributeValue(ProviderResourceAspect.ATTR_SIZE)); newPra.SetAttribute(ProviderResourceAspect.ATTR_RESOURCE_ACCESSOR_PATH, providerResourceAspect.GetAttributeValue(ProviderResourceAspect.ATTR_RESOURCE_ACCESSOR_PATH)); newPra.SetAttribute(ProviderResourceAspect.ATTR_PARENT_DIRECTORY_ID, providerResourceAspect.GetAttributeValue(ProviderResourceAspect.ATTR_PARENT_DIRECTORY_ID)); newPra.SetAttribute(ProviderResourceAspect.ATTR_SYSTEM_ID, providerResourceAspect.GetAttributeValue(ProviderResourceAspect.ATTR_SYSTEM_ID)); if (videoAspects != null) { foreach (MultipleMediaItemAspect videoAspect in videoAspects) { int videoResourceIndex = videoAspect.GetAttributeValue <int>(VideoStreamAspect.ATTR_RESOURCE_INDEX); if (videoResourceIndex == resouceIndex) { MultipleMediaItemAspect newVa = MediaItemAspect.CreateAspect(existingAspects, VideoStreamAspect.Metadata); newVa.SetAttribute(VideoStreamAspect.ATTR_RESOURCE_INDEX, resourceIndexMap[videoResourceIndex]); newVa.SetAttribute(VideoStreamAspect.ATTR_STREAM_INDEX, videoAspect.GetAttributeValue(VideoStreamAspect.ATTR_STREAM_INDEX)); newVa.SetAttribute(VideoStreamAspect.ATTR_ASPECTRATIO, videoAspect.GetAttributeValue(VideoStreamAspect.ATTR_ASPECTRATIO)); newVa.SetAttribute(VideoStreamAspect.ATTR_AUDIOSTREAMCOUNT, videoAspect.GetAttributeValue(VideoStreamAspect.ATTR_AUDIOSTREAMCOUNT)); newVa.SetAttribute(VideoStreamAspect.ATTR_DURATION, videoAspect.GetAttributeValue(VideoStreamAspect.ATTR_DURATION)); newVa.SetAttribute(VideoStreamAspect.ATTR_FPS, videoAspect.GetAttributeValue(VideoStreamAspect.ATTR_FPS)); newVa.SetAttribute(VideoStreamAspect.ATTR_HEIGHT, videoAspect.GetAttributeValue(VideoStreamAspect.ATTR_HEIGHT)); newVa.SetAttribute(VideoStreamAspect.ATTR_VIDEOBITRATE, videoAspect.GetAttributeValue(VideoStreamAspect.ATTR_VIDEOBITRATE)); newVa.SetAttribute(VideoStreamAspect.ATTR_VIDEOENCODING, videoAspect.GetAttributeValue(VideoStreamAspect.ATTR_VIDEOENCODING)); newVa.SetAttribute(VideoStreamAspect.ATTR_WIDTH, videoAspect.GetAttributeValue(VideoStreamAspect.ATTR_WIDTH)); newVa.SetAttribute(VideoStreamAspect.ATTR_VIDEO_TYPE, videoAspect.GetAttributeValue(VideoStreamAspect.ATTR_VIDEO_TYPE)); newVa.SetAttribute(VideoStreamAspect.ATTR_VIDEO_PART, videoAspect.GetAttributeValue(VideoStreamAspect.ATTR_VIDEO_PART)); newVa.SetAttribute(VideoStreamAspect.ATTR_VIDEO_PART_SET, videoAspect.GetAttributeValue(VideoStreamAspect.ATTR_VIDEO_PART_SET)); newVa.SetAttribute(VideoStreamAspect.ATTR_VIDEO_PART_SET_NAME, videoAspect.GetAttributeValue(VideoStreamAspect.ATTR_VIDEO_PART_SET_NAME)); } } } //Correct sets Dictionary <string, int> setList = new Dictionary <string, int>(); MediaItemAspect.TryGetAspects(existingAspects, ProviderResourceAspect.Metadata, out existingProviderResourceAspects); IList <MultipleMediaItemAspect> existingVideoAspects; if (MediaItemAspect.TryGetAspects(existingAspects, VideoStreamAspect.Metadata, out existingVideoAspects)) { int newMediaSet = 0; Dictionary <int, int> knownSets = new Dictionary <int, int>(); foreach (MultipleMediaItemAspect videoStreamAspect in existingVideoAspects) { string filename = null; foreach (MultipleMediaItemAspect pra in existingProviderResourceAspects) { if (pra.GetAttributeValue <int>(ProviderResourceAspect.ATTR_RESOURCE_INDEX) == videoStreamAspect.GetAttributeValue <int>(VideoStreamAspect.ATTR_RESOURCE_INDEX)) { accessorPath = (string)pra.GetAttributeValue(ProviderResourceAspect.ATTR_RESOURCE_ACCESSOR_PATH); resourcePath = resourcePath = ResourcePath.Deserialize(accessorPath); filename = resourcePath.FileName ?? Path.GetFileName(resourcePath.BasePathSegment.Path); break; } } videoStreamAspect.SetAttribute(VideoStreamAspect.ATTR_VIDEO_PART_SET, GetMultipartSetNumber(ref setList, ref newMediaSet, filename)); } } if (videoAudioAspects != null) { foreach (MultipleMediaItemAspect videoAudioAspect in videoAudioAspects) { int audioResourceIndex = videoAudioAspect.GetAttributeValue <int>(VideoAudioStreamAspect.ATTR_RESOURCE_INDEX); if (audioResourceIndex == resouceIndex) { MultipleMediaItemAspect newVaa = MediaItemAspect.CreateAspect(existingAspects, VideoAudioStreamAspect.Metadata); newVaa.SetAttribute(VideoAudioStreamAspect.ATTR_RESOURCE_INDEX, resourceIndexMap[audioResourceIndex]); newVaa.SetAttribute(VideoAudioStreamAspect.ATTR_STREAM_INDEX, videoAudioAspect.GetAttributeValue(VideoAudioStreamAspect.ATTR_STREAM_INDEX)); newVaa.SetAttribute(VideoAudioStreamAspect.ATTR_AUDIOBITRATE, videoAudioAspect.GetAttributeValue(VideoAudioStreamAspect.ATTR_AUDIOBITRATE)); newVaa.SetAttribute(VideoAudioStreamAspect.ATTR_AUDIOCHANNELS, videoAudioAspect.GetAttributeValue(VideoAudioStreamAspect.ATTR_AUDIOCHANNELS)); newVaa.SetAttribute(VideoAudioStreamAspect.ATTR_AUDIOENCODING, videoAudioAspect.GetAttributeValue(VideoAudioStreamAspect.ATTR_AUDIOENCODING)); newVaa.SetAttribute(VideoAudioStreamAspect.ATTR_AUDIOLANGUAGE, videoAudioAspect.GetAttributeValue(VideoAudioStreamAspect.ATTR_AUDIOLANGUAGE)); } } } //Internal subtitles if (subtitleAspects != null) { foreach (MultipleMediaItemAspect subAspect in subtitleAspects) { int videoResourceIndex = subAspect.GetAttributeValue <int>(SubtitleAspect.ATTR_VIDEO_RESOURCE_INDEX); int subResourceIndex = subAspect.GetAttributeValue <int>(SubtitleAspect.ATTR_RESOURCE_INDEX); if (videoResourceIndex == resouceIndex && subResourceIndex == -1) { MultipleMediaItemAspect newSa = MediaItemAspect.CreateAspect(existingAspects, SubtitleAspect.Metadata); newSa.SetAttribute(SubtitleAspect.ATTR_VIDEO_RESOURCE_INDEX, resourceIndexMap[videoResourceIndex]); newSa.SetAttribute(SubtitleAspect.ATTR_RESOURCE_INDEX, resourceIndexMap[videoResourceIndex]); newSa.SetAttribute(SubtitleAspect.ATTR_STREAM_INDEX, subAspect.GetAttributeValue(SubtitleAspect.ATTR_STREAM_INDEX)); newSa.SetAttribute(SubtitleAspect.ATTR_SUBTITLE_ENCODING, subAspect.GetAttributeValue(SubtitleAspect.ATTR_SUBTITLE_ENCODING)); newSa.SetAttribute(SubtitleAspect.ATTR_SUBTITLE_FORMAT, subAspect.GetAttributeValue(SubtitleAspect.ATTR_SUBTITLE_FORMAT)); newSa.SetAttribute(SubtitleAspect.ATTR_SUBTITLE_LANGUAGE, subAspect.GetAttributeValue(SubtitleAspect.ATTR_SUBTITLE_LANGUAGE)); newSa.SetAttribute(SubtitleAspect.ATTR_INTERNAL, subAspect.GetAttributeValue(SubtitleAspect.ATTR_INTERNAL)); newSa.SetAttribute(SubtitleAspect.ATTR_DEFAULT, subAspect.GetAttributeValue(SubtitleAspect.ATTR_DEFAULT)); newSa.SetAttribute(SubtitleAspect.ATTR_FORCED, subAspect.GetAttributeValue(SubtitleAspect.ATTR_FORCED)); } } } //External subtitles ResourcePath existingResourcePath; if (subtitleAspects != null) { foreach (MultipleMediaItemAspect subAspect in subtitleAspects) { int subResourceIndex = subAspect.GetAttributeValue <int>(SubtitleAspect.ATTR_RESOURCE_INDEX); if (subResourceIndex == resouceIndex) { //Find video resource int videoResourceIndex = -1; if (existingProviderResourceAspects != null) { foreach (MultipleMediaItemAspect existingProviderResourceAspect in existingProviderResourceAspects) { accessorPath = (string)providerResourceAspect.GetAttributeValue(ProviderResourceAspect.ATTR_RESOURCE_ACCESSOR_PATH); resourcePath = ResourcePath.Deserialize(accessorPath); accessorPath = (string)existingProviderResourceAspect.GetAttributeValue(ProviderResourceAspect.ATTR_RESOURCE_ACCESSOR_PATH); existingResourcePath = ResourcePath.Deserialize(accessorPath); if (ResourcePath.GetFileNameWithoutExtension(resourcePath).StartsWith(ResourcePath.GetFileNameWithoutExtension(existingResourcePath), StringComparison.InvariantCultureIgnoreCase)) { bool resPrimary = existingProviderResourceAspect.GetAttributeValue <int>(ProviderResourceAspect.ATTR_TYPE) == ProviderResourceAspect.TYPE_PRIMARY; if (resPrimary == true) { videoResourceIndex = providerResourceAspect.GetAttributeValue <int>(ProviderResourceAspect.ATTR_RESOURCE_INDEX); break; } } } } if (videoResourceIndex >= 0) { MultipleMediaItemAspect newSa = MediaItemAspect.CreateAspect(existingAspects, SubtitleAspect.Metadata); newSa.SetAttribute(SubtitleAspect.ATTR_VIDEO_RESOURCE_INDEX, videoResourceIndex); newSa.SetAttribute(SubtitleAspect.ATTR_RESOURCE_INDEX, resourceIndexMap[subResourceIndex]); newSa.SetAttribute(SubtitleAspect.ATTR_STREAM_INDEX, subAspect.GetAttributeValue(SubtitleAspect.ATTR_STREAM_INDEX)); newSa.SetAttribute(SubtitleAspect.ATTR_SUBTITLE_ENCODING, subAspect.GetAttributeValue(SubtitleAspect.ATTR_SUBTITLE_ENCODING)); newSa.SetAttribute(SubtitleAspect.ATTR_SUBTITLE_FORMAT, subAspect.GetAttributeValue(SubtitleAspect.ATTR_SUBTITLE_FORMAT)); newSa.SetAttribute(SubtitleAspect.ATTR_SUBTITLE_LANGUAGE, subAspect.GetAttributeValue(SubtitleAspect.ATTR_SUBTITLE_LANGUAGE)); newSa.SetAttribute(SubtitleAspect.ATTR_INTERNAL, subAspect.GetAttributeValue(SubtitleAspect.ATTR_INTERNAL)); newSa.SetAttribute(SubtitleAspect.ATTR_DEFAULT, subAspect.GetAttributeValue(SubtitleAspect.ATTR_DEFAULT)); newSa.SetAttribute(SubtitleAspect.ATTR_FORCED, subAspect.GetAttributeValue(SubtitleAspect.ATTR_FORCED)); } } } } } return(true); }