Some style fixes

This commit is contained in:
Bond_009 2019-09-25 17:19:48 +02:00
parent ac9dfa8e93
commit c5995af493
3 changed files with 65 additions and 36 deletions

View File

@ -21,14 +21,6 @@ namespace Emby.Server.Implementations.Images
public abstract class BaseDynamicImageProvider<T> : IHasItemChangeMonitor, IForcedProvider, ICustomMetadataProvider<T>, IHasOrder public abstract class BaseDynamicImageProvider<T> : IHasItemChangeMonitor, IForcedProvider, ICustomMetadataProvider<T>, IHasOrder
where T : BaseItem where T : BaseItem
{ {
protected virtual IReadOnlyCollection<ImageType> SupportedImages { get; }
= new ImageType[] { ImageType.Primary };
protected IFileSystem FileSystem { get; private set; }
protected IProviderManager ProviderManager { get; private set; }
protected IApplicationPaths ApplicationPaths { get; private set; }
protected IImageProcessor ImageProcessor { get; set; }
protected BaseDynamicImageProvider(IFileSystem fileSystem, IProviderManager providerManager, IApplicationPaths applicationPaths, IImageProcessor imageProcessor) protected BaseDynamicImageProvider(IFileSystem fileSystem, IProviderManager providerManager, IApplicationPaths applicationPaths, IImageProcessor imageProcessor)
{ {
ApplicationPaths = applicationPaths; ApplicationPaths = applicationPaths;
@ -37,6 +29,24 @@ namespace Emby.Server.Implementations.Images
ImageProcessor = imageProcessor; ImageProcessor = imageProcessor;
} }
protected IFileSystem FileSystem { get; }
protected IProviderManager ProviderManager { get; }
protected IApplicationPaths ApplicationPaths { get; }
protected IImageProcessor ImageProcessor { get; set; }
protected virtual IReadOnlyCollection<ImageType> SupportedImages { get; }
= new ImageType[] { ImageType.Primary };
/// <inheritdoc />
public string Name => "Dynamic Image Provider";
protected virtual int MaxImageAgeDays => 7;
public int Order => 0;
protected virtual bool Supports(BaseItem _) => true; protected virtual bool Supports(BaseItem _) => true;
public async Task<ItemUpdateType> FetchAsync(T item, MetadataRefreshOptions options, CancellationToken cancellationToken) public async Task<ItemUpdateType> FetchAsync(T item, MetadataRefreshOptions options, CancellationToken cancellationToken)
@ -85,7 +95,8 @@ namespace Emby.Server.Implementations.Images
return FetchToFileInternal(item, items, imageType, cancellationToken); return FetchToFileInternal(item, items, imageType, cancellationToken);
} }
protected async Task<ItemUpdateType> FetchToFileInternal(BaseItem item, protected async Task<ItemUpdateType> FetchToFileInternal(
BaseItem item,
IReadOnlyList<BaseItem> itemsWithImages, IReadOnlyList<BaseItem> itemsWithImages,
ImageType imageType, ImageType imageType,
CancellationToken cancellationToken) CancellationToken cancellationToken)
@ -181,8 +192,6 @@ namespace Emby.Server.Implementations.Images
return outputPath; return outputPath;
} }
public string Name => "Dynamic Image Provider";
protected virtual string CreateImage(BaseItem item, protected virtual string CreateImage(BaseItem item,
IReadOnlyCollection<BaseItem> itemsWithImages, IReadOnlyCollection<BaseItem> itemsWithImages,
string outputPathWithoutExtension, string outputPathWithoutExtension,
@ -214,8 +223,6 @@ namespace Emby.Server.Implementations.Images
throw new ArgumentException("Unexpected image type", nameof(imageType)); throw new ArgumentException("Unexpected image type", nameof(imageType));
} }
protected virtual int MaxImageAgeDays => 7;
public bool HasChanged(BaseItem item, IDirectoryService directoryServicee) public bool HasChanged(BaseItem item, IDirectoryService directoryServicee)
{ {
if (!Supports(item)) if (!Supports(item))
@ -263,15 +270,9 @@ namespace Emby.Server.Implementations.Images
protected virtual bool HasChangedByDate(BaseItem item, ItemImageInfo image) protected virtual bool HasChangedByDate(BaseItem item, ItemImageInfo image)
{ {
var age = DateTime.UtcNow - image.DateModified; var age = DateTime.UtcNow - image.DateModified;
if (age.TotalDays <= MaxImageAgeDays) return age.TotalDays > MaxImageAgeDays;
{
return false;
}
return true;
} }
public int Order => 0;
protected string CreateSingleImage(IEnumerable<BaseItem> itemsWithImages, string outputPathWithoutExtension, ImageType imageType) protected string CreateSingleImage(IEnumerable<BaseItem> itemsWithImages, string outputPathWithoutExtension, ImageType imageType)
{ {
var image = itemsWithImages var image = itemsWithImages

View File

@ -10,10 +10,15 @@ namespace MediaBrowser.Controller.LiveTv
public interface IListingsProvider public interface IListingsProvider
{ {
string Name { get; } string Name { get; }
string Type { get; } string Type { get; }
Task<IEnumerable<ProgramInfo>> GetProgramsAsync(ListingsProviderInfo info, string channelId, DateTime startDateUtc, DateTime endDateUtc, CancellationToken cancellationToken); Task<IEnumerable<ProgramInfo>> GetProgramsAsync(ListingsProviderInfo info, string channelId, DateTime startDateUtc, DateTime endDateUtc, CancellationToken cancellationToken);
Task Validate(ListingsProviderInfo info, bool validateLogin, bool validateListings); Task Validate(ListingsProviderInfo info, bool validateLogin, bool validateListings);
Task<List<NameIdPair>> GetLineups(ListingsProviderInfo info, string country, string location); Task<List<NameIdPair>> GetLineups(ListingsProviderInfo info, string country, string location);
Task<List<ChannelInfo>> GetChannels(ListingsProviderInfo info, CancellationToken cancellationToken); Task<List<ChannelInfo>> GetChannels(ListingsProviderInfo info, CancellationToken cancellationToken);
} }
} }

View File

@ -14,11 +14,12 @@ namespace MediaBrowser.Providers.TV.TheTVDB
{ {
public class TvDbClientManager public class TvDbClientManager
{ {
private const string DefaultLanguage = "en";
private readonly SemaphoreSlim _cacheWriteLock = new SemaphoreSlim(1, 1); private readonly SemaphoreSlim _cacheWriteLock = new SemaphoreSlim(1, 1);
private readonly IMemoryCache _cache; private readonly IMemoryCache _cache;
private readonly TvDbClient _tvDbClient; private readonly TvDbClient _tvDbClient;
private DateTime _tokenCreatedAt; private DateTime _tokenCreatedAt;
private const string DefaultLanguage = "en";
public TvDbClientManager(IMemoryCache memoryCache) public TvDbClientManager(IMemoryCache memoryCache)
{ {
@ -102,39 +103,50 @@ namespace MediaBrowser.Providers.TV.TheTVDB
return episodes; return episodes;
} }
public Task<TvDbResponse<SeriesSearchResult[]>> GetSeriesByImdbIdAsync(string imdbId, string language, public Task<TvDbResponse<SeriesSearchResult[]>> GetSeriesByImdbIdAsync(
string imdbId,
string language,
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
var cacheKey = GenerateKey("series", imdbId, language); var cacheKey = GenerateKey("series", imdbId, language);
return TryGetValue(cacheKey, language,() => TvDbClient.Search.SearchSeriesByImdbIdAsync(imdbId, cancellationToken)); return TryGetValue(cacheKey, language,() => TvDbClient.Search.SearchSeriesByImdbIdAsync(imdbId, cancellationToken));
} }
public Task<TvDbResponse<SeriesSearchResult[]>> GetSeriesByZap2ItIdAsync(string zap2ItId, string language, public Task<TvDbResponse<SeriesSearchResult[]>> GetSeriesByZap2ItIdAsync(
string zap2ItId,
string language,
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
var cacheKey = GenerateKey("series", zap2ItId, language); var cacheKey = GenerateKey("series", zap2ItId, language);
return TryGetValue( cacheKey, language,() => TvDbClient.Search.SearchSeriesByZap2ItIdAsync(zap2ItId, cancellationToken)); return TryGetValue(cacheKey, language, () => TvDbClient.Search.SearchSeriesByZap2ItIdAsync(zap2ItId, cancellationToken));
} }
public Task<TvDbResponse<Actor[]>> GetActorsAsync(int tvdbId, string language, public Task<TvDbResponse<Actor[]>> GetActorsAsync(
int tvdbId,
string language,
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
var cacheKey = GenerateKey("actors", tvdbId, language); var cacheKey = GenerateKey("actors", tvdbId, language);
return TryGetValue(cacheKey, language,() => TvDbClient.Series.GetActorsAsync(tvdbId, cancellationToken)); return TryGetValue(cacheKey, language, () => TvDbClient.Series.GetActorsAsync(tvdbId, cancellationToken));
} }
public Task<TvDbResponse<Image[]>> GetImagesAsync(int tvdbId, ImagesQuery imageQuery, string language, public Task<TvDbResponse<Image[]>> GetImagesAsync(
int tvdbId,
ImagesQuery imageQuery,
string language,
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
var cacheKey = GenerateKey("images", tvdbId, language, imageQuery); var cacheKey = GenerateKey("images", tvdbId, language, imageQuery);
return TryGetValue(cacheKey, language,() => TvDbClient.Series.GetImagesAsync(tvdbId, imageQuery, cancellationToken)); return TryGetValue(cacheKey, language, () => TvDbClient.Series.GetImagesAsync(tvdbId, imageQuery, cancellationToken));
} }
public Task<TvDbResponse<Language[]>> GetLanguagesAsync(CancellationToken cancellationToken) public Task<TvDbResponse<Language[]>> GetLanguagesAsync(CancellationToken cancellationToken)
{ {
return TryGetValue("languages", null,() => TvDbClient.Languages.GetAllAsync(cancellationToken)); return TryGetValue("languages", null, () => TvDbClient.Languages.GetAllAsync(cancellationToken));
} }
public Task<TvDbResponse<EpisodesSummary>> GetSeriesEpisodeSummaryAsync(int tvdbId, string language, public Task<TvDbResponse<EpisodesSummary>> GetSeriesEpisodeSummaryAsync(
int tvdbId,
string language,
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
var cacheKey = GenerateKey("seriesepisodesummary", tvdbId, language); var cacheKey = GenerateKey("seriesepisodesummary", tvdbId, language);
@ -142,8 +154,12 @@ namespace MediaBrowser.Providers.TV.TheTVDB
() => TvDbClient.Series.GetEpisodesSummaryAsync(tvdbId, cancellationToken)); () => TvDbClient.Series.GetEpisodesSummaryAsync(tvdbId, cancellationToken));
} }
public Task<TvDbResponse<EpisodeRecord[]>> GetEpisodesPageAsync(int tvdbId, int page, EpisodeQuery episodeQuery, public Task<TvDbResponse<EpisodeRecord[]>> GetEpisodesPageAsync(
string language, CancellationToken cancellationToken) int tvdbId,
int page,
EpisodeQuery episodeQuery,
string language,
CancellationToken cancellationToken)
{ {
var cacheKey = GenerateKey(language, tvdbId, episodeQuery); var cacheKey = GenerateKey(language, tvdbId, episodeQuery);
@ -151,7 +167,9 @@ namespace MediaBrowser.Providers.TV.TheTVDB
() => TvDbClient.Series.GetEpisodesAsync(tvdbId, page, episodeQuery, cancellationToken)); () => TvDbClient.Series.GetEpisodesAsync(tvdbId, page, episodeQuery, cancellationToken));
} }
public Task<string> GetEpisodeTvdbId(EpisodeInfo searchInfo, string language, public Task<string> GetEpisodeTvdbId(
EpisodeInfo searchInfo,
string language,
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
searchInfo.SeriesProviderIds.TryGetValue(MetadataProviders.Tvdb.ToString(), searchInfo.SeriesProviderIds.TryGetValue(MetadataProviders.Tvdb.ToString(),
@ -187,7 +205,9 @@ namespace MediaBrowser.Providers.TV.TheTVDB
return GetEpisodeTvdbId(Convert.ToInt32(seriesTvdbId), episodeQuery, language, cancellationToken); return GetEpisodeTvdbId(Convert.ToInt32(seriesTvdbId), episodeQuery, language, cancellationToken);
} }
public async Task<string> GetEpisodeTvdbId(int seriesTvdbId, EpisodeQuery episodeQuery, public async Task<string> GetEpisodeTvdbId(
int seriesTvdbId,
EpisodeQuery episodeQuery,
string language, string language,
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
@ -197,8 +217,11 @@ namespace MediaBrowser.Providers.TV.TheTVDB
return episodePage.Data.FirstOrDefault()?.Id.ToString(); return episodePage.Data.FirstOrDefault()?.Id.ToString();
} }
public Task<TvDbResponse<EpisodeRecord[]>> GetEpisodesPageAsync(int tvdbId, EpisodeQuery episodeQuery, public Task<TvDbResponse<EpisodeRecord[]>> GetEpisodesPageAsync(
string language, CancellationToken cancellationToken) int tvdbId,
EpisodeQuery episodeQuery,
string language,
CancellationToken cancellationToken)
{ {
return GetEpisodesPageAsync(tvdbId, 1, episodeQuery, language, cancellationToken); return GetEpisodesPageAsync(tvdbId, 1, episodeQuery, language, cancellationToken);
} }