Extract imagetype-to-keytype statements into a utility function and move tvdb specific utils to separate class
This commit is contained in:
parent
1aaa8de1f9
commit
b9efcace79
|
@ -7,26 +7,6 @@ namespace MediaBrowser.Controller.Library
|
|||
/// </summary>
|
||||
public static class TVUtils
|
||||
{
|
||||
/// <summary>
|
||||
/// The TVDB API key
|
||||
/// </summary>
|
||||
public static readonly string TvdbApiKey = "OG4V3YJ3FAP7FP2K";
|
||||
public static readonly string TvdbBaseUrl = "https://www.thetvdb.com/";
|
||||
/// <summary>
|
||||
/// The banner URL
|
||||
/// </summary>
|
||||
public static readonly string BannerUrl = TvdbBaseUrl + "banners/";
|
||||
|
||||
public static string NormalizeLanguage(string language)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(language))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// pt-br is just pt to tvdb
|
||||
return language.Split('-')[0].ToLowerInvariant();
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets the air days.
|
||||
/// </summary>
|
||||
|
|
|
@ -11,7 +11,6 @@ using MediaBrowser.Controller.Library;
|
|||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Providers;
|
||||
using MediaBrowser.Providers.TV;
|
||||
using MediaBrowser.Providers.TV.TheTVDB;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using TvDbSharper;
|
||||
|
@ -89,7 +88,7 @@ namespace MediaBrowser.Providers.People
|
|||
|
||||
return new RemoteImageInfo
|
||||
{
|
||||
Url = TVUtils.BannerUrl + actor.Image,
|
||||
Url = TvdbUtils.BannerUrl + actor.Image,
|
||||
Type = ImageType.Primary,
|
||||
ProviderName = Name
|
||||
};
|
||||
|
|
|
@ -28,7 +28,7 @@ namespace MediaBrowser.Providers.TV.TheTVDB
|
|||
private TvDbClientManager()
|
||||
{
|
||||
tvDbClient = new TvDbClient();
|
||||
tvDbClient.Authentication.AuthenticateAsync(TVUtils.TvdbApiKey);
|
||||
tvDbClient.Authentication.AuthenticateAsync(TvdbUtils.TvdbApiKey);
|
||||
tokenCreatedAt = DateTime.Now;
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ namespace MediaBrowser.Providers.TV.TheTVDB
|
|||
}
|
||||
catch
|
||||
{
|
||||
tvDbClient.Authentication.AuthenticateAsync(TVUtils.TvdbApiKey);
|
||||
tvDbClient.Authentication.AuthenticateAsync(TvdbUtils.TvdbApiKey);
|
||||
}
|
||||
|
||||
tokenCreatedAt = DateTime.Now;
|
||||
|
@ -222,7 +222,7 @@ namespace MediaBrowser.Providers.TV.TheTVDB
|
|||
return cachedValue;
|
||||
}
|
||||
|
||||
tvDbClient.AcceptedLanguage = TVUtils.NormalizeLanguage(language) ?? DefaultLanguage;
|
||||
tvDbClient.AcceptedLanguage = TvdbUtils.NormalizeLanguage(language) ?? DefaultLanguage;
|
||||
var result = await resultFactory.Invoke();
|
||||
_cache.Set(key, result, TimeSpan.FromHours(1));
|
||||
return result;
|
||||
|
|
|
@ -1,13 +1,10 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Common.Net;
|
||||
using MediaBrowser.Controller.Configuration;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Entities.TV;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Providers;
|
||||
|
@ -105,7 +102,7 @@ namespace MediaBrowser.Providers.TV.TheTVDB
|
|||
Width = Convert.ToInt32(episode.ThumbWidth),
|
||||
Height = Convert.ToInt32(episode.ThumbHeight),
|
||||
ProviderName = Name,
|
||||
Url = TVUtils.BannerUrl + episode.Filename,
|
||||
Url = TvdbUtils.BannerUrl + episode.Filename,
|
||||
Type = ImageType.Primary
|
||||
};
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ using System.Threading.Tasks;
|
|||
using MediaBrowser.Common.Net;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Entities.TV;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Providers;
|
||||
|
@ -100,10 +99,10 @@ namespace MediaBrowser.Providers.TV.TheTVDB
|
|||
RatingType = RatingType.Score,
|
||||
CommunityRating = (double?)image.RatingsInfo.Average,
|
||||
VoteCount = image.RatingsInfo.Count,
|
||||
Url = TVUtils.BannerUrl + image.FileName,
|
||||
Url = TvdbUtils.BannerUrl + image.FileName,
|
||||
ProviderName = ProviderName,
|
||||
Language = languages.FirstOrDefault(lang => lang.Id == image.LanguageId)?.Abbreviation,
|
||||
ThumbnailUrl = TVUtils.BannerUrl + image.Thumbnail
|
||||
ThumbnailUrl = TvdbUtils.BannerUrl + image.Thumbnail
|
||||
};
|
||||
|
||||
var resolution = image.Resolution.Split('x');
|
||||
|
@ -113,19 +112,7 @@ namespace MediaBrowser.Providers.TV.TheTVDB
|
|||
imageInfo.Height = Convert.ToInt32(resolution[1]);
|
||||
}
|
||||
|
||||
if (string.Equals(image.KeyType, "season", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
imageInfo.Type = ImageType.Primary;
|
||||
}
|
||||
else if (string.Equals(image.KeyType, "seasonwide", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
imageInfo.Type = ImageType.Banner;
|
||||
}
|
||||
else if (string.Equals(image.KeyType, "fanart", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
imageInfo.Type = ImageType.Backdrop;
|
||||
}
|
||||
|
||||
imageInfo.Type = TvdbUtils.GetImageTypeFromKeyType(image.KeyType);
|
||||
list.Add(imageInfo);
|
||||
}
|
||||
var isLanguageEn = string.Equals(preferredLanguage, "en", StringComparison.OrdinalIgnoreCase);
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Common.Net;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Providers;
|
||||
|
@ -95,10 +93,10 @@ namespace MediaBrowser.Providers.TV.TheTVDB
|
|||
RatingType = RatingType.Score,
|
||||
CommunityRating = (double?)image.RatingsInfo.Average,
|
||||
VoteCount = image.RatingsInfo.Count,
|
||||
Url = TVUtils.BannerUrl + image.FileName,
|
||||
Url = TvdbUtils.BannerUrl + image.FileName,
|
||||
ProviderName = Name,
|
||||
Language = languages.FirstOrDefault(lang => lang.Id == image.LanguageId)?.Abbreviation,
|
||||
ThumbnailUrl = TVUtils.BannerUrl + image.Thumbnail
|
||||
ThumbnailUrl = TvdbUtils.BannerUrl + image.Thumbnail
|
||||
};
|
||||
|
||||
var resolution = image.Resolution.Split('x');
|
||||
|
@ -108,20 +106,7 @@ namespace MediaBrowser.Providers.TV.TheTVDB
|
|||
imageInfo.Height = Convert.ToInt32(resolution[1]);
|
||||
}
|
||||
|
||||
|
||||
if (string.Equals(image.KeyType, "poster", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
imageInfo.Type = ImageType.Primary;
|
||||
}
|
||||
else if (string.Equals(image.KeyType, "series", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
imageInfo.Type = ImageType.Banner;
|
||||
}
|
||||
else if (string.Equals(image.KeyType, "fanart", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
imageInfo.Type = ImageType.Backdrop;
|
||||
}
|
||||
|
||||
imageInfo.Type = TvdbUtils.GetImageTypeFromKeyType(image.KeyType);
|
||||
list.Add(imageInfo);
|
||||
}
|
||||
var isLanguageEn = string.Equals(preferredLanguage, "en", StringComparison.OrdinalIgnoreCase);
|
||||
|
|
|
@ -232,7 +232,7 @@ namespace MediaBrowser.Providers.TV.TheTVDB
|
|||
Name = tvdbTitles.FirstOrDefault(),
|
||||
ProductionYear = firstAired.Year,
|
||||
SearchProviderName = Name,
|
||||
ImageUrl = TVUtils.BannerUrl + seriesSearchResult.Banner
|
||||
ImageUrl = TvdbUtils.BannerUrl + seriesSearchResult.Banner
|
||||
|
||||
};
|
||||
try
|
||||
|
@ -383,7 +383,7 @@ namespace MediaBrowser.Providers.TV.TheTVDB
|
|||
Type = PersonType.Actor,
|
||||
Name = (actor.Name ?? string.Empty).Trim(),
|
||||
Role = actor.Role,
|
||||
ImageUrl = TVUtils.BannerUrl + actor.Image,
|
||||
ImageUrl = TvdbUtils.BannerUrl + actor.Image,
|
||||
SortOrder = actor.SortOrder
|
||||
};
|
||||
|
||||
|
|
47
MediaBrowser.Providers/TV/TheTVDB/TvdbUtils.cs
Normal file
47
MediaBrowser.Providers/TV/TheTVDB/TvdbUtils.cs
Normal file
|
@ -0,0 +1,47 @@
|
|||
using System;
|
||||
using System.ComponentModel;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using TvDbSharper.Dto;
|
||||
|
||||
namespace MediaBrowser.Providers.TV.TheTVDB
|
||||
{
|
||||
/// <summary>
|
||||
/// Class TVUtils
|
||||
/// </summary>
|
||||
public static class TvdbUtils
|
||||
{
|
||||
/// <summary>
|
||||
/// The TVDB API key
|
||||
/// </summary>
|
||||
public static readonly string TvdbApiKey = "OG4V3YJ3FAP7FP2K";
|
||||
public static readonly string TvdbBaseUrl = "https://www.thetvdb.com/";
|
||||
/// <summary>
|
||||
/// The banner URL
|
||||
/// </summary>
|
||||
public static readonly string BannerUrl = TvdbBaseUrl + "banners/";
|
||||
|
||||
public static ImageType GetImageTypeFromKeyType(string keyType)
|
||||
{
|
||||
switch (keyType.ToLowerInvariant())
|
||||
{
|
||||
case "poster":
|
||||
case "season": return ImageType.Primary;
|
||||
case "series":
|
||||
case "seasonwide": return ImageType.Banner;
|
||||
case "fanart": return ImageType.Backdrop;
|
||||
default: throw new ArgumentException($"Invalid or unknown keytype: {keyType}", nameof(keyType));
|
||||
}
|
||||
}
|
||||
|
||||
public static string NormalizeLanguage(string language)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(language))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// pt-br is just pt to tvdb
|
||||
return language.Split('-')[0].ToLowerInvariant();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user