switch recordings to ts when preserving original audio

This commit is contained in:
Luke Pulverenti 2016-06-12 19:33:11 -04:00
parent f378a2c789
commit 383110f9af
7 changed files with 1709 additions and 1783 deletions

View File

@ -194,6 +194,8 @@ namespace MediaBrowser.Providers.TV
}
private async void LibraryUpdateTimerCallback(object state)
{
try
{
if (MissingEpisodeProvider.IsRunning)
{
@ -202,7 +204,7 @@ namespace MediaBrowser.Providers.TV
if (_libraryManager.IsScanRunning)
{
return ;
return;
}
var seriesList = _libraryManager.GetItemList(new InternalItemsQuery()
@ -218,6 +220,11 @@ namespace MediaBrowser.Providers.TV
await new MissingEpisodeProvider(_logger, _config, _libraryManager, _localization, _fileSystem)
.Run(seriesGroups, false, CancellationToken.None).ConfigureAwait(false);
}
catch (Exception ex)
{
_logger.ErrorException("Error in SeriesPostScanTask", ex);
}
}
private bool FilterItem(BaseItem item)
{

View File

@ -50,7 +50,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
var streams = mediaSource.MediaStreams ?? new List<MediaStream>();
if (streams.Any(i => i.Type == MediaStreamType.Audio && (i.Codec ?? string.Empty).IndexOf("aac", StringComparison.OrdinalIgnoreCase) != -1))
{
return Path.ChangeExtension(targetFile, ".mkv");
return Path.ChangeExtension(targetFile, ".ts");
}
}

View File

@ -8,6 +8,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
{
public abstract class BaseSqliteRepository : IDisposable
{
protected readonly SemaphoreSlim WriteLock = new SemaphoreSlim(1, 1);
protected readonly IDbConnector DbConnector;
protected ILogger Logger;
@ -19,11 +20,16 @@ namespace MediaBrowser.Server.Implementations.Persistence
Logger = logManager.GetLogger(GetType().Name);
}
protected virtual bool EnableConnectionPooling
{
get { return true; }
}
protected virtual async Task<IDbConnection> CreateConnection(bool isReadOnly = false)
{
var connection = await DbConnector.Connect(DbFilePath, false, true).ConfigureAwait(false);
connection.RunQueries(new []
connection.RunQueries(new[]
{
"pragma temp_store = memory"
@ -45,12 +51,15 @@ namespace MediaBrowser.Server.Implementations.Persistence
{
_disposed = true;
Dispose(true);
GC.SuppressFinalize(this);
}
protected async Task Vacuum(IDbConnection connection)
{
CheckDisposed();
await WriteLock.WaitAsync().ConfigureAwait(false);
try
{
using (var cmd = connection.CreateCommand())
@ -65,7 +74,13 @@ namespace MediaBrowser.Server.Implementations.Persistence
throw;
}
finally
{
WriteLock.Release();
}
}
private readonly object _disposeLock = new object();
/// <summary>
/// Releases unmanaged and - optionally - managed resources.
@ -73,6 +88,27 @@ namespace MediaBrowser.Server.Implementations.Persistence
/// <param name="dispose"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
protected virtual void Dispose(bool dispose)
{
if (dispose)
{
try
{
lock (_disposeLock)
{
WriteLock.Wait();
CloseConnection();
}
}
catch (Exception ex)
{
Logger.ErrorException("Error disposing database", ex);
}
}
}
protected virtual void CloseConnection()
{
}
}
}

View File

@ -39,12 +39,8 @@ namespace MediaBrowser.Server.Implementations.Persistence
var connectionString = connectionstr.ConnectionString;
if (enablePooling)
{
connectionString += ";Max Pool Size=100";
}
//logger.Info("Sqlite {0} opening {1}", SQLiteConnection.SQLiteVersion, connectionString);
SQLiteConnection.SetMemoryStatus(false);
var connection = new SQLiteConnection(connectionString);

View File

@ -15,11 +15,18 @@ namespace MediaBrowser.Server.Implementations.Persistence
{
public class SqliteUserDataRepository : BaseSqliteRepository, IUserDataRepository
{
private IDbConnection _connection;
public SqliteUserDataRepository(ILogManager logManager, IApplicationPaths appPaths, IDbConnector connector) : base(logManager, connector)
{
DbFilePath = Path.Combine(appPaths.DataPath, "userdata_v2.db");
}
protected override bool EnableConnectionPooling
{
get { return false; }
}
/// <summary>
/// Gets the name of the repository
/// </summary>
@ -36,23 +43,27 @@ namespace MediaBrowser.Server.Implementations.Persistence
/// Opens the connection to the database
/// </summary>
/// <returns>Task.</returns>
public async Task Initialize(IDbConnector dbConnector)
{
using (var connection = await CreateConnection().ConfigureAwait(false))
public async Task Initialize()
{
_connection = await CreateConnection(false).ConfigureAwait(false);
string[] queries = {
"create table if not exists userdata (key nvarchar, userId GUID, rating float null, played bit, playCount int, isFavorite bit, playbackPositionTicks bigint, lastPlayedDate datetime null)",
"create index if not exists idx_userdata on userdata(key)",
"create unique index if not exists userdataindex on userdata (key, userId)"
"create unique index if not exists userdataindex on userdata (key, userId)",
//pragmas
"pragma temp_store = memory",
"pragma shrink_memory"
};
connection.RunQueries(queries, Logger);
_connection.RunQueries(queries, Logger);
connection.AddColumn(Logger, "userdata", "AudioStreamIndex", "int");
connection.AddColumn(Logger, "userdata", "SubtitleStreamIndex", "int");
}
_connection.AddColumn(Logger, "userdata", "AudioStreamIndex", "int");
_connection.AddColumn(Logger, "userdata", "SubtitleStreamIndex", "int");
}
/// <summary>
@ -114,15 +125,15 @@ namespace MediaBrowser.Server.Implementations.Persistence
{
cancellationToken.ThrowIfCancellationRequested();
using (var connection = await CreateConnection().ConfigureAwait(false))
{
await WriteLock.WaitAsync(cancellationToken).ConfigureAwait(false);
IDbTransaction transaction = null;
try
{
transaction = connection.BeginTransaction();
transaction = _connection.BeginTransaction();
using (var cmd = connection.CreateCommand())
using (var cmd = _connection.CreateCommand())
{
cmd.CommandText = "replace into userdata (key, userId, rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex) values (@key, @userId, @rating,@played,@playCount,@isFavorite,@playbackPositionTicks,@lastPlayedDate,@AudioStreamIndex,@SubtitleStreamIndex)";
@ -170,7 +181,8 @@ namespace MediaBrowser.Server.Implementations.Persistence
{
transaction.Dispose();
}
}
WriteLock.Release();
}
}
@ -185,17 +197,17 @@ namespace MediaBrowser.Server.Implementations.Persistence
{
cancellationToken.ThrowIfCancellationRequested();
using (var connection = await CreateConnection().ConfigureAwait(false))
{
await WriteLock.WaitAsync(cancellationToken).ConfigureAwait(false);
IDbTransaction transaction = null;
try
{
transaction = connection.BeginTransaction();
transaction = _connection.BeginTransaction();
foreach (var userItemData in userData)
{
using (var cmd = connection.CreateCommand())
using (var cmd = _connection.CreateCommand())
{
cmd.CommandText = "replace into userdata (key, userId, rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex) values (@key, @userId, @rating,@played,@playCount,@isFavorite,@playbackPositionTicks,@lastPlayedDate,@AudioStreamIndex,@SubtitleStreamIndex)";
@ -246,7 +258,8 @@ namespace MediaBrowser.Server.Implementations.Persistence
{
transaction.Dispose();
}
}
WriteLock.Release();
}
}
@ -272,9 +285,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
throw new ArgumentNullException("key");
}
using (var connection = CreateConnection(true).Result)
{
using (var cmd = connection.CreateCommand())
using (var cmd = _connection.CreateCommand())
{
cmd.CommandText = "select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where key = @key and userId=@userId";
@ -292,7 +303,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
return null;
}
}
}
public UserItemData GetUserData(Guid userId, List<string> keys)
{
@ -305,9 +315,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
throw new ArgumentNullException("keys");
}
using (var connection = CreateConnection(true).Result)
{
using (var cmd = connection.CreateCommand())
using (var cmd = _connection.CreateCommand())
{
var index = 0;
var excludeIds = new List<string>();
@ -341,7 +349,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
return null;
}
}
}
/// <summary>
/// Return all user-data associated with the given user
@ -355,11 +362,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
throw new ArgumentNullException("userId");
}
var list = new List<UserItemData>();
using (var connection = CreateConnection(true).Result)
{
using (var cmd = connection.CreateCommand())
using (var cmd = _connection.CreateCommand())
{
cmd.CommandText = "select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where userId=@userId";
@ -369,15 +372,12 @@ namespace MediaBrowser.Server.Implementations.Persistence
{
while (reader.Read())
{
list.Add(ReadRow(reader));
yield return ReadRow(reader);
}
}
}
}
return list;
}
/// <summary>
/// Read a row from the specified reader into the provided userData object
/// </summary>
@ -416,5 +416,19 @@ namespace MediaBrowser.Server.Implementations.Persistence
return userData;
}
protected override void CloseConnection()
{
if (_connection != null)
{
if (_connection.IsOpen())
{
_connection.Close();
}
_connection.Dispose();
_connection = null;
}
}
}
}

View File

@ -573,7 +573,7 @@ namespace MediaBrowser.Server.Startup.Common
await displayPreferencesRepo.Initialize().ConfigureAwait(false);
await ConfigureUserDataRepositories().ConfigureAwait(false);
await itemRepo.Initialize(NativeApp.GetDbConnector()).ConfigureAwait(false);
await itemRepo.Initialize().ConfigureAwait(false);
((LibraryManager)LibraryManager).ItemRepository = ItemRepository;
await ConfigureNotificationsRepository().ConfigureAwait(false);
progress.Report(100);
@ -746,7 +746,7 @@ namespace MediaBrowser.Server.Startup.Common
{
var repo = new SqliteUserDataRepository(LogManager, ApplicationPaths, NativeApp.GetDbConnector());
await repo.Initialize(NativeApp.GetDbConnector()).ConfigureAwait(false);
await repo.Initialize().ConfigureAwait(false);
((UserDataManager)UserDataManager).Repository = repo;
}