Merge pull request #2292 from MediaBrowser/dev

Dev
This commit is contained in:
Luke 2016-11-16 12:59:03 -05:00 committed by GitHub
commit 1835eee101
4 changed files with 11 additions and 375 deletions

View file

@ -87,9 +87,6 @@ namespace Emby.Server.Core.Data
private IDbCommand _deleteItemValuesCommand;
private IDbCommand _saveItemValuesCommand;
private IDbCommand _deleteProviderIdsCommand;
private IDbCommand _saveProviderIdsCommand;
private IDbCommand _deleteImagesCommand;
private IDbCommand _saveImagesCommand;
@ -165,10 +162,6 @@ namespace Emby.Server.Core.Data
"create table if not exists ItemValues (ItemId GUID, Type INT, Value TEXT, CleanValue TEXT)",
"create table if not exists ProviderIds (ItemId GUID, Name TEXT, Value TEXT, PRIMARY KEY (ItemId, Name))",
// covering index
"create index if not exists Idx_ProviderIds1 on ProviderIds(ItemId,Name,Value)",
"create table if not exists Images (ItemId GUID NOT NULL, Path TEXT NOT NULL, ImageType INT NOT NULL, DateModified DATETIME, IsPlaceHolder BIT NOT NULL, SortOrder INT)",
"create index if not exists idx_Images on Images(ItemId)",
@ -182,9 +175,7 @@ namespace Emby.Server.Core.Data
createMediaStreamsTableCommand,
"create index if not exists idx_mediastreams1 on mediastreams(ItemId)",
//"drop table if exists UserDataKeys"
"create index if not exists idx_mediastreams1 on mediastreams(ItemId)"
};
@ -316,6 +307,8 @@ namespace Emby.Server.Core.Data
"drop index if exists idx_ItemValues5",
"drop index if exists idx_UserDataKeys3",
"drop table if exists UserDataKeys",
"drop table if exists ProviderIds",
"drop index if exists Idx_ProviderIds1",
"create index if not exists idx_PathTypedBaseItems on TypedBaseItems(Path)",
"create index if not exists idx_ParentIdTypedBaseItems on TypedBaseItems(ParentId)",
@ -672,17 +665,6 @@ namespace Emby.Server.Core.Data
_saveItemValuesCommand.Parameters.Add(_saveItemValuesCommand, "@Value");
_saveItemValuesCommand.Parameters.Add(_saveItemValuesCommand, "@CleanValue");
// provider ids
_deleteProviderIdsCommand = _connection.CreateCommand();
_deleteProviderIdsCommand.CommandText = "delete from ProviderIds where ItemId=@Id";
_deleteProviderIdsCommand.Parameters.Add(_deleteProviderIdsCommand, "@Id");
_saveProviderIdsCommand = _connection.CreateCommand();
_saveProviderIdsCommand.CommandText = "insert into ProviderIds (ItemId, Name, Value) values (@ItemId, @Name, @Value)";
_saveProviderIdsCommand.Parameters.Add(_saveProviderIdsCommand, "@ItemId");
_saveProviderIdsCommand.Parameters.Add(_saveProviderIdsCommand, "@Name");
_saveProviderIdsCommand.Parameters.Add(_saveProviderIdsCommand, "@Value");
// images
_deleteImagesCommand = _connection.CreateCommand();
_deleteImagesCommand.CommandText = "delete from Images where ItemId=@Id";
@ -1101,7 +1083,6 @@ namespace Emby.Server.Core.Data
}
UpdateImages(item.Id, item.ImageInfos, transaction);
UpdateProviderIds(item.Id, item.ProviderIds, transaction);
UpdateItemValues(item.Id, GetItemValuesToSave(item), transaction);
}
@ -3869,9 +3850,12 @@ namespace Emby.Server.Core.Data
}
var paramName = "@ExcludeProviderId" + index;
excludeIds.Add("(COALESCE((select value from ProviderIds where ItemId=Guid and Name = '" + pair.Key + "'), '') <> " + paramName + ")");
cmd.Parameters.Add(cmd, paramName, DbType.String).Value = pair.Value;
//excludeIds.Add("(COALESCE((select value from ProviderIds where ItemId=Guid and Name = '" + pair.Key + "'), '') <> " + paramName + ")");
excludeIds.Add("ProviderIds not like " + paramName);
cmd.Parameters.Add(cmd, paramName, DbType.String).Value = "%" + pair.Key + "=" + pair.Value + "%";
index++;
break;
}
whereClauses.Add(string.Join(" AND ", excludeIds.ToArray()));
@ -3879,20 +3863,17 @@ namespace Emby.Server.Core.Data
if (query.HasImdbId.HasValue)
{
var fn = query.HasImdbId.Value ? "<>" : "=";
whereClauses.Add("(COALESCE((select value from ProviderIds where ItemId=Guid and Name = 'Imdb'), '') " + fn + " '')");
whereClauses.Add("ProviderIds like '%imdb=%'");
}
if (query.HasTmdbId.HasValue)
{
var fn = query.HasTmdbId.Value ? "<>" : "=";
whereClauses.Add("(COALESCE((select value from ProviderIds where ItemId=Guid and Name = 'Tmdb'), '') " + fn + " '')");
whereClauses.Add("ProviderIds like '%tmdb=%'");
}
if (query.HasTvdbId.HasValue)
{
var fn = query.HasTvdbId.Value ? "<>" : "=";
whereClauses.Add("(COALESCE((select value from ProviderIds where ItemId=Guid and Name = 'Tvdb'), '') " + fn + " '')");
whereClauses.Add("ProviderIds like '%tvdb=%'");
}
if (query.AlbumNames.Length > 0)
@ -4255,11 +4236,6 @@ namespace Emby.Server.Core.Data
_deleteItemValuesCommand.Transaction = transaction;
_deleteItemValuesCommand.ExecuteNonQuery();
// Delete provider ids
_deleteProviderIdsCommand.GetParameter(0).Value = id;
_deleteProviderIdsCommand.Transaction = transaction;
_deleteProviderIdsCommand.ExecuteNonQuery();
// Delete images
_deleteImagesCommand.GetParameter(0).Value = id;
_deleteImagesCommand.Transaction = transaction;
@ -4932,53 +4908,6 @@ namespace Emby.Server.Core.Data
}
}
private void UpdateProviderIds(Guid itemId, Dictionary<string, string> values, IDbTransaction transaction)
{
if (itemId == Guid.Empty)
{
throw new ArgumentNullException("itemId");
}
if (values == null)
{
throw new ArgumentNullException("values");
}
// Just in case there might be case-insensitive duplicates, strip them out now
var newValues = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
foreach (var pair in values)
{
newValues[pair.Key] = pair.Value;
}
CheckDisposed();
// First delete
_deleteProviderIdsCommand.GetParameter(0).Value = itemId;
_deleteProviderIdsCommand.Transaction = transaction;
_deleteProviderIdsCommand.ExecuteNonQuery();
foreach (var pair in newValues)
{
if (string.IsNullOrWhiteSpace(pair.Key))
{
continue;
}
if (string.IsNullOrWhiteSpace(pair.Value))
{
continue;
}
_saveProviderIdsCommand.GetParameter(0).Value = itemId;
_saveProviderIdsCommand.GetParameter(1).Value = pair.Key;
_saveProviderIdsCommand.GetParameter(2).Value = pair.Value;
_saveProviderIdsCommand.Transaction = transaction;
_saveProviderIdsCommand.ExecuteNonQuery();
}
}
private void UpdateItemValues(Guid itemId, List<Tuple<int, string>> values, IDbTransaction transaction)
{
if (itemId == Guid.Empty)

View file

@ -1,146 +0,0 @@
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Providers;
using MediaBrowser.Providers.Genres;
using MediaBrowser.Providers.ImagesByName;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.IO;
using MediaBrowser.Controller.IO;
using MediaBrowser.Model.IO;
namespace MediaBrowser.Providers.GameGenres
{
public class GameGenreImageProvider : IRemoteImageProvider
{
private readonly IServerConfigurationManager _config;
private readonly IHttpClient _httpClient;
private readonly IFileSystem _fileSystem;
private readonly SemaphoreSlim _listResourcePool = new SemaphoreSlim(1, 1);
public GameGenreImageProvider(IServerConfigurationManager config, IHttpClient httpClient, IFileSystem fileSystem)
{
_config = config;
_httpClient = httpClient;
_fileSystem = fileSystem;
}
public string Name
{
get { return ProviderName; }
}
public static string ProviderName
{
get { return "Emby Designs"; }
}
public bool Supports(IHasImages item)
{
return item is GameGenre;
}
public IEnumerable<ImageType> GetSupportedImages(IHasImages item)
{
return new List<ImageType>
{
ImageType.Primary,
ImageType.Thumb
};
}
public Task<IEnumerable<RemoteImageInfo>> GetImages(IHasImages item, CancellationToken cancellationToken)
{
return GetImages(item, true, true, cancellationToken);
}
private async Task<IEnumerable<RemoteImageInfo>> GetImages(IHasImages item, bool posters, bool thumbs, CancellationToken cancellationToken)
{
var list = new List<RemoteImageInfo>();
if (posters)
{
var posterPath = Path.Combine(_config.ApplicationPaths.CachePath, "imagesbyname", "remotegamegenreposters.txt");
await EnsurePosterList(posterPath, cancellationToken).ConfigureAwait(false);
list.Add(GetImage(item, posterPath, ImageType.Primary, "folder"));
}
cancellationToken.ThrowIfCancellationRequested();
if (thumbs)
{
var thumbsPath = Path.Combine(_config.ApplicationPaths.CachePath, "imagesbyname", "remotegamegenrethumbs.txt");
await EnsureThumbsList(thumbsPath, cancellationToken).ConfigureAwait(false);
list.Add(GetImage(item, thumbsPath, ImageType.Thumb, "thumb"));
}
return list.Where(i => i != null);
}
private RemoteImageInfo GetImage(IHasImages item, string filename, ImageType type, string remoteFilename)
{
var list = ImageUtils.GetAvailableImages(filename, _fileSystem);
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/gamegenres/{0}/{1}.jpg", image, filename);
}
private Task EnsureThumbsList(string file, CancellationToken cancellationToken)
{
const string url = "https://raw.github.com/MediaBrowser/MediaBrowser.Resources/master/images/imagesbyname/gamegenrethumbs.txt";
return ImageUtils.EnsureList(url, file, _httpClient, _fileSystem, _listResourcePool, cancellationToken);
}
private Task EnsurePosterList(string file, CancellationToken cancellationToken)
{
const string url = "https://raw.github.com/MediaBrowser/MediaBrowser.Resources/master/images/imagesbyname/gamegenreposters.txt";
return ImageUtils.EnsureList(url, file, _httpClient, _fileSystem, _listResourcePool, cancellationToken);
}
public int Order
{
get { return 0; }
}
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
{
return _httpClient.GetResponse(new HttpRequestOptions
{
CancellationToken = cancellationToken,
Url = url,
BufferContent = false
});
}
}
}

View file

@ -1,145 +0,0 @@
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Providers;
using MediaBrowser.Providers.ImagesByName;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.IO;
using MediaBrowser.Controller.IO;
using MediaBrowser.Model.IO;
namespace MediaBrowser.Providers.Genres
{
public class GenreImageProvider : IRemoteImageProvider
{
private readonly IServerConfigurationManager _config;
private readonly IHttpClient _httpClient;
private readonly IFileSystem _fileSystem;
private readonly SemaphoreSlim _listResourcePool = new SemaphoreSlim(1, 1);
public GenreImageProvider(IServerConfigurationManager config, IHttpClient httpClient, IFileSystem fileSystem)
{
_config = config;
_httpClient = httpClient;
_fileSystem = fileSystem;
}
public string Name
{
get { return ProviderName; }
}
public static string ProviderName
{
get { return "Emby Designs"; }
}
public bool Supports(IHasImages item)
{
return item is Genre;
}
public IEnumerable<ImageType> GetSupportedImages(IHasImages item)
{
return new List<ImageType>
{
ImageType.Primary,
ImageType.Thumb
};
}
public Task<IEnumerable<RemoteImageInfo>> GetImages(IHasImages item, CancellationToken cancellationToken)
{
return GetImages(item, true, true, cancellationToken);
}
private async Task<IEnumerable<RemoteImageInfo>> GetImages(IHasImages item, bool posters, bool thumbs, CancellationToken cancellationToken)
{
var list = new List<RemoteImageInfo>();
if (posters)
{
var posterPath = Path.Combine(_config.ApplicationPaths.CachePath, "imagesbyname", "remotegenreposters.txt");
await EnsurePosterList(posterPath, cancellationToken).ConfigureAwait(false);
list.Add(GetImage(item, posterPath, ImageType.Primary, "folder"));
}
cancellationToken.ThrowIfCancellationRequested();
if (thumbs)
{
var thumbsPath = Path.Combine(_config.ApplicationPaths.CachePath, "imagesbyname", "remotegenrethumbs.txt");
await EnsureThumbsList(thumbsPath, cancellationToken).ConfigureAwait(false);
list.Add(GetImage(item, thumbsPath, ImageType.Thumb, "thumb"));
}
return list.Where(i => i != null);
}
private RemoteImageInfo GetImage(IHasImages item, string filename, ImageType type, string remoteFilename)
{
var list = ImageUtils.GetAvailableImages(filename, _fileSystem);
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/genres/{0}/{1}.jpg", image, filename);
}
private Task EnsureThumbsList(string file, CancellationToken cancellationToken)
{
const string url = "https://raw.github.com/MediaBrowser/MediaBrowser.Resources/master/images/imagesbyname/genrethumbs.txt";
return ImageUtils.EnsureList(url, file, _httpClient, _fileSystem, _listResourcePool, cancellationToken);
}
private Task EnsurePosterList(string file, CancellationToken cancellationToken)
{
const string url = "https://raw.github.com/MediaBrowser/MediaBrowser.Resources/master/images/imagesbyname/genreposters.txt";
return ImageUtils.EnsureList(url, file, _httpClient, _fileSystem, _listResourcePool, cancellationToken);
}
public int Order
{
get { return 0; }
}
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
{
return _httpClient.GetResponse(new HttpRequestOptions
{
CancellationToken = cancellationToken,
Url = url,
BufferContent = false
});
}
}
}

View file

@ -80,8 +80,6 @@
<Compile Include="Movies\MovieDbSearch.cs" />
<Compile Include="Movies\MovieMetadataService.cs" />
<Compile Include="Movies\TmdbSettings.cs" />
<Compile Include="GameGenres\GameGenreImageProvider.cs" />
<Compile Include="Genres\GenreImageProvider.cs" />
<Compile Include="ImagesByName\ImageUtils.cs" />
<Compile Include="MediaInfo\AudioImageProvider.cs" />
<Compile Include="MediaInfo\VideoImageProvider.cs" />