Пример #1
0
        protected static bool CanExtract(IResourceAccessor mediaItemAccessor, IDictionary <Guid, IList <MediaItemAspect> > extractedAspectData, out IResourceAccessor metaFileAccessor)
        {
            metaFileAccessor = null;
            IFileSystemResourceAccessor fsra = mediaItemAccessor as IFileSystemResourceAccessor;

            if (fsra == null || !fsra.IsFile)
            {
                return(false);
            }

            string title;

            if (!MediaItemAspect.TryGetAttribute(extractedAspectData, MediaAspect.ATTR_TITLE, out title) || string.IsNullOrEmpty(title))
            {
                return(false);
            }

            string filePath       = mediaItemAccessor.CanonicalLocalResourcePath.ToString();
            string lowerExtension = StringUtils.TrimToEmpty(ProviderPathHelper.GetExtension(filePath)).ToLowerInvariant();

            if (lowerExtension != ".ts")
            {
                return(false);
            }
            string metaFilePath = ProviderPathHelper.ChangeExtension(filePath, ".xml");

            if (!ResourcePath.Deserialize(metaFilePath).TryCreateLocalResourceAccessor(out metaFileAccessor))
            {
                return(false);
            }
            return(true);
        }
Пример #2
0
        protected bool TryGetConfiguration(MediaItem mediaItem, out EmulatorConfiguration configuration)
        {
            configuration = null;
            List <string> mimeTypes;
            string        mimeType;

            if (mediaItem == null ||
                !MediaItemAspect.TryGetAttribute(mediaItem.Aspects, ProviderResourceAspect.ATTR_MIME_TYPE, out mimeTypes) ||
                string.IsNullOrEmpty(mimeType = mimeTypes.First()))
            {
                return(false);
            }

            List <string> paths;
            string        path;

            if (!MediaItemAspect.TryGetAttribute(mediaItem.Aspects, ProviderResourceAspect.ATTR_RESOURCE_ACCESSOR_PATH, out paths) ||
                string.IsNullOrEmpty(path = paths.First()))
            {
                return(false);
            }

            ResourcePath rp  = ResourcePath.Deserialize(path);
            string       ext = ProviderPathHelper.GetExtension(rp.FileName);

            return(ServiceRegistration.Get <IEmulatorManager>().TryGetConfiguration(mimeType, ext, out configuration));
        }
Пример #3
0
        public override void Update(MediaItem mediaItem)
        {
            base.Update(mediaItem);
            SingleMediaItemAspect imageAspect;

            if (MediaItemAspect.TryGetAspect(mediaItem.Aspects, ImageAspect.Metadata, out imageAspect))
            {
                SimpleTitle = Title;
                int?width  = (int?)imageAspect[ImageAspect.ATTR_WIDTH];
                int?height = (int?)imageAspect[ImageAspect.ATTR_HEIGHT];
                if (width.HasValue && width.Value > 0 && height.HasValue && height.Value > 0)
                {
                    Width  = width;
                    Height = height;
                    Size   = width + " x " + height;
                }
            }
            IList <MultipleMediaItemAspect> resourceAspects;

            if (MediaItemAspect.TryGetAspects(mediaItem.Aspects, ProviderResourceAspect.Metadata, out resourceAspects))
            {
                ResourcePath rp  = ResourcePath.Deserialize((string)resourceAspects[0][ProviderResourceAspect.ATTR_RESOURCE_ACCESSOR_PATH]);
                string       ext = ProviderPathHelper.GetExtension(rp.FileName);
                if (ext.Length > 1)
                {
                    // remove leading '.'
                    ext = ext.Substring(1);
                }
                Extension = ext;
                MimeType  = (string)resourceAspects[0][ProviderResourceAspect.ATTR_MIME_TYPE];
            }
            FireChange();
        }
        public static Type GetPlayerTypeForMediaItem(IResourceLocator locator, string mimeType)
        {
            Type playerType;

            // When a mimetype is set, try to get the player type for it
            if (mimeType != null && MIMETYPES2PLAYER.TryGetValue(mimeType.ToLowerInvariant(), out playerType))
            {
                return(playerType);
            }

            // 2nd chance: If no mimetype matches, try extension
            string path      = locator.NativeResourcePath.LastPathSegment.Path;
            string extension = StringUtils.TrimToEmpty(ProviderPathHelper.GetExtension(path)).ToLowerInvariant();

            if (EXTENSIONS2PLAYER.TryGetValue(extension, out playerType))
            {
                return(playerType);
            }
            return(null);
        }
Пример #5
0
        protected static bool CanExtract(ILocalFsResourceAccessor lfsra, IDictionary <Guid, IList <MediaItemAspect> > extractedAspectData)
        {
            if (lfsra == null || !lfsra.IsFile)
            {
                return(false);
            }

            string title;

            if (!MediaItemAspect.TryGetAttribute(extractedAspectData, MediaAspect.ATTR_TITLE, out title) || string.IsNullOrEmpty(title))
            {
                return(false);
            }

            string filePath       = lfsra.CanonicalLocalResourcePath.ToString();
            string lowerExtension = StringUtils.TrimToEmpty(ProviderPathHelper.GetExtension(filePath)).ToLowerInvariant();

            if (lowerExtension != ".wtv" && lowerExtension != ".dvr-ms")
            {
                return(false);
            }
            return(true);
        }
Пример #6
0
        public ImageItem(MediaItem mediaItem) : base(mediaItem)
        {
            MediaItemAspect imageAspect;

            if (mediaItem.Aspects.TryGetValue(ImageAspect.ASPECT_ID, out imageAspect))
            {
                SimpleTitle = Title;
                int?width  = (int?)imageAspect[ImageAspect.ATTR_WIDTH];
                int?height = (int?)imageAspect[ImageAspect.ATTR_HEIGHT];
                if (width.HasValue && width.Value > 0 && height.HasValue && height.Value > 0)
                {
                    Width  = width;
                    Height = height;
                    Size   = width + " x " + height;
                }
            }
            MediaItemAspect resourceAspect;

            if (mediaItem.Aspects.TryGetValue(ProviderResourceAspect.ASPECT_ID, out resourceAspect))
            {
                ResourcePath rp  = ResourcePath.Deserialize((string)resourceAspect[ProviderResourceAspect.ATTR_RESOURCE_ACCESSOR_PATH]);
                string       ext = ProviderPathHelper.GetExtension(rp.FileName);
                if (ext.Length > 1)
                {
                    // remove leading '.'
                    ext = ext.Substring(1);
                }
                Extension = ext;
            }
            MediaItemAspect mediaAspect;

            if (mediaItem.Aspects.TryGetValue(MediaAspect.ASPECT_ID, out mediaAspect))
            {
                MimeType = (string)mediaAspect[MediaAspect.ATTR_MIME_TYPE];
            }
        }
Пример #7
0
        private static void TestRecording(string filename)
        {
            if (Directory.Exists("_Test"))
            {
                Directory.Delete("_Test", true);
            }

            ServiceRegistration.Set <IPathManager>(new PathManager());
            ServiceRegistration.Get <IPathManager>().SetPath("DATA", "_Test/Data");

            ServiceRegistration.Set <ILocalization>(new NoLocalization());
            ServiceRegistration.Set <ILogger>(new ConsoleLogger(LogLevel.All, true));

            ServiceRegistration.Set <IMediaAccessor>(new TestMediaAccessor());
            ServiceRegistration.Set <IMediaItemAspectTypeRegistration>(new MockMediaItemAspectTypeRegistration());

            ApplicationCore.RegisterDefaultMediaItemAspectTypes().Wait();

            ServiceRegistration.Set <SeriesTvDbMatcher>(new SeriesTvDbMatcher());

            IDictionary <Guid, IList <MediaItemAspect> > aspects = new Dictionary <Guid, IList <MediaItemAspect> >();

            string ext = StringUtils.TrimToEmpty(ProviderPathHelper.GetExtension(filename)).ToLowerInvariant();

            if (ext != ".xml")
            {
                Console.WriteLine("Filetype must be XML");
                return;
            }
            XmlSerializer serializer = new XmlSerializer(typeof(Tve3RecordingMetadataExtractor.Tags));

            using (Stream stream = new FileStream(filename, FileMode.Open, FileAccess.Read))
            {
                Tve3RecordingMetadataExtractor.Tags      tags = (Tve3RecordingMetadataExtractor.Tags)serializer.Deserialize(stream);
                Tve3RecordingMetadataExtractor.SimpleTag tag  = tags.Tag.Find(t => t.Name == "TITLE");
                MediaItemAspect.SetAttribute(aspects, MediaAspect.ATTR_TITLE, tag.Value);
            }

            IMediaItemAspectTypeRegistration registration = ServiceRegistration.Get <IMediaItemAspectTypeRegistration>();

            Console.WriteLine("Before extract:");
            ShowMIAs(aspects, registration);

            IMetadataExtractor extractor = new Tve3RecordingMetadataExtractor();
            IResourceAccessor  accessor  = new MockLocalFsResourceAccessor(ProviderPathHelper.ChangeExtension(filename, ".ts"));

            extractor.TryExtractMetadataAsync(accessor, aspects, false);

            Console.WriteLine("After extract:");
            ShowMIAs(aspects, registration);

            string value;

            if (MediaItemAspect.TryGetExternalAttribute(aspects, ExternalIdentifierAspect.SOURCE_TVDB, ExternalIdentifierAspect.TYPE_SERIES, out value))
            {
                SeriesInfo seriesInfo = new SeriesInfo()
                {
                    TvdbId = Int32.Parse(value)
                };
                SeriesTvDbMatcher.Instance.UpdateSeriesAsync(seriesInfo, false).Wait();
                Console.WriteLine("{0}: {1}", seriesInfo.SeriesName, seriesInfo.Description);
            }
        }
Пример #8
0
        public bool TryExtractMetadata(IResourceAccessor mediaItemAccessor, IDictionary <Guid, MediaItemAspect> extractedAspectData, bool forceQuickMode)
        {
            try
            {
                IFileSystemResourceAccessor fsra = mediaItemAccessor as IFileSystemResourceAccessor;
                if (fsra == null || !mediaItemAccessor.IsFile)
                {
                    return(false);
                }

                string filePath       = mediaItemAccessor.CanonicalLocalResourcePath.ToString();
                string lowerExtension = StringUtils.TrimToEmpty(ProviderPathHelper.GetExtension(filePath)).ToLowerInvariant();
                if (lowerExtension != ".ts")
                {
                    return(false);
                }
                string            metaFilePath = ProviderPathHelper.ChangeExtension(filePath, ".xml");
                IResourceAccessor metaFileAccessor;
                if (!ResourcePath.Deserialize(metaFilePath).TryCreateLocalResourceAccessor(out metaFileAccessor))
                {
                    return(false);
                }

                Tags tags;
                using (metaFileAccessor)
                {
                    using (Stream metaStream = metaFileAccessor.OpenRead())
                        tags = (Tags)GetTagsXmlSerializer().Deserialize(metaStream);
                }

                MediaItemAspect mediaAspect     = MediaItemAspect.GetOrCreateAspect(extractedAspectData, MediaAspect.Metadata);
                MediaItemAspect videoAspect     = MediaItemAspect.GetOrCreateAspect(extractedAspectData, VideoAspect.Metadata);
                MediaItemAspect recordingAspect = MediaItemAspect.GetOrCreateAspect(extractedAspectData, RecordingAspect.Metadata);

                // Handle series information
                SeriesInfo seriesInfo = GetSeriesFromTags(tags);
                if (seriesInfo.IsCompleteMatch)
                {
                    if (!forceQuickMode)
                    {
                        SeriesTvDbMatcher.Instance.FindAndUpdateSeries(seriesInfo);
                    }

                    seriesInfo.SetMetadata(extractedAspectData);
                }

                string value;
                if (TryGet(tags, TAG_TITLE, out value) && !string.IsNullOrEmpty(value))
                {
                    mediaAspect.SetAttribute(MediaAspect.ATTR_TITLE, value);
                }

                if (TryGet(tags, TAG_GENRE, out value))
                {
                    videoAspect.SetCollectionAttribute(VideoAspect.ATTR_GENRES, new List <String> {
                        value
                    });
                }

                if (TryGet(tags, TAG_PLOT, out value))
                {
                    videoAspect.SetAttribute(VideoAspect.ATTR_STORYPLOT, value);
                    Match yearMatch = _yearMatcher.Match(value);
                    int   guessedYear;
                    if (int.TryParse(yearMatch.Value, out guessedYear))
                    {
                        MediaItemAspect.SetAttribute(extractedAspectData, MediaAspect.ATTR_RECORDINGTIME, new DateTime(guessedYear, 1, 1));
                    }
                }

                if (TryGet(tags, TAG_CHANNEL, out value))
                {
                    recordingAspect.SetAttribute(RecordingAspect.ATTR_CHANNEL, value);
                }

                // Recording date formatted: 2011-11-04 20:55
                DateTime recordingStart;
                DateTime recordingEnd;
                if (TryGet(tags, TAG_STARTTIME, out value) && DateTime.TryParse(value, out recordingStart))
                {
                    recordingAspect.SetAttribute(RecordingAspect.ATTR_STARTTIME, recordingStart);
                }

                if (TryGet(tags, TAG_ENDTIME, out value) && DateTime.TryParse(value, out recordingEnd))
                {
                    recordingAspect.SetAttribute(RecordingAspect.ATTR_ENDTIME, recordingEnd);
                }

                return(true);
            }
            catch (Exception e)
            {
                // Only log at the info level here - And simply return false. This lets the caller know that we
                // couldn't perform our task here.
                ServiceRegistration.Get <ILogger>().Info("Tve3RecordingMetadataExtractor: Exception reading resource '{0}' (Text: '{1}')", mediaItemAccessor.CanonicalLocalResourcePath, e.Message);
            }
            return(false);
        }
        private bool ExtractMetadata(ILocalFsResourceAccessor lfsra, IDictionary <Guid, MediaItemAspect> extractedAspectData, bool forceQuickMode)
        {
            if (lfsra == null || !lfsra.IsFile)
            {
                return(false);
            }

            string title;

            if (!MediaItemAspect.TryGetAttribute(extractedAspectData, MediaAspect.ATTR_TITLE, out title) || string.IsNullOrEmpty(title))
            {
                return(false);
            }

            string filePath       = lfsra.CanonicalLocalResourcePath.ToString();
            string lowerExtension = StringUtils.TrimToEmpty(ProviderPathHelper.GetExtension(filePath)).ToLowerInvariant();

            if (lowerExtension != ".wtv" && lowerExtension != ".dvr-ms")
            {
                return(false);
            }

            using (var rec = new MCRecMetadataEditor(lfsra.LocalFileSystemPath))
            {
                // Handle series information
                IDictionary tags       = rec.GetAttributes();
                SeriesInfo  seriesInfo = GetSeriesFromTags(tags);

                if (!forceQuickMode)
                {
                    if (SeriesTvDbMatcher.Instance.FindAndUpdateSeries(seriesInfo))
                    {
                        seriesInfo.SetMetadata(extractedAspectData);
                    }
                }

                // Force MimeType
                MediaItemAspect.SetAttribute(extractedAspectData, MediaAspect.ATTR_MIME_TYPE, "slimtv/wtv");

                string value;
                if (TryGet(tags, TAG_TITLE, out value) && !string.IsNullOrEmpty(value))
                {
                    MediaItemAspect.SetAttribute(extractedAspectData, MediaAspect.ATTR_TITLE, value);
                }

                if (TryGet(tags, TAG_GENRE, out value))
                {
                    MediaItemAspect.SetCollectionAttribute(extractedAspectData, VideoAspect.ATTR_GENRES, new List <String>(value.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries)));
                }

                if (TryGet(tags, TAG_PLOT, out value))
                {
                    MediaItemAspect.SetAttribute(extractedAspectData, VideoAspect.ATTR_STORYPLOT, value);
                }

                if (TryGet(tags, TAG_ORIGINAL_TIME, out value))
                {
                    DateTime origTime;
                    if (DateTime.TryParse(value, out origTime))
                    {
                        MediaItemAspect.SetAttribute(extractedAspectData, MediaAspect.ATTR_RECORDINGTIME, origTime);
                    }
                }

                if (TryGet(tags, TAG_CHANNEL, out value))
                {
                    MediaItemAspect.SetAttribute(extractedAspectData, RecordingAspect.ATTR_CHANNEL, value);
                }

                long lValue;
                if (TryGet(tags, TAG_STARTTIME, out lValue))
                {
                    MediaItemAspect.SetAttribute(extractedAspectData, RecordingAspect.ATTR_STARTTIME, FromMCEFileTime(lValue));
                }
                if (TryGet(tags, TAG_ENDTIME, out lValue))
                {
                    MediaItemAspect.SetAttribute(extractedAspectData, RecordingAspect.ATTR_ENDTIME, FromMCEFileTime(lValue));
                }
            }
            return(true);
        }