2015-08-28 04:19:08 +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;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Providers.Folders
|
|
|
|
|
{
|
|
|
|
|
public class DefaultImageProvider : IRemoteImageProvider, IHasItemChangeMonitor
|
|
|
|
|
{
|
|
|
|
|
private readonly IHttpClient _httpClient;
|
|
|
|
|
|
|
|
|
|
public DefaultImageProvider(IHttpClient httpClient)
|
|
|
|
|
{
|
|
|
|
|
_httpClient = httpClient;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerable<ImageType> GetSupportedImages(IHasImages item)
|
|
|
|
|
{
|
|
|
|
|
return new List<ImageType>
|
|
|
|
|
{
|
2016-03-02 03:59:23 +00:00
|
|
|
|
ImageType.Primary
|
2015-08-28 04:19:08 +00:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
var list = new List<RemoteImageInfo>();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(url))
|
|
|
|
|
{
|
2015-11-23 16:02:48 +00:00
|
|
|
|
list.AddRange(new List<RemoteImageInfo>{
|
2015-08-28 04:19:08 +00:00
|
|
|
|
new RemoteImageInfo
|
|
|
|
|
{
|
|
|
|
|
ProviderName = Name,
|
|
|
|
|
Url = url,
|
|
|
|
|
Type = ImageType.Primary
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Task.FromResult<IEnumerable<RemoteImageInfo>>(list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string GetImageUrl(string viewType)
|
|
|
|
|
{
|
|
|
|
|
const string urlPrefix = "https://raw.githubusercontent.com/MediaBrowser/Emby.Resources/master/images/folders/";
|
|
|
|
|
|
|
|
|
|
if (string.Equals(viewType, CollectionType.Books, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2015-11-03 04:34:47 +00:00
|
|
|
|
return urlPrefix + "books.jpg";
|
2015-08-28 04:19:08 +00:00
|
|
|
|
}
|
|
|
|
|
if (string.Equals(viewType, CollectionType.Games, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2015-11-03 04:34:47 +00:00
|
|
|
|
return urlPrefix + "games.jpg";
|
2015-08-28 04:19:08 +00:00
|
|
|
|
}
|
|
|
|
|
if (string.Equals(viewType, CollectionType.Music, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2016-03-30 01:33:08 +00:00
|
|
|
|
//return urlPrefix + "music.jpg";
|
2015-08-28 04:19:08 +00:00
|
|
|
|
}
|
|
|
|
|
if (string.Equals(viewType, CollectionType.Photos, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
//return urlPrefix + "photos.png";
|
|
|
|
|
}
|
|
|
|
|
if (string.Equals(viewType, CollectionType.TvShows, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2015-12-27 18:48:20 +00:00
|
|
|
|
//return urlPrefix + "tv.jpg";
|
2015-08-28 04:19:08 +00:00
|
|
|
|
}
|
|
|
|
|
if (string.Equals(viewType, CollectionType.Channels, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2015-11-03 04:34:47 +00:00
|
|
|
|
return urlPrefix + "channels.jpg";
|
2015-08-28 04:19:08 +00:00
|
|
|
|
}
|
|
|
|
|
if (string.Equals(viewType, CollectionType.LiveTv, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return urlPrefix + "livetv.png";
|
|
|
|
|
}
|
|
|
|
|
if (string.Equals(viewType, CollectionType.Movies, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2015-12-27 18:48:20 +00:00
|
|
|
|
//return urlPrefix + "movies.jpg";
|
2015-08-28 04:19:08 +00:00
|
|
|
|
}
|
2015-08-28 15:02:22 +00:00
|
|
|
|
if (string.Equals(viewType, CollectionType.Playlists, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2015-11-03 04:34:47 +00:00
|
|
|
|
return urlPrefix + "playlists.jpg";
|
2015-08-28 15:02:22 +00:00
|
|
|
|
}
|
2015-09-01 14:01:59 +00:00
|
|
|
|
if (string.Equals(viewType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2016-03-30 01:33:08 +00:00
|
|
|
|
//return urlPrefix + "homevideos.jpg";
|
2015-09-01 14:01:59 +00:00
|
|
|
|
}
|
|
|
|
|
if (string.Equals(viewType, CollectionType.MusicVideos, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2015-11-03 04:34:47 +00:00
|
|
|
|
return urlPrefix + "musicvideos.jpg";
|
2015-09-01 14:01:59 +00:00
|
|
|
|
}
|
|
|
|
|
if (string.Equals(viewType, CollectionType.BoxSets, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2016-02-27 04:38:43 +00:00
|
|
|
|
//return urlPrefix + "collections.jpg";
|
2015-09-01 14:01:59 +00:00
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrWhiteSpace(viewType))
|
|
|
|
|
{
|
2015-11-03 04:34:47 +00:00
|
|
|
|
return urlPrefix + "generic.jpg";
|
2015-09-01 14:01:59 +00:00
|
|
|
|
}
|
2015-08-28 04:19:08 +00:00
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Name
|
|
|
|
|
{
|
|
|
|
|
get { return "Default Image Provider"; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool Supports(IHasImages item)
|
|
|
|
|
{
|
|
|
|
|
var view = item as UserView;
|
|
|
|
|
|
|
|
|
|
if (view != null)
|
|
|
|
|
{
|
2015-10-16 05:36:16 +00:00
|
|
|
|
return !string.IsNullOrWhiteSpace(GetImageUrl(view.ViewType));
|
2015-08-28 04:19:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-10-16 05:36:16 +00:00
|
|
|
|
var folder = item as ICollectionFolder;
|
|
|
|
|
|
|
|
|
|
if (folder != null)
|
|
|
|
|
{
|
|
|
|
|
return !string.IsNullOrWhiteSpace(GetImageUrl(folder.CollectionType));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
2015-08-28 04:19:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
return _httpClient.GetResponse(new HttpRequestOptions
|
|
|
|
|
{
|
|
|
|
|
CancellationToken = cancellationToken,
|
|
|
|
|
Url = url,
|
|
|
|
|
ResourcePool = GenreImageProvider.ImageDownloadResourcePool
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-08 18:32:38 +00:00
|
|
|
|
public bool HasChanged(IHasMetadata item, IDirectoryService directoryService)
|
2015-08-28 04:19:08 +00:00
|
|
|
|
{
|
|
|
|
|
return GetSupportedImages(item).Any(i => !item.HasImage(i));
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-11-23 16:04:57 +00:00
|
|
|
|
}
|