diff options
| author | Luke <luke.pulverenti@gmail.com> | 2016-11-09 12:33:25 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-11-09 12:33:25 -0500 |
| commit | 90406d842b8efc6f14a909149ff8143e634f154f (patch) | |
| tree | eee8e9dc308d1ff6313ab0a5cc5ccaae2c750379 /Emby.Server.Implementations | |
| parent | 15e84cf646a2b5ba16c714ba1c509ae5fed36e04 (diff) | |
| parent | c1ae3ec2ce803b16fa9ecc0981865aa7c9be172b (diff) | |
Merge pull request #2278 from MediaBrowser/dev
Dev
Diffstat (limited to 'Emby.Server.Implementations')
4 files changed, 172 insertions, 0 deletions
diff --git a/Emby.Server.Implementations/Emby.Server.Implementations.csproj b/Emby.Server.Implementations/Emby.Server.Implementations.csproj index 806702dfd3..7e885b7798 100644 --- a/Emby.Server.Implementations/Emby.Server.Implementations.csproj +++ b/Emby.Server.Implementations/Emby.Server.Implementations.csproj @@ -51,6 +51,7 @@ <Compile Include="Devices\DeviceManager.cs" /> <Compile Include="Dto\DtoService.cs" /> <Compile Include="EntryPoints\AutomaticRestartEntryPoint.cs" /> + <Compile Include="EntryPoints\KeepServerAwake.cs" /> <Compile Include="EntryPoints\LibraryChangedNotifier.cs" /> <Compile Include="EntryPoints\LoadRegistrations.cs" /> <Compile Include="EntryPoints\RecordingNotifier.cs" /> @@ -187,6 +188,7 @@ <Compile Include="Session\SessionManager.cs" /> <Compile Include="Session\SessionWebSocketListener.cs" /> <Compile Include="Session\WebSocketController.cs" /> + <Compile Include="Social\SharingManager.cs" /> <Compile Include="Sorting\AiredEpisodeOrderComparer.cs" /> <Compile Include="Sorting\AirTimeComparer.cs" /> <Compile Include="Sorting\AlbumArtistComparer.cs" /> diff --git a/Emby.Server.Implementations/EntryPoints/KeepServerAwake.cs b/Emby.Server.Implementations/EntryPoints/KeepServerAwake.cs new file mode 100644 index 0000000000..8ae85e3909 --- /dev/null +++ b/Emby.Server.Implementations/EntryPoints/KeepServerAwake.cs @@ -0,0 +1,65 @@ +using MediaBrowser.Controller; +using MediaBrowser.Controller.Plugins; +using MediaBrowser.Controller.Session; +using MediaBrowser.Model.Logging; +using System; +using System.Linq; +using MediaBrowser.Model.System; +using MediaBrowser.Model.Threading; + +namespace Emby.Server.Implementations.EntryPoints +{ + public class KeepServerAwake : IServerEntryPoint + { + private readonly ISessionManager _sessionManager; + private readonly ILogger _logger; + private ITimer _timer; + private readonly IServerApplicationHost _appHost; + private readonly ITimerFactory _timerFactory; + private readonly IPowerManagement _powerManagement; + + public KeepServerAwake(ISessionManager sessionManager, ILogger logger, IServerApplicationHost appHost, ITimerFactory timerFactory, IPowerManagement powerManagement) + { + _sessionManager = sessionManager; + _logger = logger; + _appHost = appHost; + _timerFactory = timerFactory; + _powerManagement = powerManagement; + } + + public void Run() + { + _timer = _timerFactory.Create(OnTimerCallback, null, TimeSpan.FromMinutes(5), TimeSpan.FromMinutes(5)); + } + + private void OnTimerCallback(object state) + { + var now = DateTime.UtcNow; + + try + { + if (_sessionManager.Sessions.Any(i => (now - i.LastActivityDate).TotalMinutes < 15)) + { + _powerManagement.PreventSystemStandby(); + } + else + { + _powerManagement.AllowSystemStandby(); + } + } + catch (Exception ex) + { + _logger.ErrorException("Error resetting system standby timer", ex); + } + } + + public void Dispose() + { + if (_timer != null) + { + _timer.Dispose(); + _timer = null; + } + } + } +} diff --git a/Emby.Server.Implementations/LiveTv/EmbyTV/EncodedRecorder.cs b/Emby.Server.Implementations/LiveTv/EmbyTV/EncodedRecorder.cs index 5d70d03839..5e55b893f3 100644 --- a/Emby.Server.Implementations/LiveTv/EmbyTV/EncodedRecorder.cs +++ b/Emby.Server.Implementations/LiveTv/EmbyTV/EncodedRecorder.cs @@ -177,6 +177,11 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV inputModifiers = "-ss " + _mediaEncoder.GetTimeParameter(startTimeTicks) + " " + inputModifiers; } + var analyzeDurationSeconds = 5; + var analyzeDuration = " -analyzeduration " + + (analyzeDurationSeconds * 1000000).ToString(CultureInfo.InvariantCulture); + inputModifiers += analyzeDuration; + commandLineArgs = string.Format(commandLineArgs, inputTempFile, targetFile, videoArgs, GetAudioArgs(mediaSource), durationParam); return inputModifiers + " " + commandLineArgs; diff --git a/Emby.Server.Implementations/Social/SharingManager.cs b/Emby.Server.Implementations/Social/SharingManager.cs new file mode 100644 index 0000000000..54614c8797 --- /dev/null +++ b/Emby.Server.Implementations/Social/SharingManager.cs @@ -0,0 +1,100 @@ +using MediaBrowser.Common.Extensions; +using MediaBrowser.Controller; +using MediaBrowser.Controller.Configuration; +using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Library; +using MediaBrowser.Model.Social; +using System; +using System.Threading.Tasks; + +namespace Emby.Server.Implementations.Social +{ + public class SharingManager : ISharingManager + { + private readonly ISharingRepository _repository; + private readonly IServerConfigurationManager _config; + private readonly ILibraryManager _libraryManager; + private readonly IServerApplicationHost _appHost; + + public SharingManager(ISharingRepository repository, IServerConfigurationManager config, ILibraryManager libraryManager, IServerApplicationHost appHost) + { + _repository = repository; + _config = config; + _libraryManager = libraryManager; + _appHost = appHost; + } + + public async Task<SocialShareInfo> CreateShare(string itemId, string userId) + { + if (string.IsNullOrWhiteSpace(itemId)) + { + throw new ArgumentNullException("itemId"); + } + if (string.IsNullOrWhiteSpace(userId)) + { + throw new ArgumentNullException("userId"); + } + + var item = _libraryManager.GetItemById(itemId); + + if (item == null) + { + throw new ResourceNotFoundException(); + } + + var externalUrl = (await _appHost.GetSystemInfo().ConfigureAwait(false)).WanAddress; + + if (string.IsNullOrWhiteSpace(externalUrl)) + { + throw new InvalidOperationException("No external server address is currently available."); + } + + var info = new SocialShareInfo + { + Id = Guid.NewGuid().ToString("N"), + ExpirationDate = DateTime.UtcNow.AddDays(_config.Configuration.SharingExpirationDays), + ItemId = itemId, + UserId = userId + }; + + AddShareInfo(info, externalUrl); + + await _repository.CreateShare(info).ConfigureAwait(false); + + return info; + } + + private string GetTitle(BaseItem item) + { + return item.Name; + } + + public SocialShareInfo GetShareInfo(string id) + { + var info = _repository.GetShareInfo(id); + + AddShareInfo(info, _appHost.GetSystemInfo().Result.WanAddress); + + return info; + } + + private void AddShareInfo(SocialShareInfo info, string externalUrl) + { + info.ImageUrl = externalUrl + "/Social/Shares/Public/" + info.Id + "/Image"; + info.Url = externalUrl + "/emby/web/shared.html?id=" + info.Id; + + var item = _libraryManager.GetItemById(info.ItemId); + + if (item != null) + { + info.Overview = item.Overview; + info.Name = GetTitle(item); + } + } + + public Task DeleteShare(string id) + { + return _repository.DeleteShare(id); + } + } +} |
