make external id's modular

pull/702/head
Luke Pulverenti 11 years ago
parent 6e5d90bafe
commit 0d90f1d450

@ -150,6 +150,7 @@
<Compile Include="Persistence\MediaStreamQuery.cs" />
<Compile Include="Providers\DirectoryService.cs" />
<Compile Include="Providers\ICustomMetadataProvider.cs" />
<Compile Include="Providers\IExternalId.cs" />
<Compile Include="Providers\IForcedProvider.cs" />
<Compile Include="Providers\IHasChangeMonitor.cs" />
<Compile Include="Entities\IHasMetadata.cs" />

@ -0,0 +1,15 @@
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Controller.Providers
{
public interface IExternalId
{
string Name { get; }
string Key { get; }
string UrlFormatString { get; }
bool Supports(IHasProviderIds item);
}
}

@ -56,9 +56,11 @@ namespace MediaBrowser.Controller.Providers
/// <param name="metadataProviders">The metadata providers.</param>
/// <param name="savers">The savers.</param>
/// <param name="imageSavers">The image savers.</param>
/// <param name="externalIds">The external ids.</param>
void AddParts(IEnumerable<IImageProvider> imageProviders, IEnumerable<IMetadataService> metadataServices, IEnumerable<IMetadataProvider> metadataProviders,
IEnumerable<IMetadataSaver> savers,
IEnumerable<IImageSaver> imageSavers);
IEnumerable<IImageSaver> imageSavers,
IEnumerable<IExternalId> externalIds);
/// <summary>
/// Gets the available remote images.
@ -82,6 +84,13 @@ namespace MediaBrowser.Controller.Providers
/// <returns>IEnumerable{MetadataPlugin}.</returns>
IEnumerable<MetadataPluginSummary> GetAllMetadataPlugins();
/// <summary>
/// Gets the external urls.
/// </summary>
/// <param name="item">The item.</param>
/// <returns>IEnumerable{ExternalUrl}.</returns>
IEnumerable<ExternalUrl> GetExternalUrls(IHasProviderIds item);
/// <summary>
/// Saves the metadata.
/// </summary>

@ -332,6 +332,9 @@
<Compile Include="..\MediaBrowser.Model\Plugins\PluginInfo.cs">
<Link>Plugins\PluginInfo.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.Model\Providers\ExternalIdInfo.cs">
<Link>Providers\ExternalIdInfo.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.Model\Providers\ImageProviderInfo.cs">
<Link>Providers\ImageProviderInfo.cs</Link>
</Compile>

@ -319,6 +319,9 @@
<Compile Include="..\MediaBrowser.Model\Plugins\PluginInfo.cs">
<Link>Plugins\PluginInfo.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.Model\Providers\ExternalIdInfo.cs">
<Link>Providers\ExternalIdInfo.cs</Link>
</Compile>
<Compile Include="..\MediaBrowser.Model\Providers\ImageProviderInfo.cs">
<Link>Providers\ImageProviderInfo.cs</Link>
</Compile>

@ -1,10 +1,11 @@
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Library;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.Serialization;
using MediaBrowser.Model.Library;
using MediaBrowser.Model.Providers;
namespace MediaBrowser.Model.Dto
{
@ -77,6 +78,12 @@ namespace MediaBrowser.Model.Dto
/// <value>The premiere date.</value>
public DateTime? PremiereDate { get; set; }
/// <summary>
/// Gets or sets the external urls.
/// </summary>
/// <value>The external urls.</value>
public ExternalUrl[] ExternalUrls { get; set; }
/// <summary>
/// Gets or sets the critic rating.
/// </summary>

@ -88,6 +88,7 @@
<Compile Include="LiveTv\TimerInfoDto.cs" />
<Compile Include="Logging\NullLogger.cs" />
<Compile Include="News\NewsItem.cs" />
<Compile Include="Providers\ExternalIdInfo.cs" />
<Compile Include="Providers\ImageProviderInfo.cs" />
<Compile Include="Providers\RemoteImageInfo.cs" />
<Compile Include="Dto\StudioDto.cs" />

@ -0,0 +1,45 @@

namespace MediaBrowser.Model.Providers
{
public class ExternalIdInfo
{
/// <summary>
/// Gets or sets the name.
/// </summary>
/// <value>The name.</value>
public string Name { get; set; }
/// <summary>
/// Gets or sets the key.
/// </summary>
/// <value>The key.</value>
public string Key { get; set; }
/// <summary>
/// Gets or sets the type of the item.
/// </summary>
/// <value>The type of the item.</value>
public string ItemType { get; set; }
/// <summary>
/// Gets or sets the format string.
/// </summary>
/// <value>The format string.</value>
public string FormatString { get; set; }
}
public class ExternalUrl
{
/// <summary>
/// Gets or sets the name.
/// </summary>
/// <value>The name.</value>
public string Name { get; set; }
/// <summary>
/// Gets or sets the type of the item.
/// </summary>
/// <value>The type of the item.</value>
public string Url { get; set; }
}
}

@ -51,6 +51,11 @@ namespace MediaBrowser.Model.Querying
/// </summary>
DisplayPreferencesId,
/// <summary>
/// The external urls
/// </summary>
ExternalUrls,
/// <summary>
/// Genres
/// </summary>

@ -57,6 +57,8 @@ namespace MediaBrowser.Providers.Manager
private IEnumerable<IMetadataSaver> _savers;
private IImageSaver[] _imageSavers;
private IExternalId[] _externalIds;
/// <summary>
/// Initializes a new instance of the <see cref="ProviderManager" /> class.
/// </summary>
@ -82,8 +84,10 @@ namespace MediaBrowser.Providers.Manager
/// <param name="metadataProviders">The metadata providers.</param>
/// <param name="metadataSavers">The metadata savers.</param>
/// <param name="imageSavers">The image savers.</param>
/// <param name="externalIds">The external ids.</param>
public void AddParts(IEnumerable<IImageProvider> imageProviders, IEnumerable<IMetadataService> metadataServices, IEnumerable<IMetadataProvider> metadataProviders, IEnumerable<IMetadataSaver> metadataSavers,
IEnumerable<IImageSaver> imageSavers)
IEnumerable<IImageSaver> imageSavers,
IEnumerable<IExternalId> externalIds)
{
ImageProviders = imageProviders.ToArray();
@ -91,6 +95,7 @@ namespace MediaBrowser.Providers.Manager
_metadataProviders = metadataProviders.ToArray();
_savers = metadataSavers.ToArray();
_imageSavers = imageSavers.ToArray();
_externalIds = externalIds.OrderBy(i => i.Name).ToArray();
}
public Task RefreshMetadata(IHasMetadata item, MetadataRefreshOptions options, CancellationToken cancellationToken)
@ -625,5 +630,47 @@ namespace MediaBrowser.Providers.Manager
// Nothing found
return new List<RemoteSearchResult>();
}
public IEnumerable<IExternalId> GetExternalIds(IHasProviderIds item)
{
return _externalIds.Where(i =>
{
try
{
return i.Supports(item);
}
catch (Exception ex)
{
_logger.ErrorException("Error in {0}.Suports", ex, i.GetType().Name);
return false;
}
});
}
public IEnumerable<ExternalUrl> GetExternalUrls(IHasProviderIds item)
{
return GetExternalIds(item)
.Select(i =>
{
if (string.IsNullOrEmpty(i.UrlFormatString))
{
return null;
}
var value = item.GetProviderId(i.Key);
if (string.IsNullOrEmpty(value))
{
return null;
}
return new ExternalUrl
{
Name = i.Name,
Url = string.Format(i.UrlFormatString, value)
};
}).Where(i => i != null);
}
}
}

@ -99,6 +99,7 @@
<Compile Include="MediaInfo\FFProbeProvider.cs" />
<Compile Include="MediaInfo\FFProbeVideoInfo.cs" />
<Compile Include="Movies\MovieDbTrailerProvider.cs" />
<Compile Include="Movies\MovieExternalIds.cs" />
<Compile Include="Movies\TrailerMetadataService.cs" />
<Compile Include="Movies\GenericMovieDbInfo.cs" />
<Compile Include="Movies\MovieDbSearch.cs" />
@ -123,11 +124,13 @@
<Compile Include="Music\AudioDbAlbumProvider.cs" />
<Compile Include="Music\AudioDbArtistImageProvider.cs" />
<Compile Include="Music\AudioDbArtistProvider.cs" />
<Compile Include="Music\AudioDbExternalIds.cs" />
<Compile Include="Music\AudioMetadataService.cs" />
<Compile Include="Music\Extensions.cs" />
<Compile Include="Music\LastfmArtistProvider.cs" />
<Compile Include="Music\MovieDbMusicVideoProvider.cs" />
<Compile Include="Music\MusicBrainzArtistProvider.cs" />
<Compile Include="Music\MusicExternalIds.cs" />
<Compile Include="Music\MusicVideoMetadataService.cs" />
<Compile Include="Music\MusicVideoXmlProvider.cs" />
<Compile Include="Omdb\OmdbProvider.cs" />
@ -196,6 +199,7 @@
<Compile Include="TV\SeriesXmlProvider.cs" />
<Compile Include="TV\SeriesXmlParser.cs" />
<Compile Include="TV\TvdbPrescanTask.cs" />
<Compile Include="TV\TvExternalIds.cs" />
<Compile Include="Users\UserMetadataService.cs" />
<Compile Include="Videos\VideoMetadataService.cs" />
<Compile Include="Xbmc\XbmcImageSaver.cs" />

@ -0,0 +1,147 @@
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Providers.Movies
{
public class MovieDbMovieExternalId : IExternalId
{
public string Name
{
get { return "TheMovieDb"; }
}
public string Key
{
get { return MetadataProviders.Tmdb.ToString(); }
}
public string UrlFormatString
{
get { return "http://www.themoviedb.org/movie/{0}"; }
}
public bool Supports(IHasProviderIds item)
{
return item is Movie || item is Trailer || item is MusicVideo;
}
}
public class MovieDbSeriesExternalId : IExternalId
{
public string Name
{
get { return "TheMovieDb"; }
}
public string Key
{
get { return MetadataProviders.Tmdb.ToString(); }
}
public string UrlFormatString
{
get { return "http://www.themoviedb.org/tv/{0}"; }
}
public bool Supports(IHasProviderIds item)
{
return item is Series;
}
}
public class MovieDbPersonExternalId : IExternalId
{
public string Name
{
get { return "TheMovieDb"; }
}
public string Key
{
get { return MetadataProviders.Tmdb.ToString(); }
}
public string UrlFormatString
{
get { return "http://www.themoviedb.org/person/{0}"; }
}
public bool Supports(IHasProviderIds item)
{
return item is Person;
}
}
public class MovieDbCollectionExternalId : IExternalId
{
public string Name
{
get { return "TheMovieDb"; }
}
public string Key
{
get { return MetadataProviders.Tmdb.ToString(); }
}
public string UrlFormatString
{
get { return "http://www.themoviedb.org/collection/{0}"; }
}
public bool Supports(IHasProviderIds item)
{
return item is BoxSet;
}
}
public class ImdbExternalId : IExternalId
{
public string Name
{
get { return "IMDb"; }
}
public string Key
{
get { return MetadataProviders.Imdb.ToString(); }
}
public string UrlFormatString
{
get { return "http://www.imdb.com/title/{0}"; }
}
public bool Supports(IHasProviderIds item)
{
return !(item is Person);
}
}
public class ImdbPersonExternalId : IExternalId
{
public string Name
{
get { return "IMDb"; }
}
public string Key
{
get { return MetadataProviders.Imdb.ToString(); }
}
public string UrlFormatString
{
get { return "http://www.imdb.com/name/{0}"; }
}
public bool Supports(IHasProviderIds item)
{
return item is Person;
}
}
}

@ -0,0 +1,99 @@
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Providers.Music
{
public class AudioDbAlbumExternalId : IExternalId
{
public string Name
{
get { return "TheAudioDb"; }
}
public string Key
{
get { return MetadataProviders.AudioDbAlbum.ToString(); }
}
public string UrlFormatString
{
get { return "http://www.theaudiodb.com/album/{0}"; }
}
public bool Supports(IHasProviderIds item)
{
return item is MusicAlbum;
}
}
public class AudioDbOtherAlbumExternalId : IExternalId
{
public string Name
{
get { return "TheAudioDb Album"; }
}
public string Key
{
get { return MetadataProviders.AudioDbAlbum.ToString(); }
}
public string UrlFormatString
{
get { return "http://www.theaudiodb.com/album/{0}"; }
}
public bool Supports(IHasProviderIds item)
{
return item is Audio;
}
}
public class AudioDbArtistExternalId : IExternalId
{
public string Name
{
get { return "TheAudioDb"; }
}
public string Key
{
get { return MetadataProviders.AudioDbArtist.ToString(); }
}
public string UrlFormatString
{
get { return "http://www.theaudiodb.com/artist/{0}"; }
}
public bool Supports(IHasProviderIds item)
{
return item is MusicArtist;
}
}
public class AudioDbOtherArtistExternalId : IExternalId
{
public string Name
{
get { return "TheAudioDb"; }
}
public string Key
{
get { return MetadataProviders.AudioDbArtist.ToString(); }
}
public string UrlFormatString
{
get { return "http://www.theaudiodb.com/artist/{0}"; }
}
public bool Supports(IHasProviderIds item)
{
return item is Audio || item is MusicAlbum;
}
}
}

@ -0,0 +1,121 @@
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Providers.Music
{
public class MusicBrainzReleaseGroupExternalId : IExternalId
{
public string Name
{
get { return "MusicBrainz Release Group"; }
}
public string Key
{
get { return MetadataProviders.MusicBrainzReleaseGroup.ToString(); }
}
public string UrlFormatString
{
get { return "http://musicbrainz.org/release-group/{0}"; }
}
public bool Supports(IHasProviderIds item)
{
return item is Audio || item is MusicAlbum || item is MusicArtist;
}
}
public class MusicBrainzAlbumArtistExternalId : IExternalId
{
public string Name
{
get { return "MusicBrainz Album Artist"; }
}
public string Key
{
get { return MetadataProviders.MusicBrainzAlbumArtist.ToString(); }
}
public string UrlFormatString
{
get { return "http://musicbrainz.org/artist/{0}"; }
}
public bool Supports(IHasProviderIds item)
{
return item is Audio || item is MusicAlbum;
}
}
public class MusicBrainzAlbumExternalId : IExternalId
{
public string Name
{
get { return "MusicBrainz Album"; }
}
public string Key
{
get { return MetadataProviders.MusicBrainzAlbum.ToString(); }
}
public string UrlFormatString
{
get { return "http://musicbrainz.org/release/{0}"; }
}
public bool Supports(IHasProviderIds item)
{
return item is Audio || item is MusicAlbum;
}
}
public class MusicBrainzArtistExternalId : IExternalId
{
public string Name
{
get { return "MusicBrainz"; }
}
public string Key
{
get { return MetadataProviders.MusicBrainzArtist.ToString(); }
}
public string UrlFormatString
{
get { return "http://musicbrainz.org/artist/{0}"; }
}
public bool Supports(IHasProviderIds item)
{
return item is MusicArtist;
}
}
public class MusicBrainzOtherArtistExternalId : IExternalId
{
public string Name
{
get { return "MusicBrainz Artist"; }
}
public string Key
{
get { return MetadataProviders.MusicBrainzArtist.ToString(); }
}
public string UrlFormatString
{
get { return "http://musicbrainz.org/artist/{0}"; }
}
public bool Supports(IHasProviderIds item)
{
return item is Audio || item is MusicAlbum;
}
}
}

@ -0,0 +1,100 @@
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Providers.TV
{
public class Zap2ItExternalId : IExternalId
{
public string Name
{
get { return "Zap2It"; }
}
public string Key
{
get { return MetadataProviders.Zap2It.ToString(); }
}
public string UrlFormatString
{
get { return "http://tvlistings.zap2it.com/tv/dexter/{0}?aid=zap2it"; }
}
public bool Supports(IHasProviderIds item)
{
return item is Series;
}
}
public class TvdbExternalId : IExternalId
{
public string Name
{
get { return "TheTVDB"; }
}
public string Key
{
get { return MetadataProviders.Tvdb.ToString(); }
}
public string UrlFormatString
{
get { return "http://thetvdb.com/index.php?tab=series&id={0}"; }
}
public bool Supports(IHasProviderIds item)
{
return item is Series;
}
}
public class TvComSeriesExternalId : IExternalId
{
public string Name
{
get { return "TV.com"; }
}
public string Key
{
get { return MetadataProviders.Tvcom.ToString(); }
}
public string UrlFormatString
{
get { return null; }
}
public bool Supports(IHasProviderIds item)
{
return item is Series;
}
}
public class TvComPersonExternalId : IExternalId
{
public string Name
{
get { return "TV.com"; }
}
public string Key
{
get { return MetadataProviders.Tvcom.ToString(); }
}
public string UrlFormatString
{
get { return null; }
}
public bool Supports(IHasProviderIds item)
{
return item is Person;
}
}
}

@ -9,6 +9,7 @@ using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Persistence;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Controller.Session;
using MediaBrowser.Model.Drawing;
using MediaBrowser.Model.Dto;
@ -35,8 +36,9 @@ namespace MediaBrowser.Server.Implementations.Dto
private readonly IImageProcessor _imageProcessor;
private readonly IServerConfigurationManager _config;
private readonly IFileSystem _fileSystem;
private readonly IProviderManager _providerManager;
public DtoService(ILogger logger, ILibraryManager libraryManager, IUserManager userManager, IUserDataManager userDataRepository, IItemRepository itemRepo, IImageProcessor imageProcessor, IServerConfigurationManager config, IFileSystem fileSystem)
public DtoService(ILogger logger, ILibraryManager libraryManager, IUserManager userManager, IUserDataManager userDataRepository, IItemRepository itemRepo, IImageProcessor imageProcessor, IServerConfigurationManager config, IFileSystem fileSystem, IProviderManager providerManager)
{
_logger = logger;
_libraryManager = libraryManager;
@ -46,6 +48,7 @@ namespace MediaBrowser.Server.Implementations.Dto
_imageProcessor = imageProcessor;
_config = config;
_fileSystem = fileSystem;
_providerManager = providerManager;
}
/// <summary>
@ -689,6 +692,11 @@ namespace MediaBrowser.Server.Implementations.Dto
dto.HomePageUrl = item.HomePageUrl;
}
if (fields.Contains(ItemFields.ExternalUrls))
{
dto.ExternalUrls = _providerManager.GetExternalUrls(item).ToArray();
}
if (fields.Contains(ItemFields.Tags))
{
var hasTags = item as IHasTags;

@ -284,6 +284,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv
if (!fileInfo.Exists)
{
_logger.Debug("Creating directory {0}", path);
Directory.CreateDirectory(path);
fileInfo = new DirectoryInfo(path);

@ -423,7 +423,7 @@ namespace MediaBrowser.ServerApplication
ImageProcessor = new ImageProcessor(Logger, ServerConfigurationManager.ApplicationPaths, FileSystemManager, JsonSerializer);
RegisterSingleInstance(ImageProcessor);
DtoService = new DtoService(Logger, LibraryManager, UserManager, UserDataManager, ItemRepository, ImageProcessor, ServerConfigurationManager, FileSystemManager);
DtoService = new DtoService(Logger, LibraryManager, UserManager, UserDataManager, ItemRepository, ImageProcessor, ServerConfigurationManager, FileSystemManager, ProviderManager);
RegisterSingleInstance(DtoService);
var newsService = new Server.Implementations.News.NewsService(ApplicationPaths, JsonSerializer);
@ -617,7 +617,8 @@ namespace MediaBrowser.ServerApplication
ProviderManager.AddParts(GetExports<IImageProvider>(), GetExports<IMetadataService>(), GetExports<IMetadataProvider>(),
GetExports<IMetadataSaver>(),
GetExports<IImageSaver>());
GetExports<IImageSaver>(),
GetExports<IExternalId>());
ImageProcessor.AddParts(GetExports<IImageEnhancer>());

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>MediaBrowser.Common.Internal</id>
<version>3.0.331</version>
<version>3.0.332</version>
<title>MediaBrowser.Common.Internal</title>
<authors>Luke</authors>
<owners>ebr,Luke,scottisafool</owners>
@ -12,7 +12,7 @@
<description>Contains common components shared by Media Browser Theater and Media Browser Server. Not intended for plugin developer consumption.</description>
<copyright>Copyright © Media Browser 2013</copyright>
<dependencies>
<dependency id="MediaBrowser.Common" version="3.0.331" />
<dependency id="MediaBrowser.Common" version="3.0.332" />
<dependency id="NLog" version="2.1.0" />
<dependency id="SimpleInjector" version="2.4.1" />
<dependency id="sharpcompress" version="0.10.2" />

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>MediaBrowser.Common</id>
<version>3.0.331</version>
<version>3.0.332</version>
<title>MediaBrowser.Common</title>
<authors>Media Browser Team</authors>
<owners>ebr,Luke,scottisafool</owners>

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>MediaBrowser.Server.Core</id>
<version>3.0.331</version>
<version>3.0.332</version>
<title>Media Browser.Server.Core</title>
<authors>Media Browser Team</authors>
<owners>ebr,Luke,scottisafool</owners>
@ -12,7 +12,7 @@
<description>Contains core components required to build plugins for Media Browser Server.</description>
<copyright>Copyright © Media Browser 2013</copyright>
<dependencies>
<dependency id="MediaBrowser.Common" version="3.0.331" />
<dependency id="MediaBrowser.Common" version="3.0.332" />
</dependencies>
</metadata>
<files>

Loading…
Cancel
Save