fixes #552 - Add parental control usage limits

This commit is contained in:
Luke Pulverenti
2014-10-14 20:05:09 -04:00
parent 52776df012
commit bd1bd5e87e
34 changed files with 326 additions and 94 deletions

View File

@@ -1,19 +0,0 @@

namespace MediaBrowser.Controller.Connect
{
public class ConnectUser
{
public string Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public bool IsActive { get; set; }
public string ImageUrl { get; set; }
}
public class ConnectUserQuery
{
public string Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
}
}

View File

@@ -564,6 +564,11 @@ namespace MediaBrowser.Controller.Entities
return PlayAccess.None;
}
//if (!user.IsParentalScheduleAllowed())
//{
// return PlayAccess.None;
//}
return PlayAccess.Full;
}
@@ -1465,8 +1470,6 @@ namespace MediaBrowser.Controller.Entities
image.Path = file.FullName;
image.DateModified = imageInfo.DateModified;
image.Width = imageInfo.Width;
image.Height = imageInfo.Height;
}
}
@@ -1639,26 +1642,12 @@ namespace MediaBrowser.Controller.Entities
private ItemImageInfo GetImageInfo(FileSystemInfo file, ImageType type)
{
var info = new ItemImageInfo
return new ItemImageInfo
{
Path = file.FullName,
Type = type,
DateModified = FileSystem.GetLastWriteTimeUtc(file)
};
try
{
var size = ImageProcessor.GetImageSize(info.Path);
info.Width = Convert.ToInt32(size.Width);
info.Height = Convert.ToInt32(size.Height);
}
catch
{
}
return info;
}
/// <summary>

View File

@@ -10,9 +10,5 @@ namespace MediaBrowser.Controller.Entities
public ImageType Type { get; set; }
public DateTime DateModified { get; set; }
public int? Width { get; set; }
public int? Height { get; set; }
}
}

View File

@@ -6,6 +6,7 @@ using MediaBrowser.Model.Connect;
using MediaBrowser.Model.Serialization;
using System;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.Threading;
using System.Threading.Tasks;
@@ -259,5 +260,41 @@ namespace MediaBrowser.Controller.Entities
Configuration = config;
UserManager.UpdateConfiguration(this, Configuration);
}
public bool IsParentalScheduleAllowed()
{
return IsParentalScheduleAllowed(DateTime.UtcNow);
}
public bool IsParentalScheduleAllowed(DateTime date)
{
var schedules = Configuration.AccessSchedules;
if (schedules.Length == 0)
{
return true;
}
return schedules.Any(i => IsParentalScheduleAllowed(i, date));
}
private bool IsParentalScheduleAllowed(AccessSchedule schedule, DateTime date)
{
if (date.Kind != DateTimeKind.Utc)
{
throw new ArgumentException("Utc date expected");
}
var localTime = date.ToLocalTime();
return localTime.DayOfWeek == schedule.DayOfWeek && IsWithinTime(schedule, localTime);
}
private bool IsWithinTime(AccessSchedule schedule, DateTime localTime)
{
var hour = localTime.TimeOfDay.TotalHours;
return hour >= schedule.StartHour && hour <= schedule.EndHour;
}
}
}

View File

@@ -129,6 +129,7 @@ namespace MediaBrowser.Controller.Entities
public bool IsPlaceHolder { get; set; }
public bool IsShortcut { get; set; }
public string ShortcutPath { get; set; }
/// <summary>
/// Gets or sets the tags.
@@ -578,6 +579,28 @@ namespace MediaBrowser.Controller.Entities
PlayableStreamFileNames = i.PlayableStreamFileNames.ToList()
};
if (i.IsShortcut)
{
info.Path = i.ShortcutPath;
if (info.Path.StartsWith("Http", StringComparison.OrdinalIgnoreCase))
{
info.Protocol = MediaProtocol.Http;
}
else if (info.Path.StartsWith("Rtmp", StringComparison.OrdinalIgnoreCase))
{
info.Protocol = MediaProtocol.Rtmp;
}
else if (info.Path.StartsWith("Rtsp", StringComparison.OrdinalIgnoreCase))
{
info.Protocol = MediaProtocol.Rtsp;
}
else
{
info.Protocol = MediaProtocol.File;
}
}
if (string.IsNullOrEmpty(info.Container))
{
if (i.VideoType == VideoType.VideoFile || i.VideoType == VideoType.Iso)

View File

@@ -99,7 +99,6 @@
<Compile Include="Collections\CollectionCreationOptions.cs" />
<Compile Include="Collections\CollectionEvents.cs" />
<Compile Include="Collections\ICollectionManager.cs" />
<Compile Include="Connect\ConnectUser.cs" />
<Compile Include="Connect\IConnectManager.cs" />
<Compile Include="Connect\UserLinkResult.cs" />
<Compile Include="Devices\IDeviceManager.cs" />