2014-06-14 23:13:09 +00:00
|
|
|
|
using MediaBrowser.Common.Net;
|
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
using MediaBrowser.Model.Providers;
|
|
|
|
|
using MediaBrowser.Providers.Genres;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2014-09-06 04:21:23 +00:00
|
|
|
|
using System.Linq;
|
2014-06-14 23:13:09 +00:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Providers.FolderImages
|
|
|
|
|
{
|
2014-09-11 01:57:11 +00:00
|
|
|
|
public class DefaultImageProvider : IRemoteImageProvider, IHasItemChangeMonitor
|
2014-06-14 23:13:09 +00:00
|
|
|
|
{
|
|
|
|
|
private readonly IHttpClient _httpClient;
|
|
|
|
|
|
|
|
|
|
public DefaultImageProvider(IHttpClient httpClient)
|
|
|
|
|
{
|
|
|
|
|
_httpClient = httpClient;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerable<ImageType> GetSupportedImages(IHasImages item)
|
|
|
|
|
{
|
|
|
|
|
return new List<ImageType>
|
|
|
|
|
{
|
|
|
|
|
ImageType.Primary,
|
|
|
|
|
ImageType.Thumb
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<IEnumerable<RemoteImageInfo>> GetImages(IHasImages item, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
var view = item as UserView;
|
|
|
|
|
|
|
|
|
|
if (view != null)
|
|
|
|
|
{
|
|
|
|
|
return GetImages(view.ViewType, cancellationToken);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var folder = (ICollectionFolder)item;
|
|
|
|
|
return GetImages(folder.CollectionType, cancellationToken);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Task<IEnumerable<RemoteImageInfo>> GetImages(string viewType, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
var url = GetImageUrl(viewType);
|
|
|
|
|
|
|
|
|
|
return Task.FromResult<IEnumerable<RemoteImageInfo>>(new List<RemoteImageInfo>
|
|
|
|
|
{
|
|
|
|
|
new RemoteImageInfo
|
|
|
|
|
{
|
|
|
|
|
ProviderName = Name,
|
|
|
|
|
Url = url,
|
|
|
|
|
Type = ImageType.Primary
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
new RemoteImageInfo
|
|
|
|
|
{
|
|
|
|
|
ProviderName = Name,
|
|
|
|
|
Url = url,
|
|
|
|
|
Type = ImageType.Thumb
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string GetImageUrl(string viewType)
|
|
|
|
|
{
|
|
|
|
|
const string urlPrefix = "https://raw.githubusercontent.com/MediaBrowser/MediaBrowser.Resources/master/images/folders/";
|
|
|
|
|
|
|
|
|
|
if (string.Equals(viewType, CollectionType.Books, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2014-09-06 17:46:09 +00:00
|
|
|
|
return urlPrefix + "books.png";
|
2014-06-14 23:13:09 +00:00
|
|
|
|
}
|
|
|
|
|
if (string.Equals(viewType, CollectionType.Games, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2014-09-06 17:46:09 +00:00
|
|
|
|
return urlPrefix + "games.png";
|
2014-06-14 23:13:09 +00:00
|
|
|
|
}
|
|
|
|
|
if (string.Equals(viewType, CollectionType.Music, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2014-09-06 17:46:09 +00:00
|
|
|
|
return urlPrefix + "music.png";
|
2014-06-14 23:13:09 +00:00
|
|
|
|
}
|
|
|
|
|
if (string.Equals(viewType, CollectionType.Photos, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2014-09-06 17:46:09 +00:00
|
|
|
|
return urlPrefix + "photos.png";
|
2014-06-14 23:13:09 +00:00
|
|
|
|
}
|
|
|
|
|
if (string.Equals(viewType, CollectionType.TvShows, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2014-09-06 17:46:09 +00:00
|
|
|
|
return urlPrefix + "tv.png";
|
2014-06-14 23:13:09 +00:00
|
|
|
|
}
|
|
|
|
|
if (string.Equals(viewType, CollectionType.Channels, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2014-09-06 17:46:09 +00:00
|
|
|
|
return urlPrefix + "channels.png";
|
2014-06-14 23:13:09 +00:00
|
|
|
|
}
|
|
|
|
|
if (string.Equals(viewType, CollectionType.LiveTv, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2014-09-06 17:46:09 +00:00
|
|
|
|
return urlPrefix + "livetv.png";
|
2014-06-14 23:13:09 +00:00
|
|
|
|
}
|
|
|
|
|
if (string.Equals(viewType, CollectionType.Movies, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2014-09-06 17:46:09 +00:00
|
|
|
|
return urlPrefix + "movies.png";
|
2014-06-14 23:13:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-09-06 17:46:09 +00:00
|
|
|
|
return urlPrefix + "generic.png";
|
2014-06-14 23:13:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Name
|
|
|
|
|
{
|
|
|
|
|
get { return "Default Image Provider"; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool Supports(IHasImages item)
|
|
|
|
|
{
|
2014-10-29 22:01:02 +00:00
|
|
|
|
var view = item as UserView;
|
|
|
|
|
|
|
|
|
|
if (view != null)
|
|
|
|
|
{
|
|
|
|
|
return !view.UserId.HasValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return item is ICollectionFolder;
|
2014-06-14 23:13:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
return _httpClient.GetResponse(new HttpRequestOptions
|
|
|
|
|
{
|
|
|
|
|
CancellationToken = cancellationToken,
|
|
|
|
|
Url = url,
|
|
|
|
|
ResourcePool = GenreImageProvider.ImageDownloadResourcePool
|
|
|
|
|
});
|
|
|
|
|
}
|
2014-09-06 04:21:23 +00:00
|
|
|
|
|
2014-09-11 01:57:11 +00:00
|
|
|
|
public bool HasChanged(IHasMetadata item, MetadataStatus status, IDirectoryService directoryService)
|
2014-09-06 04:21:23 +00:00
|
|
|
|
{
|
|
|
|
|
return GetSupportedImages(item).Any(i => !item.HasImage(i));
|
|
|
|
|
}
|
2014-06-14 23:13:09 +00:00
|
|
|
|
}
|
|
|
|
|
}
|