Skip to content

Commit

Permalink
Merge pull request #3201 from MediaBrowser/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
LukePulverenti authored Mar 13, 2018
2 parents 178de6a + aff82d4 commit cbb30d8
Show file tree
Hide file tree
Showing 28 changed files with 232 additions and 146 deletions.
4 changes: 2 additions & 2 deletions Emby.Drawing.Skia/SkiaEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public ImageFormat[] SupportedOutputFormats
{
get
{
return new[] { ImageFormat.Webp, ImageFormat.Gif, ImageFormat.Jpg, ImageFormat.Png, ImageFormat.Bmp };
return new[] { ImageFormat.Webp, ImageFormat.Jpg, ImageFormat.Png };
}
}

Expand Down Expand Up @@ -290,7 +290,7 @@ internal static SKBitmap Decode(string path, bool forceCleanBitmap, IFileSystem
{
// decode
codec.GetPixels(bitmap.Info, bitmap.GetPixels());

origin = codec.Origin;
}
else
Expand Down
9 changes: 6 additions & 3 deletions Emby.Drawing/ImageProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public ImageFormat[] GetSupportedImageOutputFormats()
return _imageEncoder.SupportedOutputFormats;
}

private readonly string[] TransparentImageTypes = new string[] { ".png", ".webp" };
private readonly string[] TransparentImageTypes = new string[] { ".png", ".webp", ".gif" };
public bool SupportsTransparency(string path)
{
return TransparentImageTypes.Contains(Path.GetExtension(path) ?? string.Empty);
Expand All @@ -196,6 +196,7 @@ public async Task<Tuple<string, string, DateTime>> ProcessImage(ImageProcessingO

var originalImagePath = originalImage.Path;
var dateModified = originalImage.DateModified;
var originalImageSize = originalImage.Width > 0 && originalImage.Height > 0 ? new ImageSize(originalImage.Width, originalImage.Height) : (ImageSize?)null;

if (!_imageEncoder.SupportsImageEncoding)
{
Expand Down Expand Up @@ -225,6 +226,8 @@ public async Task<Tuple<string, string, DateTime>> ProcessImage(ImageProcessingO
originalImagePath = tuple.Item1;
dateModified = tuple.Item2;
requiresTransparency = tuple.Item3;
// TODO: Get this info
originalImageSize = null;
}

var photo = item as Photo;
Expand All @@ -248,7 +251,7 @@ public async Task<Tuple<string, string, DateTime>> ProcessImage(ImageProcessingO
}
}

if (options.HasDefaultOptions(originalImagePath) && (!autoOrient || !options.RequiresAutoOrientation))
if (options.HasDefaultOptions(originalImagePath, originalImageSize) && (!autoOrient || !options.RequiresAutoOrientation))
{
// Just spit out the original file if all the options are default
return new Tuple<string, string, DateTime>(originalImagePath, MimeTypes.GetMimeType(originalImagePath), dateModified);
Expand Down Expand Up @@ -329,7 +332,7 @@ private ImageFormat GetOutputFormat(ImageFormat[] clientSupportedFormats, bool r
}

// If transparency is needed and webp isn't supported, than png is the only option
if (requiresTransparency)
if (requiresTransparency && clientSupportedFormats.Contains(ImageFormat.Png))
{
return ImageFormat.Png;
}
Expand Down
12 changes: 3 additions & 9 deletions Emby.Server.Implementations/Data/SqliteItemRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2300,6 +2300,8 @@ private bool HasField(InternalItemsQuery query, ItemFields name)

switch (name)
{
case ItemFields.Tags:
return fields.Contains(name) || HasProgramAttributes(query);
case ItemFields.HomePageUrl:
case ItemFields.CustomRating:
case ItemFields.ProductionLocations:
Expand All @@ -2308,7 +2310,6 @@ private bool HasField(InternalItemsQuery query, ItemFields name)
case ItemFields.Taglines:
case ItemFields.SortName:
case ItemFields.Studios:
case ItemFields.Tags:
case ItemFields.ThemeSongIds:
case ItemFields.ThemeVideoIds:
case ItemFields.DateCreated:
Expand Down Expand Up @@ -2504,14 +2505,7 @@ private string[] GetFinalColumnsToSelect(InternalItemsQuery query, string[] star
}
}

if (HasProgramAttributes(query))
{
if (!list.Contains("Tags", StringComparer.OrdinalIgnoreCase))
{
list.Add("Tags");
}
}
else
if (!HasProgramAttributes(query))
{
list.Remove("IsKids");
list.Remove("IsMovie");
Expand Down
2 changes: 1 addition & 1 deletion Emby.Server.Implementations/Library/MediaSourceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public async Task<IEnumerable<MediaSourceInfo>> GetPlayackMediaSources(string id

var mediaSources = GetStaticMediaSources(hasMediaSources, enablePathSubstitution, user);

if (mediaSources.Count == 1 && mediaSources[0].MediaStreams.Count == 0 && mediaSources[0].Type != MediaSourceType.Placeholder)
if (mediaSources.Count == 1 && mediaSources[0].Type != MediaSourceType.Placeholder && !mediaSources[0].MediaStreams.Any(i => i.Type == MediaStreamType.Audio || i.Type == MediaStreamType.Video))
{
await item.RefreshMetadata(new MediaBrowser.Controller.Providers.MetadataRefreshOptions(_fileSystem)
{
Expand Down
12 changes: 8 additions & 4 deletions Emby.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,6 @@ private ProgramInfo GetProgram(string channelId, ScheduleDirect.Program programI
DateTime endAt = startAt.AddSeconds(programInfo.duration);
ProgramAudio audioType = ProgramAudio.Stereo;

bool repeat = programInfo.@new == null;

var programId = programInfo.programID ?? string.Empty;

string newID = programId + "T" + startAt.Ticks + "C" + channelId;
Expand Down Expand Up @@ -296,14 +294,17 @@ private ProgramInfo GetProgram(string channelId, ScheduleDirect.Program programI
CommunityRating = null,
EpisodeTitle = episodeTitle,
Audio = audioType,
IsRepeat = repeat,
//IsNew = programInfo.@new ?? false,
IsRepeat = programInfo.repeat,
IsSeries = string.Equals(details.entityType, "episode", StringComparison.OrdinalIgnoreCase),
ImageUrl = details.primaryImage,
ThumbImageUrl = details.thumbImage,
IsKids = string.Equals(details.audience, "children", StringComparison.OrdinalIgnoreCase),
IsSports = string.Equals(details.entityType, "sports", StringComparison.OrdinalIgnoreCase),
IsMovie = IsMovie(details),
Etag = programInfo.md5
Etag = programInfo.md5,
IsLive = string.Equals(programInfo.liveTapeDelay, "live", StringComparison.OrdinalIgnoreCase),
IsPremiere = programInfo.premiere
};

var showId = programId;
Expand Down Expand Up @@ -1116,6 +1117,9 @@ public class Program
public List<Rating> ratings { get; set; }
public bool? @new { get; set; }
public Multipart multipart { get; set; }
public string liveTapeDelay { get; set; }
public bool premiere { get; set; }
public bool repeat { get; set; }
}


Expand Down
56 changes: 40 additions & 16 deletions MediaBrowser.Api/Images/ImageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -660,37 +660,61 @@ private ImageFormat[] GetOutputFormats(ImageRequest request)
private ImageFormat[] GetClientSupportedFormats()
{
//Logger.Debug("Request types: {0}", string.Join(",", Request.AcceptTypes ?? new string[] { }));
var supportsWebP = (Request.AcceptTypes ?? new string[] { }).Contains("image/webp", StringComparer.OrdinalIgnoreCase);
var supportedFormats = (Request.AcceptTypes ?? new string[] { }).Select(i => i.Split(';')[0]).ToArray();
var acceptParam = Request.QueryString["accept"];

var userAgent = Request.UserAgent ?? string.Empty;

if (!supportsWebP)
{
if (string.Equals(Request.QueryString["accept"], "webp", StringComparison.OrdinalIgnoreCase))
{
supportsWebP = true;
}
}
var supportsWebP = SupportsFormat(supportedFormats, acceptParam, "webp", false);

if (!supportsWebP)
{
var userAgent = Request.UserAgent ?? string.Empty;
if (userAgent.IndexOf("crosswalk", StringComparison.OrdinalIgnoreCase) != -1 &&
userAgent.IndexOf("android", StringComparison.OrdinalIgnoreCase) != -1)
{
supportsWebP = true;
}
}

var formats = new List<ImageFormat>(4);

if (supportsWebP)
{
// Not displaying properly on iOS
if (userAgent.IndexOf("cfnetwork", StringComparison.OrdinalIgnoreCase) == -1)
{
return new[] { ImageFormat.Webp, ImageFormat.Jpg, ImageFormat.Png };
}
formats.Add(ImageFormat.Webp);
}

if (SupportsFormat(supportedFormats, acceptParam, "jpg", true))
{
formats.Add(ImageFormat.Jpg);
}

if (SupportsFormat(supportedFormats, acceptParam, "png", true))
{
formats.Add(ImageFormat.Png);
}

if (SupportsFormat(supportedFormats, acceptParam, "gif", true))
{
formats.Add(ImageFormat.Gif);
}

return formats.ToArray();
}

private bool SupportsFormat(string[] requestAcceptTypes, string acceptParam, string format, bool acceptAll)
{
var mimeType = "image/" + format;

if (requestAcceptTypes.Contains(mimeType))
{
return true;
}

if (acceptAll && requestAcceptTypes.Contains("*/*"))
{
return true;
}

return new[] { ImageFormat.Jpg, ImageFormat.Png };
return string.Equals(Request.QueryString["accept"], format, StringComparison.OrdinalIgnoreCase);
}

/// <summary>
Expand Down
23 changes: 22 additions & 1 deletion MediaBrowser.Api/LiveTv/LiveTvService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
using MediaBrowser.Model.Services;
using MediaBrowser.Model.System;
using MediaBrowser.Model.Extensions;
using MediaBrowser.Model.Cryptography;
using System.Text;

namespace MediaBrowser.Api.LiveTv
{
Expand Down Expand Up @@ -605,6 +607,7 @@ public class AddListingProvider : ListingsProviderInfo, IReturn<ListingsProvider
{
public bool ValidateLogin { get; set; }
public bool ValidateListings { get; set; }
public string Pw { get; set; }
}

[Route("/LiveTv/ListingProviders", "DELETE", Summary = "Deletes a listing provider")]
Expand Down Expand Up @@ -711,8 +714,9 @@ public class LiveTvService : BaseApiService
private readonly IAuthorizationContext _authContext;
private readonly ISessionContext _sessionContext;
private readonly IEnvironmentInfo _environment;
private ICryptoProvider _cryptographyProvider;

public LiveTvService(ILiveTvManager liveTvManager, IUserManager userManager, IServerConfigurationManager config, IHttpClient httpClient, ILibraryManager libraryManager, IDtoService dtoService, IFileSystem fileSystem, IAuthorizationContext authContext, ISessionContext sessionContext, IEnvironmentInfo environment)
public LiveTvService(ICryptoProvider crypto, ILiveTvManager liveTvManager, IUserManager userManager, IServerConfigurationManager config, IHttpClient httpClient, ILibraryManager libraryManager, IDtoService dtoService, IFileSystem fileSystem, IAuthorizationContext authContext, ISessionContext sessionContext, IEnvironmentInfo environment)
{
_liveTvManager = liveTvManager;
_userManager = userManager;
Expand All @@ -724,6 +728,7 @@ public LiveTvService(ILiveTvManager liveTvManager, IUserManager userManager, ISe
_authContext = authContext;
_sessionContext = sessionContext;
_environment = environment;
_cryptographyProvider = crypto;
}

public object Get(GetTunerHostTypes request)
Expand Down Expand Up @@ -869,10 +874,26 @@ private void AssertUserCanManageLiveTv()

public async Task<object> Post(AddListingProvider request)
{
if (request.Pw != null)
{
request.Password = GetHashedString(request.Pw);
}

request.Pw = null;

var result = await _liveTvManager.SaveListingProvider(request, request.ValidateLogin, request.ValidateListings).ConfigureAwait(false);
return ToOptimizedResult(result);
}

/// <summary>
/// Gets the hashed string.
/// </summary>
private string GetHashedString(string str)
{
// legacy
return BitConverter.ToString(_cryptographyProvider.ComputeSHA1(Encoding.UTF8.GetBytes(str))).Replace("-", string.Empty).ToLower();
}

public void Delete(DeleteListingProvider request)
{
_liveTvManager.DeleteListingsProvider(request.Id);
Expand Down
21 changes: 14 additions & 7 deletions MediaBrowser.Controller/Drawing/ImageProcessingOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public ImageProcessingOptions()
public string ForegroundLayer { get; set; }
public bool RequiresAutoOrientation { get; set; }

public bool HasDefaultOptions(string originalImagePath)
private bool HasDefaultOptions(string originalImagePath)
{
return HasDefaultOptionsWithoutSize(originalImagePath) &&
!Width.HasValue &&
Expand All @@ -59,34 +59,41 @@ public bool HasDefaultOptions(string originalImagePath)
!MaxHeight.HasValue;
}

public bool HasDefaultOptions(string originalImagePath, ImageSize size)
public bool HasDefaultOptions(string originalImagePath, ImageSize? size)
{
if (!size.HasValue)
{
return HasDefaultOptions(originalImagePath);
}

if (!HasDefaultOptionsWithoutSize(originalImagePath))
{
return false;
}

if (Width.HasValue && !size.Width.Equals(Width.Value))
var sizeValue = size.Value;

if (Width.HasValue && !sizeValue.Width.Equals(Width.Value))
{
return false;
}
if (Height.HasValue && !size.Height.Equals(Height.Value))
if (Height.HasValue && !sizeValue.Height.Equals(Height.Value))
{
return false;
}
if (MaxWidth.HasValue && size.Width > MaxWidth.Value)
if (MaxWidth.HasValue && sizeValue.Width > MaxWidth.Value)
{
return false;
}
if (MaxHeight.HasValue && size.Height > MaxHeight.Value)
if (MaxHeight.HasValue && sizeValue.Height > MaxHeight.Value)
{
return false;
}

return true;
}

public bool HasDefaultOptionsWithoutSize(string originalImagePath)
private bool HasDefaultOptionsWithoutSize(string originalImagePath)
{
return (Quality >= 90) &&
IsFormatSupported(originalImagePath) &&
Expand Down
2 changes: 1 addition & 1 deletion MediaBrowser.Controller/Entities/BaseItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2324,7 +2324,7 @@ protected List<FileSystemMetadata> GetLocalMetadataFilesToDelete()
}

var filename = System.IO.Path.GetFileNameWithoutExtension(Path);
var extensions = new List<string> { ".nfo", ".xml", ".srt", ".vtt", ".sub", ".idx", ".txt", ".edl" };
var extensions = new List<string> { ".nfo", ".xml", ".srt", ".vtt", ".sub", ".idx", ".txt", ".edl", ".bif", ".smi", ".ttml" };
extensions.AddRange(SupportedImageExtensions);

return FileSystem.GetFiles(FileSystem.GetDirectoryName(Path), extensions.ToArray(extensions.Count), false, false)
Expand Down
Loading

0 comments on commit cbb30d8

Please sign in to comment.