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
|
|
|
|
|
{
|
2015-03-13 19:37:19 +00:00
|
|
|
|
public class DefaultImageProvider : IRemoteImageProvider, IHasItemChangeMonitor, IHasOrder
|
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)
|
|
|
|
|
{
|
2015-03-14 04:50:23 +00:00
|
|
|
|
return GetImages(view.ViewType, view.ParentId != Guid.Empty, cancellationToken);
|
2014-06-14 23:13:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var folder = (ICollectionFolder)item;
|
2015-03-13 19:16:34 +00:00
|
|
|
|
return GetImages(folder.CollectionType, false, cancellationToken);
|
2014-06-14 23:13:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-03-14 04:50:23 +00:00
|
|
|
|
private Task<IEnumerable<RemoteImageInfo>> GetImages(string viewType, bool isSubView, CancellationToken cancellationToken)
|
2014-06-14 23:13:09 +00:00
|
|
|
|
{
|
2015-03-14 04:50:23 +00:00
|
|
|
|
var url = GetImageUrl(viewType, isSubView);
|
2015-03-13 19:16:34 +00:00
|
|
|
|
var list = new List<RemoteImageInfo>();
|
2014-06-14 23:13:09 +00:00
|
|
|
|
|
2015-03-13 19:16:34 +00:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(url))
|
2014-06-14 23:13:09 +00:00
|
|
|
|
{
|
2015-03-13 19:16:34 +00:00
|
|
|
|
list.AddRange(new List<RemoteImageInfo>
|
|
|
|
|
{
|
|
|
|
|
new RemoteImageInfo
|
|
|
|
|
{
|
|
|
|
|
ProviderName = Name,
|
|
|
|
|
Url = url,
|
|
|
|
|
Type = ImageType.Primary
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
new RemoteImageInfo
|
|
|
|
|
{
|
|
|
|
|
ProviderName = Name,
|
|
|
|
|
Url = url,
|
|
|
|
|
Type = ImageType.Thumb
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Task.FromResult<IEnumerable<RemoteImageInfo>>(list);
|
2014-06-14 23:13:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-03-14 04:50:23 +00:00
|
|
|
|
private string GetImageUrl(string viewType, bool isSubView)
|
2014-06-14 23:13:09 +00:00
|
|
|
|
{
|
|
|
|
|
const string urlPrefix = "https://raw.githubusercontent.com/MediaBrowser/MediaBrowser.Resources/master/images/folders/";
|
|
|
|
|
|
|
|
|
|
if (string.Equals(viewType, CollectionType.Books, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2015-03-16 01:48:25 +00:00
|
|
|
|
return null;
|
2014-06-14 23:13:09 +00:00
|
|
|
|
}
|
|
|
|
|
if (string.Equals(viewType, CollectionType.Games, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2015-03-16 01:48:25 +00:00
|
|
|
|
return null;
|
2014-06-14 23:13:09 +00:00
|
|
|
|
}
|
|
|
|
|
if (string.Equals(viewType, CollectionType.Music, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2015-03-16 01:48:25 +00:00
|
|
|
|
return null;
|
2014-06-14 23:13:09 +00:00
|
|
|
|
}
|
|
|
|
|
if (string.Equals(viewType, CollectionType.Photos, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2015-03-16 01:48:25 +00:00
|
|
|
|
return null;
|
2014-06-14 23:13:09 +00:00
|
|
|
|
}
|
|
|
|
|
if (string.Equals(viewType, CollectionType.TvShows, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2015-03-16 01:48:25 +00:00
|
|
|
|
return null;
|
2014-06-14 23:13:09 +00:00
|
|
|
|
}
|
|
|
|
|
if (string.Equals(viewType, CollectionType.Channels, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2015-03-16 01:48:25 +00:00
|
|
|
|
return null;
|
2014-06-14 23:13:09 +00:00
|
|
|
|
}
|
|
|
|
|
if (string.Equals(viewType, CollectionType.LiveTv, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2015-03-16 01:48:25 +00:00
|
|
|
|
return null;
|
2014-06-14 23:13:09 +00:00
|
|
|
|
}
|
|
|
|
|
if (string.Equals(viewType, CollectionType.Movies, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2015-03-16 01:48:25 +00:00
|
|
|
|
return null;
|
2014-06-14 23:13:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-03-14 04:50:23 +00:00
|
|
|
|
if (isSubView)
|
2015-03-13 19:16:34 +00:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
2015-03-13 19:37:19 +00:00
|
|
|
|
return item is ICollectionFolder || item is UserView;
|
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));
|
|
|
|
|
}
|
2015-03-13 19:37:19 +00:00
|
|
|
|
|
|
|
|
|
public int Order
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
// Run after the dynamic image provider
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-06-14 23:13:09 +00:00
|
|
|
|
}
|
|
|
|
|
}
|