standardize knowledge of supported image extensions

This commit is contained in:
Luke Pulverenti 2013-05-30 18:22:15 -04:00
parent 3387dac01d
commit 300c3b7fd6
11 changed files with 69 additions and 59 deletions

View File

@ -1,8 +1,10 @@
using MediaBrowser.Common.Extensions; using MediaBrowser.Common.Extensions;
using MediaBrowser.Controller; using MediaBrowser.Controller;
using MediaBrowser.Controller.Entities;
using ServiceStack.ServiceHost; using ServiceStack.ServiceHost;
using System; using System;
using System.IO; using System.IO;
using System.Linq;
namespace MediaBrowser.Api.Images namespace MediaBrowser.Api.Images
{ {
@ -98,9 +100,11 @@ namespace MediaBrowser.Api.Images
? "folder" ? "folder"
: request.Type; : request.Type;
var file = Path.Combine(_appPaths.GeneralPath, request.Name, filename + ".jpg"); var paths = BaseItem.SupportedImageExtensions.Select(i => Path.Combine(_appPaths.GeneralPath, request.Name, filename + i)).ToList();
return ToStaticFileResult(File.Exists(file) ? file : Path.ChangeExtension(file, ".png")); var path = paths.FirstOrDefault(File.Exists) ?? paths.FirstOrDefault();
return ToStaticFileResult(path);
} }
/// <summary> /// <summary>
@ -114,18 +118,12 @@ namespace MediaBrowser.Api.Images
if (Directory.Exists(themeFolder)) if (Directory.Exists(themeFolder))
{ {
var file = Path.Combine(themeFolder, request.Name + ".png"); var path = BaseItem.SupportedImageExtensions.Select(i => Path.Combine(themeFolder, request.Name + i))
.FirstOrDefault(File.Exists);
if (File.Exists(file)) if (!string.IsNullOrEmpty(path))
{ {
return ToStaticFileResult(file); return ToStaticFileResult(path);
}
file = Path.Combine(themeFolder, request.Name + ".jpg");
if (File.Exists(file))
{
return ToStaticFileResult(file);
} }
} }
@ -133,18 +131,15 @@ namespace MediaBrowser.Api.Images
if (Directory.Exists(allFolder)) if (Directory.Exists(allFolder))
{ {
var file = Path.Combine(allFolder, request.Name + ".png"); // Avoid implicitly captured closure
var currentRequest = request;
if (File.Exists(file)) var path = BaseItem.SupportedImageExtensions.Select(i => Path.Combine(allFolder, currentRequest.Name + i))
.FirstOrDefault(File.Exists);
if (!string.IsNullOrEmpty(path))
{ {
return ToStaticFileResult(file); return ToStaticFileResult(path);
}
file = Path.Combine(allFolder, request.Name + ".jpg");
if (File.Exists(file))
{
return ToStaticFileResult(file);
} }
} }
@ -162,18 +157,12 @@ namespace MediaBrowser.Api.Images
if (Directory.Exists(themeFolder)) if (Directory.Exists(themeFolder))
{ {
var file = Path.Combine(themeFolder, request.Name + ".png"); var path = BaseItem.SupportedImageExtensions.Select(i => Path.Combine(themeFolder, request.Name + i))
.FirstOrDefault(File.Exists);
if (File.Exists(file)) if (!string.IsNullOrEmpty(path))
{ {
return ToStaticFileResult(file); return ToStaticFileResult(path);
}
file = Path.Combine(themeFolder, request.Name + ".jpg");
if (File.Exists(file))
{
return ToStaticFileResult(file);
} }
} }
@ -181,18 +170,15 @@ namespace MediaBrowser.Api.Images
if (Directory.Exists(allFolder)) if (Directory.Exists(allFolder))
{ {
var file = Path.Combine(allFolder, request.Name + ".png"); // Avoid implicitly captured closure
var currentRequest = request;
if (File.Exists(file)) var path = BaseItem.SupportedImageExtensions.Select(i => Path.Combine(allFolder, currentRequest.Name + i))
.FirstOrDefault(File.Exists);
if (!string.IsNullOrEmpty(path))
{ {
return ToStaticFileResult(file); return ToStaticFileResult(path);
}
file = Path.Combine(allFolder, request.Name + ".jpg");
if (File.Exists(file))
{
return ToStaticFileResult(file);
} }
} }

View File

@ -36,9 +36,10 @@ namespace MediaBrowser.Controller.Dto
dto.NowPlayingItem = DtoBuilder.GetBaseItemInfo(session.NowPlayingItem); dto.NowPlayingItem = DtoBuilder.GetBaseItemInfo(session.NowPlayingItem);
} }
if (session.UserId.HasValue) if (session.User != null)
{ {
dto.UserId = session.UserId.Value.ToString("N"); dto.UserId = session.User.Id.ToString("N");
dto.UserName = session.User.Name;
} }
return dto; return dto;

View File

@ -42,6 +42,11 @@ namespace MediaBrowser.Controller.Entities
LocalTrailerIds = new List<Guid>(); LocalTrailerIds = new List<Guid>();
} }
/// <summary>
/// The supported image extensions
/// </summary>
public static readonly string[] SupportedImageExtensions = new[] { ".png", ".jpg", ".jpeg" };
/// <summary> /// <summary>
/// The trailer folder name /// The trailer folder name
/// </summary> /// </summary>

View File

@ -146,8 +146,7 @@ namespace MediaBrowser.Controller.Providers
/// <returns>FileSystemInfo.</returns> /// <returns>FileSystemInfo.</returns>
protected virtual FileSystemInfo GetImage(BaseItem item, string filenameWithoutExtension) protected virtual FileSystemInfo GetImage(BaseItem item, string filenameWithoutExtension)
{ {
return item.ResolveArgs.GetMetaFileByPath(Path.Combine(item.ResolveArgs.Path, filenameWithoutExtension + ".png")) return BaseItem.SupportedImageExtensions.Select(i => item.ResolveArgs.GetMetaFileByPath(Path.Combine(item.ResolveArgs.Path, filenameWithoutExtension + i))).FirstOrDefault(i => i != null);
?? item.ResolveArgs.GetMetaFileByPath(Path.Combine(item.ResolveArgs.Path, filenameWithoutExtension + ".jpg"));
} }
/// <summary> /// <summary>
@ -159,7 +158,7 @@ namespace MediaBrowser.Controller.Providers
// Primary Image // Primary Image
var image = GetImage(item, "folder") ?? var image = GetImage(item, "folder") ??
GetImage(item, "poster") ?? GetImage(item, "poster") ??
GetImage(item, "cover") ?? GetImage(item, "cover") ??
GetImage(item, "default"); GetImage(item, "default");
if (image != null) if (image != null)

View File

@ -27,7 +27,7 @@ namespace MediaBrowser.Controller.Session
/// Gets or sets the user id. /// Gets or sets the user id.
/// </summary> /// </summary>
/// <value>The user id.</value> /// <value>The user id.</value>
public Guid? UserId { get; set; } public User User { get; set; }
/// <summary> /// <summary>
/// Gets or sets the type of the client. /// Gets or sets the type of the client.

View File

@ -17,6 +17,12 @@ namespace MediaBrowser.Model.Session
/// <value>The user id.</value> /// <value>The user id.</value>
public string UserId { get; set; } public string UserId { get; set; }
/// <summary>
/// Gets or sets the name of the user.
/// </summary>
/// <value>The name of the user.</value>
public string UserName { get; set; }
/// <summary> /// <summary>
/// Gets or sets the type of the client. /// Gets or sets the type of the client.
/// </summary> /// </summary>

View File

@ -4,6 +4,7 @@ using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Movies; using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Persistence; using MediaBrowser.Controller.Persistence;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Logging; using MediaBrowser.Model.Logging;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -175,7 +176,13 @@ namespace MediaBrowser.Server.Implementations.ScheduledTasks
/// <returns>IEnumerable{System.String}.</returns> /// <returns>IEnumerable{System.String}.</returns>
private IEnumerable<string> GetFiles(string path) private IEnumerable<string> GetFiles(string path)
{ {
return Directory.EnumerateFiles(path, "*.jpg", SearchOption.AllDirectories).Concat(Directory.EnumerateFiles(path, "*.png", SearchOption.AllDirectories)); return Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories)
.Where(i =>
{
var ext = Path.GetExtension(i);
return !string.IsNullOrEmpty(ext) && BaseItem.SupportedImageExtensions.Contains(ext, StringComparer.OrdinalIgnoreCase);
});
} }
/// <summary> /// <summary>

View File

@ -185,7 +185,7 @@ namespace MediaBrowser.Server.Implementations.Session
connection.DeviceName = deviceName; connection.DeviceName = deviceName;
connection.UserId = user == null ? (Guid?)null : user.Id; connection.User = user;
return connection; return connection;
} }

View File

@ -99,18 +99,18 @@ namespace MediaBrowser.Server.Implementations.Session
{ {
var session = _sessionManager.Sessions.FirstOrDefault(i => i.WebSockets.Contains(message.Connection)); var session = _sessionManager.Sessions.FirstOrDefault(i => i.WebSockets.Contains(message.Connection));
if (session != null && session.UserId.HasValue) if (session != null && session.User != null)
{ {
var item = DtoBuilder.GetItemByClientId(message.Data, _userManager, _libraryManager); var item = DtoBuilder.GetItemByClientId(message.Data, _userManager, _libraryManager);
_sessionManager.OnPlaybackStart(_userManager.GetUserById(session.UserId.Value), item, session.Client, session.DeviceId, session.DeviceName); _sessionManager.OnPlaybackStart(_userManager.GetUserById(session.User.Id), item, session.Client, session.DeviceId, session.DeviceName);
} }
} }
else if (string.Equals(message.MessageType, "PlaybackProgress", StringComparison.OrdinalIgnoreCase)) else if (string.Equals(message.MessageType, "PlaybackProgress", StringComparison.OrdinalIgnoreCase))
{ {
var session = _sessionManager.Sessions.FirstOrDefault(i => i.WebSockets.Contains(message.Connection)); var session = _sessionManager.Sessions.FirstOrDefault(i => i.WebSockets.Contains(message.Connection));
if (session != null && session.UserId.HasValue) if (session != null && session.User != null)
{ {
var vals = message.Data.Split('|'); var vals = message.Data.Split('|');
@ -130,14 +130,14 @@ namespace MediaBrowser.Server.Implementations.Session
var isPaused = vals.Length > 2 && string.Equals(vals[2], "true", StringComparison.OrdinalIgnoreCase); var isPaused = vals.Length > 2 && string.Equals(vals[2], "true", StringComparison.OrdinalIgnoreCase);
_sessionManager.OnPlaybackProgress(_userManager.GetUserById(session.UserId.Value), item, positionTicks, isPaused, session.Client, session.DeviceId, session.DeviceName); _sessionManager.OnPlaybackProgress(_userManager.GetUserById(session.User.Id), item, positionTicks, isPaused, session.Client, session.DeviceId, session.DeviceName);
} }
} }
else if (string.Equals(message.MessageType, "PlaybackStopped", StringComparison.OrdinalIgnoreCase)) else if (string.Equals(message.MessageType, "PlaybackStopped", StringComparison.OrdinalIgnoreCase))
{ {
var session = _sessionManager.Sessions.FirstOrDefault(i => i.WebSockets.Contains(message.Connection)); var session = _sessionManager.Sessions.FirstOrDefault(i => i.WebSockets.Contains(message.Connection));
if (session != null && session.UserId.HasValue) if (session != null && session.User != null)
{ {
var vals = message.Data.Split('|'); var vals = message.Data.Split('|');
@ -155,7 +155,7 @@ namespace MediaBrowser.Server.Implementations.Session
} }
} }
_sessionManager.OnPlaybackStopped(_userManager.GetUserById(session.UserId.Value), item, positionTicks, session.Client, session.DeviceId, session.DeviceName); _sessionManager.OnPlaybackStopped(_userManager.GetUserById(session.User.Id), item, positionTicks, session.Client, session.DeviceId, session.DeviceName);
} }
} }

View File

@ -190,12 +190,18 @@ namespace MediaBrowser.ServerApplication.EntryPoints
{ {
var currentSessions = _sessionManager.Sessions.ToList(); var currentSessions = _sessionManager.Sessions.ToList();
var users = currentSessions.Select(i => i.UserId ?? Guid.Empty).Where(i => i != Guid.Empty).Distinct().ToList(); var users = currentSessions.Select(i => i.User)
.Where(i => i != null)
.Select(i => i.Id)
.Distinct()
.ToList();
foreach (var userId in users) foreach (var userId in users)
{ {
var id = userId; var id = userId;
var webSockets = currentSessions.Where(u => u.UserId.HasValue && u.UserId.Value == id).SelectMany(i => i.WebSockets).ToList(); var webSockets = currentSessions.Where(u => u.User != null && u.User.Id == id)
.SelectMany(i => i.WebSockets)
.ToList();
try try
{ {

View File

@ -208,7 +208,7 @@ namespace MediaBrowser.WebDashboard.Api
var dtoBuilder = new UserDtoBuilder(logger); var dtoBuilder = new UserDtoBuilder(logger);
var tasks = userManager.Users.Where(u => connections.Any(c => c.UserId.HasValue && c.UserId.Value == u.Id)).Select(dtoBuilder.GetUserDto); var tasks = userManager.Users.Where(u => connections.Any(c => c.User != null && c.User.Id == u.Id)).Select(dtoBuilder.GetUserDto);
var users = await Task.WhenAll(tasks).ConfigureAwait(false); var users = await Task.WhenAll(tasks).ConfigureAwait(false);