2016-03-27 17:11:27 -04:00
|
|
|
|
using MediaBrowser.Common.Net;
|
2013-12-30 11:32:01 -05:00
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
using MediaBrowser.Model.Providers;
|
2014-01-28 13:37:01 -05:00
|
|
|
|
using MediaBrowser.Providers.ImagesByName;
|
2013-12-30 11:32:01 -05:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2016-10-25 15:02:04 -04:00
|
|
|
|
using MediaBrowser.Model.IO;
|
2013-12-30 11:32:01 -05:00
|
|
|
|
|
2014-01-28 13:37:01 -05:00
|
|
|
|
namespace MediaBrowser.Providers.Studios
|
2013-12-30 11:32:01 -05:00
|
|
|
|
{
|
2014-01-28 13:37:01 -05:00
|
|
|
|
public class StudiosImageProvider : IRemoteImageProvider
|
2013-12-30 11:32:01 -05:00
|
|
|
|
{
|
|
|
|
|
private readonly IServerConfigurationManager _config;
|
|
|
|
|
private readonly IHttpClient _httpClient;
|
|
|
|
|
private readonly IFileSystem _fileSystem;
|
|
|
|
|
|
2014-01-28 13:37:01 -05:00
|
|
|
|
public StudiosImageProvider(IServerConfigurationManager config, IHttpClient httpClient, IFileSystem fileSystem)
|
2013-12-30 11:32:01 -05:00
|
|
|
|
{
|
|
|
|
|
_config = config;
|
|
|
|
|
_httpClient = httpClient;
|
|
|
|
|
_fileSystem = fileSystem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Name
|
|
|
|
|
{
|
|
|
|
|
get { return ProviderName; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string ProviderName
|
|
|
|
|
{
|
2016-10-06 14:55:01 -04:00
|
|
|
|
get { return "Emby Designs"; }
|
2013-12-30 11:32:01 -05:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-07 17:06:13 -04:00
|
|
|
|
public bool Supports(IHasMetadata item)
|
2013-12-30 11:32:01 -05:00
|
|
|
|
{
|
|
|
|
|
return item is Studio;
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-07 17:06:13 -04:00
|
|
|
|
public IEnumerable<ImageType> GetSupportedImages(IHasMetadata item)
|
2014-01-28 13:37:01 -05:00
|
|
|
|
{
|
|
|
|
|
return new List<ImageType>
|
|
|
|
|
{
|
|
|
|
|
ImageType.Primary,
|
|
|
|
|
ImageType.Thumb
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-07 17:06:13 -04:00
|
|
|
|
public Task<IEnumerable<RemoteImageInfo>> GetImages(IHasMetadata item, CancellationToken cancellationToken)
|
2013-12-30 11:32:01 -05:00
|
|
|
|
{
|
|
|
|
|
return GetImages(item, true, true, cancellationToken);
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-07 17:06:13 -04:00
|
|
|
|
private async Task<IEnumerable<RemoteImageInfo>> GetImages(IHasMetadata item, bool posters, bool thumbs, CancellationToken cancellationToken)
|
2013-12-30 11:32:01 -05:00
|
|
|
|
{
|
|
|
|
|
var list = new List<RemoteImageInfo>();
|
|
|
|
|
|
|
|
|
|
if (posters)
|
|
|
|
|
{
|
|
|
|
|
var posterPath = Path.Combine(_config.ApplicationPaths.CachePath, "imagesbyname", "remotestudioposters.txt");
|
|
|
|
|
|
2017-04-29 02:22:33 -04:00
|
|
|
|
posterPath = await EnsurePosterList(posterPath, cancellationToken).ConfigureAwait(false);
|
2013-12-30 11:32:01 -05:00
|
|
|
|
|
|
|
|
|
list.Add(GetImage(item, posterPath, ImageType.Primary, "folder"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
|
2013-12-30 11:50:57 -05:00
|
|
|
|
if (thumbs)
|
2013-12-30 11:32:01 -05:00
|
|
|
|
{
|
|
|
|
|
var thumbsPath = Path.Combine(_config.ApplicationPaths.CachePath, "imagesbyname", "remotestudiothumbs.txt");
|
|
|
|
|
|
2017-04-29 02:22:33 -04:00
|
|
|
|
thumbsPath = await EnsureThumbsList(thumbsPath, cancellationToken).ConfigureAwait(false);
|
2013-12-30 11:32:01 -05:00
|
|
|
|
|
|
|
|
|
list.Add(GetImage(item, thumbsPath, ImageType.Thumb, "thumb"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return list.Where(i => i != null);
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-07 17:06:13 -04:00
|
|
|
|
private RemoteImageInfo GetImage(IHasMetadata item, string filename, ImageType type, string remoteFilename)
|
2013-12-30 11:32:01 -05:00
|
|
|
|
{
|
2016-10-27 14:31:41 -04:00
|
|
|
|
var list = ImageUtils.GetAvailableImages(filename, _fileSystem);
|
2013-12-30 11:32:01 -05:00
|
|
|
|
|
|
|
|
|
var match = ImageUtils.FindMatch(item, list);
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(match))
|
|
|
|
|
{
|
|
|
|
|
var url = GetUrl(match, remoteFilename);
|
|
|
|
|
|
|
|
|
|
return new RemoteImageInfo
|
|
|
|
|
{
|
|
|
|
|
ProviderName = Name,
|
|
|
|
|
Type = type,
|
|
|
|
|
Url = url
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string GetUrl(string image, string filename)
|
|
|
|
|
{
|
|
|
|
|
return string.Format("https://raw.github.com/MediaBrowser/MediaBrowser.Resources/master/images/imagesbyname/studios/{0}/{1}.jpg", image, filename);
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-29 02:22:33 -04:00
|
|
|
|
private Task<string> EnsureThumbsList(string file, CancellationToken cancellationToken)
|
2013-12-30 11:32:01 -05:00
|
|
|
|
{
|
|
|
|
|
const string url = "https://raw.github.com/MediaBrowser/MediaBrowser.Resources/master/images/imagesbyname/studiothumbs.txt";
|
|
|
|
|
|
2017-04-29 02:22:33 -04:00
|
|
|
|
return ImageUtils.EnsureList(url, file, _httpClient, _fileSystem, cancellationToken);
|
2013-12-30 11:32:01 -05:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-29 02:22:33 -04:00
|
|
|
|
private Task<string> EnsurePosterList(string file, CancellationToken cancellationToken)
|
2013-12-30 11:32:01 -05:00
|
|
|
|
{
|
|
|
|
|
const string url = "https://raw.github.com/MediaBrowser/MediaBrowser.Resources/master/images/imagesbyname/studioposters.txt";
|
|
|
|
|
|
2017-04-29 02:22:33 -04:00
|
|
|
|
return ImageUtils.EnsureList(url, file, _httpClient, _fileSystem, cancellationToken);
|
2013-12-30 11:32:01 -05:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-28 13:37:01 -05:00
|
|
|
|
public int Order
|
2013-12-30 11:32:01 -05:00
|
|
|
|
{
|
|
|
|
|
get { return 0; }
|
|
|
|
|
}
|
2014-01-28 13:37:01 -05:00
|
|
|
|
|
|
|
|
|
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
return _httpClient.GetResponse(new HttpRequestOptions
|
|
|
|
|
{
|
|
|
|
|
CancellationToken = cancellationToken,
|
|
|
|
|
Url = url,
|
2016-10-06 14:55:01 -04:00
|
|
|
|
BufferContent = false
|
2014-01-28 13:37:01 -05:00
|
|
|
|
});
|
|
|
|
|
}
|
2013-12-30 11:32:01 -05:00
|
|
|
|
}
|
|
|
|
|
}
|