Esempio n. 1
0
        public static async System.Threading.Tasks.Task RegisterDefaultMediaItemAspectTypes()
        {
            IMediaItemAspectTypeRegistration miatr = ServiceRegistration.Get <IMediaItemAspectTypeRegistration>();

            var knownAspects = new List <MediaItemAspectMetadata>
            {
                ProviderResourceAspect.Metadata,
                ImporterAspect.Metadata,
                DirectoryAspect.Metadata,
                MediaAspect.Metadata,
                VideoAspect.Metadata,
                GenreAspect.Metadata,
                VideoStreamAspect.Metadata,
                VideoAudioStreamAspect.Metadata,
                SubtitleAspect.Metadata,
                AudioAspect.Metadata,
                AudioAlbumAspect.Metadata,
                ImageAspect.Metadata,
                EpisodeAspect.Metadata,
                SeasonAspect.Metadata,
                SeriesAspect.Metadata,
                MovieAspect.Metadata,
                MovieCollectionAspect.Metadata,
                CompanyAspect.Metadata,
                PersonAspect.Metadata,
                CharacterAspect.Metadata,
                ThumbnailLargeAspect.Metadata,
                ExternalIdentifierAspect.Metadata,
                RelationshipAspect.Metadata,
                StubAspect.Metadata,
                ReimportAspect.Metadata
            };
            await miatr.RegisterLocallyKnownMediaItemAspectTypeAsync(knownAspects);
        }
        static SeriesMetadataExtractor()
        {
            MediaCategory  seriesCategory;
            IMediaAccessor mediaAccessor = ServiceRegistration.Get <IMediaAccessor>();

            if (!mediaAccessor.MediaCategories.TryGetValue(MEDIA_CATEGORY_NAME_SERIES, out seriesCategory))
            {
                seriesCategory = mediaAccessor.RegisterMediaCategory(MEDIA_CATEGORY_NAME_SERIES, new List <MediaCategory> {
                    DefaultMediaCategories.Video
                });
            }
            MEDIA_CATEGORIES.Add(seriesCategory);
            OnlineMatcherService.RegisterDefaultSeriesMatchers(MEDIA_CATEGORY_NAME_SERIES);
            OnlineMatcherService.RegisterDefaultSeriesSubtitleMatchers(MEDIA_CATEGORY_NAME_SERIES);

            // All non-default media item aspects must be registered
            IMediaItemAspectTypeRegistration miatr = ServiceRegistration.Get <IMediaItemAspectTypeRegistration>();

            miatr.RegisterLocallyKnownMediaItemAspectTypeAsync(TempSeriesAspect.Metadata);

            // Register reimport support
            miatr.RegisterLocallySupportedReimportMediaItemAspectTypeAsync(SeriesAspect.Metadata);
            miatr.RegisterLocallySupportedReimportMediaItemAspectTypeAsync(EpisodeAspect.Metadata);
            miatr.RegisterLocallySupportedReimportMediaItemAspectTypeAsync(VideoAspect.Metadata);
        }
Esempio n. 3
0
        public static MediaItemAspect Deserialize(XmlReader reader)
        {
            if (!reader.MoveToAttribute("Id"))
            {
                throw new ArgumentException("Media item aspect cannot be deserialized: 'Id' attribute missing");
            }
            Guid aspectTypeId = new Guid(reader.ReadContentAsString());

            reader.MoveToElement();
            IMediaItemAspectTypeRegistration miatr = ServiceRegistration.Get <IMediaItemAspectTypeRegistration>();
            MediaItemAspectMetadata          miaType;

            if (!miatr.LocallyKnownMediaItemAspectTypes.TryGetValue(aspectTypeId, out miaType))
            {
                throw new ArgumentException(string.Format("Media item aspect cannot be deserialized: Unknown media item aspect type '{0}'",
                                                          aspectTypeId));
            }
            MediaItemAspect result = new MediaItemAspect(miaType);

            if (SoapHelper.ReadEmptyStartElement(reader, "Aspect"))
            {
                return(result);
            }
            while (reader.NodeType != XmlNodeType.EndElement)
            {
                if (!reader.MoveToAttribute("Name"))
                {
                    throw new ArgumentException("Media item aspect attribute cannot be deserialized: 'Name' attribute missing");
                }
                String attributeName = reader.ReadContentAsString();
                reader.MoveToElement();
                if (SoapHelper.ReadEmptyStartElement(reader, "Attr"))
                {
                    continue;
                }
                MediaItemAspectMetadata.AttributeSpecification attributeSpec;
                if (!miaType.AttributeSpecifications.TryGetValue(attributeName, out attributeSpec))
                {
                    throw new ArgumentException(string.Format(
                                                    "Media item aspect attribute cannot be deserialized: Unknown attribute specification '{0}'", attributeName));
                }
                if (attributeSpec.IsCollectionAttribute)
                {
                    IList valuesCollection = attributeSpec.CreateValuesCollection();
                    while (reader.NodeType != XmlNodeType.EndElement)
                    {
                        valuesCollection.Add(DeserializeValue(reader, attributeSpec.AttributeType));
                    }
                    result.SetCollectionAttribute(attributeSpec, valuesCollection);
                }
                else
                {
                    result.SetAttribute(attributeSpec, DeserializeValue(reader, attributeSpec.AttributeType));
                }
                reader.ReadEndElement(); // Attr
            }
            reader.ReadEndElement();     // Aspect
            return(result);
        }
        public static void RegisterOnMediaLibrary()
        {
            MediaNavigationModel.RegisterMediaNavigationInitializer(new RecordingsLibrary());
            // All non-default media item aspects must be registered
            IMediaItemAspectTypeRegistration miatr = ServiceRegistration.Get <IMediaItemAspectTypeRegistration>();

            miatr.RegisterLocallyKnownMediaItemAspectTypeAsync(RecordingAspect.Metadata);
        }
        static ArgusRecordingMetadataExtractor()
        {
            MEDIA_CATEGORIES.Add(DefaultMediaCategories.Video);

            // All non-default media item aspects must be registered
            IMediaItemAspectTypeRegistration miatr = ServiceRegistration.Get <IMediaItemAspectTypeRegistration>();

            miatr.RegisterLocallyKnownMediaItemAspectTypeAsync(RecordingAspect.Metadata);
        }
        static SubtitleMetadataExtractor()
        {
            MEDIA_CATEGORIES.Add(DefaultMediaCategories.Video);
            SubtitleMetadataExtractorSettings settings = ServiceRegistration.Get <ISettingsManager>().Load <SubtitleMetadataExtractorSettings>();

            InitializeExtensions(settings);

            // All non-default media item aspects must be registered
            IMediaItemAspectTypeRegistration miatr = ServiceRegistration.Get <IMediaItemAspectTypeRegistration>();

            miatr.RegisterLocallyKnownMediaItemAspectTypeAsync(TempSubtitleAspect.Metadata);
        }
Esempio n. 7
0
        private static void ShowMediaItems(Client client, IFilter filter)
        {
            IMediaItemAspectTypeRegistration registration = ServiceRegistration.Get <IMediaItemAspectTypeRegistration>();
            IList <MediaItem> items = client.GetContentDirectory().SearchAsync(new MediaItemQuery(null, registration.LocallyKnownMediaItemAspectTypes.Keys, filter), true, null, true).Result;

            foreach (MediaItem item in items)
            {
                Console.WriteLine("\nItem {0}:", item.MediaItemId);
                foreach (Guid mia in item.Aspects.Keys)
                {
                    MediaItemAspectMetadata metadata = registration.LocallyKnownMediaItemAspectTypes[mia];
                    foreach (MediaItemAspect aspect in item.Aspects[mia])
                    {
                        Console.WriteLine(" {0}:", metadata.Name);
                        int    count = 0;
                        string sb    = " ";
                        foreach (MediaItemAspectMetadata.AttributeSpecification spec in aspect.Metadata.AttributeSpecifications.Values)
                        {
                            string valueStr = null;
                            if (spec.IsCollectionAttribute)
                            {
                                IEnumerable values = aspect.GetCollectionAttribute(spec);
                                if (values != null)
                                {
                                    IList <string> list = new List <string>();
                                    foreach (object value in values)
                                    {
                                        list.Add(GetValue(spec, value));
                                    }
                                    valueStr = string.Format("[{0}]", string.Join(",", list));
                                }
                            }
                            else
                            {
                                valueStr = GetValue(spec, aspect.GetAttributeValue(spec));
                            }
                            if (valueStr != null)
                            {
                                if (count > 0)
                                {
                                    sb += ",";
                                }
                                //sb += string.Format(" {0}{1}{2}({3}/{4})={5}", spec.AttributeName, aspect is MultipleMediaItemAspect ? "," : "", aspect is MultipleMediaItemAspect ? ((MultipleMediaItemAspect)aspect).Index.ToString() : "", spec.AttributeType.Name, spec.Cardinality, valueStr);
                                sb += string.Format(" {0}={1}", spec.AttributeName, valueStr);
                                count++;
                            }
                        }
                        Console.WriteLine(sb);
                    }
                }
            }
        }
Esempio n. 8
0
        static GameMetadataExtractor()
        {
            IMediaAccessor mediaAccessor = ServiceRegistration.Get <IMediaAccessor>();

            if (!mediaAccessor.MediaCategories.TryGetValue(GameCategory.CATEGORY_NAME, out _gameCategory))
            {
                _gameCategory = mediaAccessor.RegisterMediaCategory(GameCategory.CATEGORY_NAME, null);
            }
            MEDIA_CATEGORIES.Add(_gameCategory);
            // All non-default media item aspects must be registered
            IMediaItemAspectTypeRegistration miatr = ServiceRegistration.Get <IMediaItemAspectTypeRegistration>();

            miatr.RegisterLocallyKnownMediaItemAspectTypeAsync(GameAspect.Metadata);
        }
Esempio n. 9
0
        public static void RegisterDefaultMediaItemAspectTypes()
        {
            IMediaItemAspectTypeRegistration miatr = ServiceRegistration.Get <IMediaItemAspectTypeRegistration>();

            miatr.RegisterLocallyKnownMediaItemAspectType(ProviderResourceAspect.Metadata);
            miatr.RegisterLocallyKnownMediaItemAspectType(ImporterAspect.Metadata);
            miatr.RegisterLocallyKnownMediaItemAspectType(DirectoryAspect.Metadata);
            miatr.RegisterLocallyKnownMediaItemAspectType(MediaAspect.Metadata);
            miatr.RegisterLocallyKnownMediaItemAspectType(VideoAspect.Metadata);
            miatr.RegisterLocallyKnownMediaItemAspectType(AudioAspect.Metadata);
            miatr.RegisterLocallyKnownMediaItemAspectType(ImageAspect.Metadata);
            miatr.RegisterLocallyKnownMediaItemAspectType(SeriesAspect.Metadata);
            miatr.RegisterLocallyKnownMediaItemAspectType(MovieAspect.Metadata);
            miatr.RegisterLocallyKnownMediaItemAspectType(ThumbnailLargeAspect.Metadata);
        }
        static AudioMetadataExtractor()
        {
            MEDIA_CATEGORIES.Add(DefaultMediaCategories.Audio);

            // All non-default media item aspects must be registered
            IMediaItemAspectTypeRegistration miatr = ServiceRegistration.Get <IMediaItemAspectTypeRegistration>();

            miatr.RegisterLocallyKnownMediaItemAspectType(TempAlbumAspect.Metadata);
            miatr.RegisterLocallyKnownMediaItemAspectType(TempPersonAspect.Metadata);

            AudioMetadataExtractorSettings settings = ServiceRegistration.Get <ISettingsManager>().Load <AudioMetadataExtractorSettings>();

            InitializeExtensions(settings);
            InitializeUnsplittableID3v23Values(settings);
            InitializeAdditionalSeparatorBehaviour(settings);
        }
Esempio n. 11
0
        public static MediaItemAspectMetadata.AttributeSpecification DeserializeAttributeTypeReference(string atStr)
        {
            int index = atStr.IndexOf(':');
            IMediaItemAspectTypeRegistration miatr = ServiceRegistration.Get <IMediaItemAspectTypeRegistration>();
            Guid   aspectId      = new Guid(atStr.Substring(0, index));
            string attributeName = atStr.Substring(index + 1);
            MediaItemAspectMetadata miam;

            MediaItemAspectMetadata.AttributeSpecification result;
            if (!miatr.LocallyKnownMediaItemAspectTypes.TryGetValue(aspectId, out miam) ||
                !miam.AttributeSpecifications.TryGetValue(attributeName, out result))
            {
                ServiceRegistration.Get <ILogger>().Warn("SortInformation: Could not deserialize SortInformation '{0}'", atStr);
                return(null);
            }
            return(result);
        }
Esempio n. 12
0
        /// <summary>
        /// Initializes <see cref="MEDIA_CATEGORIES"/> and, if necessary, registers the "Movie" <see cref="MediaCategory"/>
        /// </summary>
        static NfoVideoMetadataExtractor()
        {
            MediaCategory videoCategory;
            var           mediaAccessor = ServiceRegistration.Get <IMediaAccessor>();

            if (!mediaAccessor.MediaCategories.TryGetValue(MEDIA_CATEGORY_NAME_VIDEO, out videoCategory))
            {
                videoCategory = mediaAccessor.RegisterMediaCategory(MEDIA_CATEGORY_NAME_VIDEO, new List <MediaCategory> {
                    DefaultMediaCategories.Video
                });
            }
            MEDIA_CATEGORIES.Add(videoCategory);

            // All non-default media item aspects must be registered
            IMediaItemAspectTypeRegistration miatr = ServiceRegistration.Get <IMediaItemAspectTypeRegistration>();

            miatr.RegisterLocallyKnownMediaItemAspectType(TempPersonAspect.Metadata);
        }
        /// <summary>
        /// Initializes <see cref="MEDIA_CATEGORIES"/> and, if necessary, registers the "Movie" <see cref="MediaCategory"/>
        /// </summary>
        static NfoMovieMetadataExtractor()
        {
            MediaCategory movieCategory;
            var           mediaAccessor = ServiceRegistration.Get <IMediaAccessor>();

            if (!mediaAccessor.MediaCategories.TryGetValue(MEDIA_CATEGORY_NAME_MOVIE, out movieCategory))
            {
                movieCategory = mediaAccessor.RegisterMediaCategory(MEDIA_CATEGORY_NAME_MOVIE, new List <MediaCategory> {
                    DefaultMediaCategories.Video
                });
            }
            MEDIA_CATEGORIES.Add(movieCategory);

            // All non-default media item aspects must be registered
            IMediaItemAspectTypeRegistration miatr = ServiceRegistration.Get <IMediaItemAspectTypeRegistration>();

            miatr.RegisterLocallyKnownMediaItemAspectTypeAsync(TempActorAspect.Metadata);
        }
        static SeriesMetadataExtractor()
        {
            MediaCategory  seriesCategory;
            IMediaAccessor mediaAccessor = ServiceRegistration.Get <IMediaAccessor>();

            if (!mediaAccessor.MediaCategories.TryGetValue(MEDIA_CATEGORY_NAME_SERIES, out seriesCategory))
            {
                seriesCategory = mediaAccessor.RegisterMediaCategory(MEDIA_CATEGORY_NAME_SERIES, new List <MediaCategory> {
                    DefaultMediaCategories.Video
                });
            }
            MEDIA_CATEGORIES.Add(seriesCategory);

            // All non-default media item aspects must be registered
            IMediaItemAspectTypeRegistration miatr = ServiceRegistration.Get <IMediaItemAspectTypeRegistration>();

            miatr.RegisterLocallyKnownMediaItemAspectType(TempSeriesAspect.Metadata);
        }
Esempio n. 15
0
        static MovieMetadataExtractor()
        {
            MediaCategory  movieCategory;
            IMediaAccessor mediaAccessor = ServiceRegistration.Get <IMediaAccessor>();

            if (!mediaAccessor.MediaCategories.TryGetValue(MEDIA_CATEGORY_NAME_MOVIE, out movieCategory))
            {
                movieCategory = mediaAccessor.RegisterMediaCategory(MEDIA_CATEGORY_NAME_MOVIE, new List <MediaCategory> {
                    DefaultMediaCategories.Video
                });
            }
            MEDIA_CATEGORIES.Add(movieCategory);

            // Register reimport support
            IMediaItemAspectTypeRegistration miatr = ServiceRegistration.Get <IMediaItemAspectTypeRegistration>();

            miatr.RegisterLocallySupportedReimportMediaItemAspectTypeAsync(MovieAspect.Metadata);
            miatr.RegisterLocallySupportedReimportMediaItemAspectTypeAsync(VideoAspect.Metadata);
        }
Esempio n. 16
0
        public bool IsValidMediaItem(MediaItem mediaItem)
        {
            if (mediaItem == null)
            {
                return(false);
            }

            if (mediaItem.IsStub)
            {
                return(false);
            }

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

            if (mediaItem.Aspects.Any(a => miatr.LocallySupportedReimportMediaItemAspectTypes.ContainsKey(a.Key)))
            {
                return(true); //Aspect supported for reimport
            }
            return(false);
        }
        public static void RegisterDefaultMediaItemAspectTypes()
        {
            IMediaItemAspectTypeRegistration miatr = ServiceRegistration.Get <IMediaItemAspectTypeRegistration>();

            miatr.RegisterLocallyKnownMediaItemAspectType(ProviderResourceAspect.Metadata);
            miatr.RegisterLocallyKnownMediaItemAspectType(ImporterAspect.Metadata);

            miatr.RegisterLocallyKnownMediaItemAspectType(DirectoryAspect.Metadata);

            miatr.RegisterLocallyKnownMediaItemAspectType(MediaAspect.Metadata);

            miatr.RegisterLocallyKnownMediaItemAspectType(VideoAspect.Metadata);
            miatr.RegisterLocallyKnownMediaItemAspectType(GenreAspect.Metadata);
            miatr.RegisterLocallyKnownMediaItemAspectType(VideoStreamAspect.Metadata);
            miatr.RegisterLocallyKnownMediaItemAspectType(VideoAudioStreamAspect.Metadata);
            miatr.RegisterLocallyKnownMediaItemAspectType(SubtitleAspect.Metadata);

            miatr.RegisterLocallyKnownMediaItemAspectType(AudioAspect.Metadata);
            miatr.RegisterLocallyKnownMediaItemAspectType(AudioAlbumAspect.Metadata);

            miatr.RegisterLocallyKnownMediaItemAspectType(ImageAspect.Metadata);

            miatr.RegisterLocallyKnownMediaItemAspectType(EpisodeAspect.Metadata);
            miatr.RegisterLocallyKnownMediaItemAspectType(SeasonAspect.Metadata);
            miatr.RegisterLocallyKnownMediaItemAspectType(SeriesAspect.Metadata);

            miatr.RegisterLocallyKnownMediaItemAspectType(MovieAspect.Metadata);
            miatr.RegisterLocallyKnownMediaItemAspectType(MovieCollectionAspect.Metadata);

            miatr.RegisterLocallyKnownMediaItemAspectType(CompanyAspect.Metadata);
            miatr.RegisterLocallyKnownMediaItemAspectType(PersonAspect.Metadata);
            miatr.RegisterLocallyKnownMediaItemAspectType(CharacterAspect.Metadata);

            miatr.RegisterLocallyKnownMediaItemAspectType(ThumbnailLargeAspect.Metadata);

            miatr.RegisterLocallyKnownMediaItemAspectType(ExternalIdentifierAspect.Metadata);
            miatr.RegisterLocallyKnownMediaItemAspectType(RelationshipAspect.Metadata);
        }
Esempio n. 18
0
    /// <summary>
    /// Synchronously synchronizes all local shares and media item aspect types with the MediaPortal server.
    /// </summary>
    protected async Task CompleteServerConnectionAsync()
    {
      UPnPServerControllerServiceProxy sc = ServerControllerServiceProxy;
      ISystemResolver systemResolver = ServiceRegistration.Get<ISystemResolver>();
      if (sc != null)
      {
        try
        {
          // Check if we're attached to the server. If the server lost its state, it might have forgotten us.
          if (!sc.GetAttachedClients().Select(clientMetadata => clientMetadata.SystemId).Contains(systemResolver.LocalSystemId))
            sc.AttachClient(systemResolver.LocalSystemId);
        }
        catch (Exception e)
        {
          ServiceRegistration.Get<ILogger>().Warn("ServerConnectionManager: Error checking attachment state at home server '{0}'", e, HomeServerSystemId);
          return; // This is a real error case, we don't need to try any other service calls
        }

        // Register state variables change events
        sc.AttachedClientsChanged += OnAttachedClientsChanged;
        sc.ConnectedClientsChanged += OnConnectedClientsChanged;
      }
      IImporterWorker importerWorker = ServiceRegistration.Get<IImporterWorker>();
      ICollection<Share> newShares = new List<Share>();
      UPnPContentDirectoryServiceProxy cd = ContentDirectoryServiceProxy;
      if (cd != null)
      {
        // Update shares registration
        try
        {
          ISettingsManager settingsManager = ServiceRegistration.Get<ISettingsManager>();
          ServerConnectionSettings settings = settingsManager.Load<ServerConnectionSettings>();
          ServiceRegistration.Get<ILogger>().Info("ServerConnectionManager: Synchronizing shares with home server");
          IDictionary<Guid, Share> serverShares = new Dictionary<Guid, Share>();
          foreach (Share share in await cd.GetSharesAsync(systemResolver.LocalSystemId, SharesFilter.All))
            serverShares.Add(share.ShareId, share);
          IDictionary<Guid, Share> localShares = ServiceRegistration.Get<ILocalSharesManagement>().Shares;
          // First remove shares - if the client lost its configuration and re-registers an already present share, the server's method will throw an exception
          foreach (Guid serverShareId in serverShares.Keys)
            if (!localShares.ContainsKey(serverShareId))
              await cd.RemoveShareAsync(serverShareId);
          foreach (Share localShare in localShares.Values)
          {
            RelocationMode relocationMode;
            if (!serverShares.ContainsKey(localShare.ShareId))
            {
              await cd.RegisterShareAsync(localShare);
              newShares.Add(localShare);
            }
            else if (settings.CachedSharesUpdates.TryGetValue(localShare.ShareId, out relocationMode))
            {
              await cd.UpdateShareAsync(localShare.ShareId, localShare.BaseResourcePath, localShare.Name, localShare.UseShareWatcher, localShare.MediaCategories,
                  relocationMode);
              switch (relocationMode)
              {
                case RelocationMode.ClearAndReImport:
                  importerWorker.ScheduleImport(localShare.BaseResourcePath, localShare.MediaCategories, true);
                  break;
                case RelocationMode.Relocate:
                  importerWorker.ScheduleRefresh(localShare.BaseResourcePath, localShare.MediaCategories, true);
                  break;
              }
            }
          }
          settings.CachedSharesUpdates.Clear();
          settingsManager.Save(settings);
        }
        catch (Exception e)
        {
          ServiceRegistration.Get<ILogger>().Warn("ServerConnectionManager: Could not synchronize local shares with server", e);
        }

        // Update media item aspect type registration
        try
        {
          IMediaItemAspectTypeRegistration miatr = ServiceRegistration.Get<IMediaItemAspectTypeRegistration>();
          ServiceRegistration.Get<ILogger>().Info("ServerConnectionManager: Checking for unregistered media item aspect types at home server");
          ICollection<Guid> serverMIATypes = await cd.GetAllManagedMediaItemAspectTypesAsync();
          foreach (KeyValuePair<Guid, MediaItemAspectMetadata> localMiaType in miatr.LocallyKnownMediaItemAspectTypes)
            if (!serverMIATypes.Contains(localMiaType.Key))
            {
              ServiceRegistration.Get<ILogger>().Info("ServerConnectionManager: Adding unregistered media item aspect type '{0}' (ID '{1}') at home server",
                  localMiaType.Value.Name, localMiaType.Key);
              await cd.AddMediaItemAspectStorageAsync(localMiaType.Value);
            }
        }
        catch (Exception e)
        {
          ServiceRegistration.Get<ILogger>().Warn("ServerConnectionManager: Could not synchronize local media item aspect types with server", e);
        }

        // Register state variables change events
        cd.PlaylistsChanged += OnContentDirectoryPlaylistsChanged;
        cd.MIATypeRegistrationsChanged += OnContentDirectoryMIATypeRegistrationsChanged;
        cd.RegisteredSharesChangeCounterChanged += OnRegisteredSharesChangeCounterChanged;

        // Activate importer worker
        ServiceRegistration.Get<ILogger>().Debug("ServerConnectionManager: Activating importer worker");
        ImporterCallback ic = new ImporterCallback(cd);
        importerWorker.Activate(ic, ic);
        foreach (Share share in newShares)
          importerWorker.ScheduleImport(share.BaseResourcePath, share.MediaCategories, true);
      }
    }
Esempio n. 19
0
 private static void ShowMIAs(IDictionary <Guid, IList <MediaItemAspect> > aspects, IMediaItemAspectTypeRegistration registration)
 {
     foreach (Guid mia in aspects.Keys)
     {
         MediaItemAspectMetadata metadata = registration.LocallyKnownMediaItemAspectTypes[mia];
         foreach (MediaItemAspect aspect in aspects[mia])
         {
             Console.WriteLine(" {0}:", metadata.Name);
             int    count = 0;
             string sb    = " ";
             foreach (MediaItemAspectMetadata.AttributeSpecification spec in metadata.AttributeSpecifications.Values)
             {
                 object value = aspect[spec];
                 if (value != null)
                 {
                     if (count > 0)
                     {
                         sb += ",";
                     }
                     if (value is IList)
                     {
                         sb += string.Format(" {0}({1}/{2})=[{3}]", spec.AttributeName, spec.AttributeType.Name, spec.Cardinality, string.Join(",", (IList)value));
                     }
                     else
                     {
                         sb += string.Format(" {0}={1}", spec.AttributeName, value.ToString());
                     }
                     count++;
                 }
             }
             Console.WriteLine(sb);
         }
     }
 }
Esempio n. 20
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);
            }
        }