sync updates

This commit is contained in:
Luke Pulverenti 2015-01-05 22:25:23 -05:00
parent 00b5150999
commit 01be627d8b
12 changed files with 90 additions and 53 deletions

View File

@ -186,7 +186,7 @@ namespace MediaBrowser.Common.Implementations
{
if (_deviceId == null)
{
_deviceId = new DeviceId(ApplicationPaths, LogManager.GetLogger("SystemId"), NetworkManager);
_deviceId = new DeviceId(ApplicationPaths, LogManager.GetLogger("SystemId"));
}
return _deviceId.Value;

View File

@ -1,6 +1,4 @@
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Net;
using MediaBrowser.Model.Logging;
using System;
using System.IO;
@ -11,7 +9,6 @@ namespace MediaBrowser.Common.Implementations.Devices
public class DeviceId
{
private readonly IApplicationPaths _appPaths;
private readonly INetworkManager _networkManager;
private readonly ILogger _logger;
private readonly object _syncLock = new object();
@ -73,23 +70,7 @@ namespace MediaBrowser.Common.Implementations.Devices
private string GetNewId()
{
// When generating an Id, base it off of the app path + mac address
// But we can't fail here, so if we can't get the mac address then just use a random guid
string mac;
try
{
mac = _networkManager.GetMacAddress();
}
catch
{
mac = Guid.NewGuid().ToString("N");
}
mac += "-" + _appPaths.ApplicationPath;
return mac.GetMD5().ToString("N");
return Guid.NewGuid().ToString("N");
}
private string GetDeviceId()
@ -107,11 +88,10 @@ namespace MediaBrowser.Common.Implementations.Devices
private string _id;
public DeviceId(IApplicationPaths appPaths, ILogger logger, INetworkManager networkManager)
public DeviceId(IApplicationPaths appPaths, ILogger logger)
{
_appPaths = appPaths;
_logger = logger;
_networkManager = networkManager;
}
public string Value

View File

@ -73,5 +73,10 @@ namespace MediaBrowser.Model.Sync
/// </summary>
/// <value>The primary image tag.</value>
public string PrimaryImageTag { get; set; }
/// <summary>
/// Gets or sets a value indicating whether [requires conversion].
/// </summary>
/// <value><c>true</c> if [requires conversion]; otherwise, <c>false</c>.</value>
public bool RequiresConversion { get; set; }
}
}

View File

@ -1,5 +1,6 @@
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.MediaEncoding;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Drawing;
@ -18,12 +19,14 @@ namespace MediaBrowser.Providers.MediaInfo
private readonly IIsoManager _isoManager;
private readonly IMediaEncoder _mediaEncoder;
private readonly IServerConfigurationManager _config;
private readonly ILibraryManager _libraryManager;
public VideoImageProvider(IIsoManager isoManager, IMediaEncoder mediaEncoder, IServerConfigurationManager config)
public VideoImageProvider(IIsoManager isoManager, IMediaEncoder mediaEncoder, IServerConfigurationManager config, ILibraryManager libraryManager)
{
_isoManager = isoManager;
_mediaEncoder = mediaEncoder;
_config = config;
_libraryManager = libraryManager;
}
/// <summary>
@ -123,7 +126,21 @@ namespace MediaBrowser.Providers.MediaInfo
{
var video = item as Video;
return item.LocationType == LocationType.FileSystem && video != null && !video.IsPlaceHolder && !video.IsShortcut && !video.IsArchive;
if (item.LocationType == LocationType.FileSystem && video != null && !video.IsPlaceHolder &&
!video.IsShortcut && !video.IsArchive)
{
if (video.GetType() == typeof(Video))
{
if (string.IsNullOrEmpty(_libraryManager.GetContentType(video)))
{
return false;
}
}
return true;
}
return false;
}
public int Order

View File

@ -35,6 +35,11 @@
"LabelChapterImageExtractionForMoviesHelp": "Extracting chapter images will allow clients to display graphical scene selection menus. The process can be slow, cpu-intensive and may require several gigabytes of space. It runs as a nightly scheduled task at 4am, although this is configurable in the scheduled tasks area. It is not recommended to run this task during peak usage hours.",
"LabelEnableAutomaticPortMapping": "Enable automatic port mapping",
"LabelEnableAutomaticPortMappingHelp": "UPnP allows automated router configuration for easy remote access. This may not work with some router models.",
"HeaderTermsOfService": "Media Browser Terms of Service",
"MessagePleaseAcceptTermsOfService": "Please accept the terms of service and privacy policy before continuing.",
"OptionIAcceptTermsOfService": "I accept the terms of service",
"ButtonPrivacyPolicy": "Privacy policy",
"ButtonTermsOfService": "Terms of Service",
"ButtonOk": "Ok",
"ButtonCancel": "Cancel",
"ButtonNew": "New",

View File

@ -51,7 +51,7 @@
</Reference>
<Reference Include="MediaBrowser.Naming, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\MediaBrowser.Naming.1.0.0.24\lib\portable-net45+sl4+wp71+win8+wpa81\MediaBrowser.Naming.dll</HintPath>
<HintPath>..\packages\MediaBrowser.Naming.1.0.0.25\lib\portable-net45+sl4+wp71+win8+wpa81\MediaBrowser.Naming.dll</HintPath>
</Reference>
<Reference Include="Mono.Nat, Version=1.2.21.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>

View File

@ -340,16 +340,17 @@ namespace MediaBrowser.Server.Implementations.Sync
var innerProgress = new ActionableProgress<double>();
await ProcessJobItem(item, innerProgress, cancellationToken).ConfigureAwait(false);
var job = _syncRepo.GetJob(item.JobId);
await ProcessJobItem(job, item, innerProgress, cancellationToken).ConfigureAwait(false);
job = _syncRepo.GetJob(item.JobId);
await UpdateJobStatus(job).ConfigureAwait(false);
index++;
}
}
private async Task ProcessJobItem(SyncJobItem jobItem, IProgress<double> progress, CancellationToken cancellationToken)
private async Task ProcessJobItem(SyncJob job, SyncJobItem jobItem, IProgress<double> progress, CancellationToken cancellationToken)
{
var item = _libraryManager.GetItemById(jobItem.ItemId);
if (item == null)
@ -372,15 +373,17 @@ namespace MediaBrowser.Server.Implementations.Sync
jobItem.Progress = 0;
jobItem.Status = SyncJobItemStatus.Converting;
var user = _userManager.GetUserById(job.UserId);
var video = item as Video;
if (video != null)
{
await Sync(jobItem, video, deviceProfile, progress, cancellationToken).ConfigureAwait(false);
await Sync(jobItem, video, user, deviceProfile, progress, cancellationToken).ConfigureAwait(false);
}
else if (item is Audio)
{
await Sync(jobItem, (Audio)item, deviceProfile, progress, cancellationToken).ConfigureAwait(false);
await Sync(jobItem, (Audio)item, user, deviceProfile, progress, cancellationToken).ConfigureAwait(false);
}
else if (item is Photo)
@ -394,7 +397,7 @@ namespace MediaBrowser.Server.Implementations.Sync
}
}
private async Task Sync(SyncJobItem jobItem, Video item, DeviceProfile profile, IProgress<double> progress, CancellationToken cancellationToken)
private async Task Sync(SyncJobItem jobItem, Video item, User user, DeviceProfile profile, IProgress<double> progress, CancellationToken cancellationToken)
{
var options = new VideoOptions
{
@ -402,7 +405,7 @@ namespace MediaBrowser.Server.Implementations.Sync
ItemId = item.Id.ToString("N"),
DeviceId = jobItem.TargetId,
Profile = profile,
MediaSources = item.GetMediaSources(false).ToList()
MediaSources = item.GetMediaSources(false, user).ToList()
};
var streamInfo = new StreamBuilder().BuildVideoItem(options);
@ -413,6 +416,7 @@ namespace MediaBrowser.Server.Implementations.Sync
if (streamInfo.PlayMethod == PlayMethod.Transcode)
{
jobItem.Status = SyncJobItemStatus.Converting;
jobItem.RequiresConversion = true;
await _syncRepo.Update(jobItem).ConfigureAwait(false);
try
@ -438,6 +442,8 @@ namespace MediaBrowser.Server.Implementations.Sync
}
else
{
jobItem.RequiresConversion = false;
if (mediaSource.Protocol == MediaProtocol.File)
{
jobItem.OutputPath = mediaSource.Path;
@ -457,7 +463,7 @@ namespace MediaBrowser.Server.Implementations.Sync
await _syncRepo.Update(jobItem).ConfigureAwait(false);
}
private async Task Sync(SyncJobItem jobItem, Audio item, DeviceProfile profile, IProgress<double> progress, CancellationToken cancellationToken)
private async Task Sync(SyncJobItem jobItem, Audio item, User user, DeviceProfile profile, IProgress<double> progress, CancellationToken cancellationToken)
{
var options = new AudioOptions
{
@ -465,7 +471,7 @@ namespace MediaBrowser.Server.Implementations.Sync
ItemId = item.Id.ToString("N"),
DeviceId = jobItem.TargetId,
Profile = profile,
MediaSources = item.GetMediaSources(false).ToList()
MediaSources = item.GetMediaSources(false, user).ToList()
};
var streamInfo = new StreamBuilder().BuildAudioItem(options);
@ -476,6 +482,7 @@ namespace MediaBrowser.Server.Implementations.Sync
if (streamInfo.PlayMethod == PlayMethod.Transcode)
{
jobItem.Status = SyncJobItemStatus.Converting;
jobItem.RequiresConversion = true;
await _syncRepo.Update(jobItem).ConfigureAwait(false);
try
@ -500,6 +507,8 @@ namespace MediaBrowser.Server.Implementations.Sync
}
else
{
jobItem.RequiresConversion = false;
if (mediaSource.Protocol == MediaProtocol.File)
{
jobItem.OutputPath = mediaSource.Path;

View File

@ -12,7 +12,6 @@ using MediaBrowser.Controller.MediaEncoding;
using MediaBrowser.Controller.Sync;
using MediaBrowser.Controller.TV;
using MediaBrowser.Model.Dlna;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Querying;
@ -393,6 +392,18 @@ namespace MediaBrowser.Server.Implementations.Sync
jobItem.Status = SyncJobItemStatus.Synced;
jobItem.Progress = 100;
if (jobItem.RequiresConversion)
{
try
{
File.Delete(jobItem.OutputPath);
}
catch (Exception ex)
{
_logger.ErrorException("Error deleting temporary job file: {0}", ex, jobItem.OutputPath);
}
}
await _repo.Update(jobItem).ConfigureAwait(false);
var processor = new SyncJobProcessor(_libraryManager, _repo, this, _logger, _userManager, _tvSeriesManager, _mediaEncoder());

View File

@ -36,7 +36,7 @@ namespace MediaBrowser.Server.Implementations.Sync
public async Task Initialize()
{
var dbFile = Path.Combine(_appPaths.DataPath, "sync10.db");
var dbFile = Path.Combine(_appPaths.DataPath, "sync11.db");
_connection = await SqliteExtensions.ConnectToDb(dbFile, _logger).ConfigureAwait(false);
@ -45,7 +45,7 @@ namespace MediaBrowser.Server.Implementations.Sync
"create table if not exists SyncJobs (Id GUID PRIMARY KEY, TargetId TEXT NOT NULL, Name TEXT NOT NULL, Quality TEXT NOT NULL, Status TEXT NOT NULL, Progress FLOAT, UserId TEXT NOT NULL, ItemIds TEXT NOT NULL, Category TEXT, ParentId TEXT, UnwatchedOnly BIT, ItemLimit INT, SyncNewContent BIT, DateCreated DateTime, DateLastModified DateTime, ItemCount int)",
"create index if not exists idx_SyncJobs on SyncJobs(Id)",
"create table if not exists SyncJobItems (Id GUID PRIMARY KEY, ItemId TEXT, ItemName TEXT, MediaSourceId TEXT, JobId TEXT, OutputPath TEXT, Status TEXT, TargetId TEXT, DateCreated DateTime, Progress FLOAT)",
"create table if not exists SyncJobItems (Id GUID PRIMARY KEY, ItemId TEXT, ItemName TEXT, MediaSourceId TEXT, JobId TEXT, RequiresConversion BIT, OutputPath TEXT, Status TEXT, TargetId TEXT, DateCreated DateTime, Progress FLOAT)",
"create index if not exists idx_SyncJobItems on SyncJobs(Id)",
//pragmas
@ -90,13 +90,14 @@ namespace MediaBrowser.Server.Implementations.Sync
_saveJobCommand.Parameters.Add(_saveJobCommand, "@ItemCount");
_saveJobItemCommand = _connection.CreateCommand();
_saveJobItemCommand.CommandText = "replace into SyncJobItems (Id, ItemId, ItemName, MediaSourceId, JobId, OutputPath, Status, TargetId, DateCreated, Progress) values (@Id, @ItemId, @ItemName, @MediaSourceId, @JobId, @OutputPath, @Status, @TargetId, @DateCreated, @Progress)";
_saveJobItemCommand.CommandText = "replace into SyncJobItems (Id, ItemId, ItemName, MediaSourceId, JobId, RequiresConversion, OutputPath, Status, TargetId, DateCreated, Progress) values (@Id, @ItemId, @ItemName, @MediaSourceId, @JobId, @RequiresConversion, @OutputPath, @Status, @TargetId, @DateCreated, @Progress)";
_saveJobItemCommand.Parameters.Add(_saveJobItemCommand, "@Id");
_saveJobItemCommand.Parameters.Add(_saveJobItemCommand, "@ItemId");
_saveJobItemCommand.Parameters.Add(_saveJobItemCommand, "@ItemName");
_saveJobItemCommand.Parameters.Add(_saveJobItemCommand, "@MediaSourceId");
_saveJobItemCommand.Parameters.Add(_saveJobItemCommand, "@JobId");
_saveJobItemCommand.Parameters.Add(_saveJobItemCommand, "@RequiresConversion");
_saveJobItemCommand.Parameters.Add(_saveJobItemCommand, "@OutputPath");
_saveJobItemCommand.Parameters.Add(_saveJobItemCommand, "@Status");
_saveJobItemCommand.Parameters.Add(_saveJobItemCommand, "@TargetId");
@ -105,7 +106,7 @@ namespace MediaBrowser.Server.Implementations.Sync
}
private const string BaseJobSelectText = "select Id, TargetId, Name, Quality, Status, Progress, UserId, ItemIds, Category, ParentId, UnwatchedOnly, ItemLimit, SyncNewContent, DateCreated, DateLastModified, ItemCount from SyncJobs";
private const string BaseJobItemSelectText = "select Id, ItemId, ItemName, MediaSourceId, JobId, OutputPath, Status, TargetId, DateCreated, Progress from SyncJobItems";
private const string BaseJobItemSelectText = "select Id, ItemId, ItemName, MediaSourceId, JobId, RequiresConversion, OutputPath, Status, TargetId, DateCreated, Progress from SyncJobItems";
public SyncJob GetJob(string id)
{
@ -556,6 +557,7 @@ namespace MediaBrowser.Server.Implementations.Sync
_saveJobItemCommand.GetParameter(index++).Value = jobItem.ItemName;
_saveJobItemCommand.GetParameter(index++).Value = jobItem.MediaSourceId;
_saveJobItemCommand.GetParameter(index++).Value = jobItem.JobId;
_saveJobItemCommand.GetParameter(index++).Value = jobItem.RequiresConversion;
_saveJobItemCommand.GetParameter(index++).Value = jobItem.OutputPath;
_saveJobItemCommand.GetParameter(index++).Value = jobItem.Status.ToString();
_saveJobItemCommand.GetParameter(index++).Value = jobItem.TargetId;
@ -618,24 +620,25 @@ namespace MediaBrowser.Server.Implementations.Sync
}
info.JobId = reader.GetString(4);
if (!reader.IsDBNull(5))
{
info.OutputPath = reader.GetString(5);
}
info.RequiresConversion = reader.GetBoolean(5);
if (!reader.IsDBNull(6))
{
info.Status = (SyncJobItemStatus)Enum.Parse(typeof(SyncJobItemStatus), reader.GetString(6), true);
info.OutputPath = reader.GetString(6);
}
info.TargetId = reader.GetString(7);
info.DateCreated = reader.GetDateTime(8);
if (!reader.IsDBNull(9))
if (!reader.IsDBNull(7))
{
info.Progress = reader.GetDouble(9);
info.Status = (SyncJobItemStatus)Enum.Parse(typeof(SyncJobItemStatus), reader.GetString(7), true);
}
info.TargetId = reader.GetString(8);
info.DateCreated = reader.GetDateTime(9);
if (!reader.IsDBNull(10))
{
info.Progress = reader.GetDouble(10);
}
return info;

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="MediaBrowser.Naming" version="1.0.0.24" targetFramework="net45" />
<package id="MediaBrowser.Naming" version="1.0.0.25" targetFramework="net45" />
<package id="Mono.Nat" version="1.2.21.0" targetFramework="net45" />
<package id="morelinq" version="1.1.0" targetFramework="net45" />
</packages>

View File

@ -471,6 +471,7 @@ namespace MediaBrowser.WebDashboard.Api
"userprofilespage.js",
"userparentalcontrol.js",
"userlibraryaccess.js",
"wizardagreement.js",
"wizardfinishpage.js",
"wizardservice.js",
"wizardstartpage.js",

View File

@ -120,6 +120,9 @@
<Content Include="dashboard-ui\scripts\userpassword.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="dashboard-ui\scripts\wizardagreement.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="dashboard-ui\selectserver.html">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
@ -1638,6 +1641,9 @@
<Content Include="dashboard-ui\userpassword.html">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="dashboard-ui\wizardagreement.html">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="dashboard-ui\wizardservice.html">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>