sync updates

pull/702/head
Luke Pulverenti 10 years ago
parent 72a5383c70
commit 280ab32ec1

@ -397,7 +397,6 @@
<Compile Include="Sync\ISyncProvider.cs" />
<Compile Include="Sync\ISyncRepository.cs" />
<Compile Include="Sync\SendFileResult.cs" />
<Compile Include="Sync\SyncJobOptions.cs" />
<Compile Include="Themes\IAppThemeManager.cs" />
<Compile Include="Themes\InternalThemeImage.cs" />
<Compile Include="TV\ITVSeriesManager.cs" />

@ -26,6 +26,11 @@ namespace MediaBrowser.Model.Sync
/// <value>The quality.</value>
public string Quality { get; set; }
/// <summary>
/// Gets or sets the bitrate.
/// </summary>
/// <value>The bitrate.</value>
public int? Bitrate { get; set; }
/// <summary>
/// Gets or sets the profile.
/// </summary>
/// <value>The profile.</value>

@ -59,6 +59,11 @@ namespace MediaBrowser.Model.Sync
/// </summary>
/// <value>The limit.</value>
public int? ItemLimit { get; set; }
/// <summary>
/// Gets or sets the bitrate.
/// </summary>
/// <value>The bitrate.</value>
public int? Bitrate { get; set; }
public SyncJobRequest()
{

@ -232,6 +232,7 @@
<Compile Include="Logging\PatternsLogger.cs" />
<Compile Include="MediaEncoder\EncodingManager.cs" />
<Compile Include="Sync\SyncHelper.cs" />
<Compile Include="Sync\SyncJobOptions.cs" />
<Compile Include="UserViews\DynamicImageProvider.cs" />
<Compile Include="News\NewsEntryPoint.cs" />
<Compile Include="News\NewsService.cs" />

@ -3,6 +3,7 @@ using MediaBrowser.Controller.Sync;
using MediaBrowser.Model.Devices;
using MediaBrowser.Model.Dlna;
using MediaBrowser.Model.Sync;
using System;
using System.Collections.Generic;
using System.Linq;
@ -92,5 +93,16 @@ namespace MediaBrowser.Server.Implementations.Sync
{
return new List<SyncProfileOption>();
}
public SyncJobOptions GetSyncJobOptions(SyncTarget target, string profile, string quality)
{
var isConverting = !string.Equals(quality, "original", StringComparison.OrdinalIgnoreCase);
return new SyncJobOptions
{
DeviceProfile = GetDeviceProfile(target, profile, quality),
IsConverting = isConverting
};
}
}
}

@ -1,5 +1,4 @@
using MediaBrowser.Model.Dlna;
using MediaBrowser.Model.Sync;
using MediaBrowser.Model.Sync;
using System.Collections.Generic;
namespace MediaBrowser.Server.Implementations.Sync
@ -13,7 +12,7 @@ namespace MediaBrowser.Server.Implementations.Sync
/// <param name="profile">The profile.</param>
/// <param name="quality">The quality.</param>
/// <returns>DeviceProfile.</returns>
DeviceProfile GetDeviceProfile(SyncTarget target, string profile, string quality);
SyncJobOptions GetSyncJobOptions(SyncTarget target, string profile, string quality);
/// <summary>
/// Gets the quality options.

@ -1,5 +1,4 @@
using System;
using System.Globalization;
namespace MediaBrowser.Server.Implementations.Sync
{
@ -17,14 +16,6 @@ namespace MediaBrowser.Server.Implementations.Sync
{
profileBitrate = Convert.ToInt32(profileBitrate.Value*.5);
}
else
{
int value;
if (int.TryParse(quality, NumberStyles.Any, CultureInfo.InvariantCulture, out value))
{
profileBitrate = value;
}
}
}
return profileBitrate;

@ -1,15 +1,14 @@
using MediaBrowser.Model.Dlna;
namespace MediaBrowser.Controller.Sync
namespace MediaBrowser.Server.Implementations.Sync
{
public class SyncJobOptions<T>
where T : AudioOptions, new ()
public class SyncJobOptions
{
/// <summary>
/// Gets or sets the conversion options.
/// </summary>
/// <value>The conversion options.</value>
public T ConversionOptions { get; set; }
public DeviceProfile DeviceProfile { get; set; }
/// <summary>
/// Gets or sets a value indicating whether this instance is converting.
/// </summary>

@ -479,7 +479,10 @@ namespace MediaBrowser.Server.Implementations.Sync
private async Task Sync(SyncJobItem jobItem, SyncJob job, Video item, User user, bool enableConversion, IProgress<double> progress, CancellationToken cancellationToken)
{
var jobOptions = _syncManager.GetVideoOptions(jobItem, job);
var conversionOptions = jobOptions.ConversionOptions;
var conversionOptions = new VideoOptions
{
Profile = jobOptions.DeviceProfile
};
conversionOptions.DeviceId = jobItem.TargetId;
conversionOptions.Context = EncodingContext.Static;
@ -672,7 +675,10 @@ namespace MediaBrowser.Server.Implementations.Sync
private async Task Sync(SyncJobItem jobItem, SyncJob job, Audio item, User user, bool enableConversion, IProgress<double> progress, CancellationToken cancellationToken)
{
var jobOptions = _syncManager.GetAudioOptions(jobItem, job);
var conversionOptions = jobOptions.ConversionOptions;
var conversionOptions = new AudioOptions
{
Profile = jobOptions.DeviceProfile
};
conversionOptions.DeviceId = jobItem.TargetId;
conversionOptions.Context = EncodingContext.Static;

@ -160,7 +160,8 @@ namespace MediaBrowser.Server.Implementations.Sync
Category = request.Category,
ParentId = request.ParentId,
Quality = request.Quality,
Profile = request.Profile
Profile = request.Profile,
Bitrate = request.Bitrate
};
if (!request.Category.HasValue && request.ItemIds != null)
@ -982,38 +983,31 @@ namespace MediaBrowser.Server.Implementations.Sync
return _repo.GetLibraryItemIds(query);
}
private bool IsOriginalQuality(SyncJob job)
public SyncJobOptions GetAudioOptions(SyncJobItem jobItem, SyncJob job)
{
return string.IsNullOrWhiteSpace(job.Quality) ||
string.Equals(job.Quality, "original", StringComparison.OrdinalIgnoreCase) ||
string.Equals(job.Profile, "original", StringComparison.OrdinalIgnoreCase);
}
public SyncJobOptions<AudioOptions> GetAudioOptions(SyncJobItem jobItem, SyncJob job)
{
return new SyncJobOptions<AudioOptions>
var options = GetSyncJobOptions(jobItem.TargetId, null, null);
if (job.Bitrate.HasValue)
{
ConversionOptions = new AudioOptions
{
Profile = GetDeviceProfile(jobItem.TargetId, null, null)
},
IsConverting = !IsOriginalQuality(job)
};
options.DeviceProfile.MaxStaticBitrate = job.Bitrate.Value;
}
return options;
}
public SyncJobOptions<VideoOptions> GetVideoOptions(SyncJobItem jobItem, SyncJob job)
public SyncJobOptions GetVideoOptions(SyncJobItem jobItem, SyncJob job)
{
return new SyncJobOptions<VideoOptions>
var options = GetSyncJobOptions(jobItem.TargetId, job.Profile, job.Quality);
if (job.Bitrate.HasValue)
{
ConversionOptions = new VideoOptions
{
Profile = GetDeviceProfile(jobItem.TargetId, job.Profile, job.Quality)
},
IsConverting = !IsOriginalQuality(job)
};
options.DeviceProfile.MaxStaticBitrate = job.Bitrate.Value;
}
return options;
}
private DeviceProfile GetDeviceProfile(string targetId, string profile, string quality)
private SyncJobOptions GetSyncJobOptions(string targetId, string profile, string quality)
{
foreach (var provider in _providers)
{
@ -1021,32 +1015,41 @@ namespace MediaBrowser.Server.Implementations.Sync
{
if (string.Equals(target.Id, targetId, StringComparison.OrdinalIgnoreCase))
{
return GetDeviceProfile(provider, target, profile, quality);
return GetSyncJobOptions(provider, target, profile, quality);
}
}
}
return null;
return GetDefaultSyncJobOptions(profile, quality);
}
private DeviceProfile GetDeviceProfile(ISyncProvider provider, SyncTarget target, string profile, string quality)
private SyncJobOptions GetSyncJobOptions(ISyncProvider provider, SyncTarget target, string profile, string quality)
{
var hasProfile = provider as IHasSyncQuality;
if (hasProfile != null)
{
return hasProfile.GetDeviceProfile(target, profile, quality);
return hasProfile.GetSyncJobOptions(target, profile, quality);
}
return GetDeviceProfile(profile, quality);
return GetDefaultSyncJobOptions(profile, quality);
}
private DeviceProfile GetDeviceProfile(string profile, string quality)
private SyncJobOptions GetDefaultSyncJobOptions(string profile, string quality)
{
var deviceProfile = new CloudSyncProfile(true, false);
deviceProfile.MaxStaticBitrate = SyncHelper.AdjustBitrate(deviceProfile.MaxStaticBitrate, quality);
return deviceProfile;
return new SyncJobOptions
{
DeviceProfile = deviceProfile,
IsConverting = IsConverting(profile, quality)
};
}
private bool IsConverting(string profile, string quality)
{
return !string.Equals(profile, "original", StringComparison.OrdinalIgnoreCase);
}
public IEnumerable<SyncQualityOption> GetQualityOptions(string targetId)

@ -1,5 +1,4 @@
using System.Text;
using MediaBrowser.Controller;
using MediaBrowser.Controller;
using MediaBrowser.Controller.Sync;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Logging;
@ -51,7 +50,7 @@ namespace MediaBrowser.Server.Implementations.Sync
string[] queries = {
"create table if not exists SyncJobs (Id GUID PRIMARY KEY, TargetId TEXT NOT NULL, Name TEXT NOT NULL, Profile TEXT, Quality TEXT, 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 table if not exists SyncJobs (Id GUID PRIMARY KEY, TargetId TEXT NOT NULL, Name TEXT NOT NULL, Profile TEXT, Quality TEXT, Bitrate INT, 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, TemporaryPath TEXT, OutputPath TEXT, Status TEXT, TargetId TEXT, DateCreated DateTime, Progress FLOAT, AdditionalFiles TEXT, MediaSource TEXT, IsMarkedForRemoval BIT, JobItemIndex INT)",
@ -66,7 +65,8 @@ namespace MediaBrowser.Server.Implementations.Sync
_connection.RunQueries(queries, _logger);
_connection.AddColumn(_logger, "SyncJobs", "Profile", "TEXT");
_connection.AddColumn(_logger, "SyncJobs", "Bitrate", "INT");
PrepareStatements();
}
@ -84,13 +84,14 @@ namespace MediaBrowser.Server.Implementations.Sync
// _insertJobCommand
_insertJobCommand = _connection.CreateCommand();
_insertJobCommand.CommandText = "insert into SyncJobs (Id, TargetId, Name, Profile, Quality, Status, Progress, UserId, ItemIds, Category, ParentId, UnwatchedOnly, ItemLimit, SyncNewContent, DateCreated, DateLastModified, ItemCount) values (@Id, @TargetId, @Name, @Profile, @Quality, @Status, @Progress, @UserId, @ItemIds, @Category, @ParentId, @UnwatchedOnly, @ItemLimit, @SyncNewContent, @DateCreated, @DateLastModified, @ItemCount)";
_insertJobCommand.CommandText = "insert into SyncJobs (Id, TargetId, Name, Profile, Quality, Bitrate, Status, Progress, UserId, ItemIds, Category, ParentId, UnwatchedOnly, ItemLimit, SyncNewContent, DateCreated, DateLastModified, ItemCount) values (@Id, @TargetId, @Name, @Profile, @Quality, @Bitrate, @Status, @Progress, @UserId, @ItemIds, @Category, @ParentId, @UnwatchedOnly, @ItemLimit, @SyncNewContent, @DateCreated, @DateLastModified, @ItemCount)";
_insertJobCommand.Parameters.Add(_insertJobCommand, "@Id");
_insertJobCommand.Parameters.Add(_insertJobCommand, "@TargetId");
_insertJobCommand.Parameters.Add(_insertJobCommand, "@Name");
_insertJobCommand.Parameters.Add(_insertJobCommand, "@Profile");
_insertJobCommand.Parameters.Add(_insertJobCommand, "@Quality");
_insertJobCommand.Parameters.Add(_insertJobCommand, "@Bitrate");
_insertJobCommand.Parameters.Add(_insertJobCommand, "@Status");
_insertJobCommand.Parameters.Add(_insertJobCommand, "@Progress");
_insertJobCommand.Parameters.Add(_insertJobCommand, "@UserId");
@ -106,13 +107,14 @@ namespace MediaBrowser.Server.Implementations.Sync
// _updateJobCommand
_updateJobCommand = _connection.CreateCommand();
_updateJobCommand.CommandText = "update SyncJobs set TargetId=@TargetId,Name=@Name,Profile=@Profile,Quality=@Quality,Status=@Status,Progress=@Progress,UserId=@UserId,ItemIds=@ItemIds,Category=@Category,ParentId=@ParentId,UnwatchedOnly=@UnwatchedOnly,ItemLimit=@ItemLimit,SyncNewContent=@SyncNewContent,DateCreated=@DateCreated,DateLastModified=@DateLastModified,ItemCount=@ItemCount where Id=@ID";
_updateJobCommand.CommandText = "update SyncJobs set TargetId=@TargetId,Name=@Name,Profile=@Profile,Quality=@Quality,Bitrate=@Bitrate,Status=@Status,Progress=@Progress,UserId=@UserId,ItemIds=@ItemIds,Category=@Category,ParentId=@ParentId,UnwatchedOnly=@UnwatchedOnly,ItemLimit=@ItemLimit,SyncNewContent=@SyncNewContent,DateCreated=@DateCreated,DateLastModified=@DateLastModified,ItemCount=@ItemCount where Id=@ID";
_updateJobCommand.Parameters.Add(_updateJobCommand, "@Id");
_updateJobCommand.Parameters.Add(_updateJobCommand, "@TargetId");
_updateJobCommand.Parameters.Add(_updateJobCommand, "@Name");
_updateJobCommand.Parameters.Add(_updateJobCommand, "@Profile");
_updateJobCommand.Parameters.Add(_updateJobCommand, "@Quality");
_updateJobCommand.Parameters.Add(_updateJobCommand, "@Bitrate");
_updateJobCommand.Parameters.Add(_updateJobCommand, "@Status");
_updateJobCommand.Parameters.Add(_updateJobCommand, "@Progress");
_updateJobCommand.Parameters.Add(_updateJobCommand, "@UserId");
@ -167,7 +169,7 @@ namespace MediaBrowser.Server.Implementations.Sync
_updateJobItemCommand.Parameters.Add(_updateJobItemCommand, "@JobItemIndex");
}
private const string BaseJobSelectText = "select Id, TargetId, Name, Profile, Quality, Status, Progress, UserId, ItemIds, Category, ParentId, UnwatchedOnly, ItemLimit, SyncNewContent, DateCreated, DateLastModified, ItemCount from SyncJobs";
private const string BaseJobSelectText = "select Id, TargetId, Name, Profile, Quality, Bitrate, Status, Progress, UserId, ItemIds, Category, ParentId, UnwatchedOnly, ItemLimit, SyncNewContent, DateCreated, DateLastModified, ItemCount from SyncJobs";
private const string BaseJobItemSelectText = "select Id, ItemId, ItemName, MediaSourceId, JobId, TemporaryPath, OutputPath, Status, TargetId, DateCreated, Progress, AdditionalFiles, MediaSource, IsMarkedForRemoval, JobItemIndex from SyncJobItems";
public SyncJob GetJob(string id)
@ -225,49 +227,54 @@ namespace MediaBrowser.Server.Implementations.Sync
if (!reader.IsDBNull(5))
{
info.Status = (SyncJobStatus)Enum.Parse(typeof(SyncJobStatus), reader.GetString(5), true);
info.Bitrate = reader.GetInt32(5);
}
if (!reader.IsDBNull(6))
{
info.Progress = reader.GetDouble(6);
info.Status = (SyncJobStatus)Enum.Parse(typeof(SyncJobStatus), reader.GetString(6), true);
}
if (!reader.IsDBNull(7))
{
info.UserId = reader.GetString(7);
info.Progress = reader.GetDouble(7);
}
if (!reader.IsDBNull(8))
{
info.RequestedItemIds = reader.GetString(8).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
info.UserId = reader.GetString(8);
}
if (!reader.IsDBNull(9))
{
info.Category = (SyncCategory)Enum.Parse(typeof(SyncCategory), reader.GetString(9), true);
info.RequestedItemIds = reader.GetString(9).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
}
if (!reader.IsDBNull(10))
{
info.ParentId = reader.GetString(10);
info.Category = (SyncCategory)Enum.Parse(typeof(SyncCategory), reader.GetString(10), true);
}
if (!reader.IsDBNull(11))
{
info.UnwatchedOnly = reader.GetBoolean(11);
info.ParentId = reader.GetString(11);
}
if (!reader.IsDBNull(12))
{
info.ItemLimit = reader.GetInt32(12);
info.UnwatchedOnly = reader.GetBoolean(12);
}
if (!reader.IsDBNull(13))
{
info.ItemLimit = reader.GetInt32(13);
}
info.SyncNewContent = reader.GetBoolean(13);
info.SyncNewContent = reader.GetBoolean(14);
info.DateCreated = reader.GetDateTime(14).ToUniversalTime();
info.DateLastModified = reader.GetDateTime(15).ToUniversalTime();
info.ItemCount = reader.GetInt32(16);
info.DateCreated = reader.GetDateTime(15).ToUniversalTime();
info.DateLastModified = reader.GetDateTime(16).ToUniversalTime();
info.ItemCount = reader.GetInt32(17);
return info;
}
@ -306,6 +313,7 @@ namespace MediaBrowser.Server.Implementations.Sync
cmd.GetParameter(index++).Value = job.Name;
cmd.GetParameter(index++).Value = job.Profile;
cmd.GetParameter(index++).Value = job.Quality;
cmd.GetParameter(index++).Value = job.Bitrate;
cmd.GetParameter(index++).Value = job.Status.ToString();
cmd.GetParameter(index++).Value = job.Progress;
cmd.GetParameter(index++).Value = job.UserId;

Loading…
Cancel
Save