add new sync methods

This commit is contained in:
Luke Pulverenti
2014-12-15 00:16:23 -05:00
parent ed31b883f4
commit e92e036574
21 changed files with 169 additions and 59 deletions

View File

@@ -1708,7 +1708,7 @@ namespace MediaBrowser.Server.Implementations.Library
public int? GetSeasonNumberFromPath(string path)
{
return SeriesResolver.GetSeasonNumberFromPath(path);
return SeriesResolver.GetSeasonNumberFromPath(path, CollectionType.TvShows);
}
public int? GetSeasonNumberFromEpisodeFile(string path)

View File

@@ -1,5 +1,4 @@
using MediaBrowser.Common.IO;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Entities.TV;
@@ -9,10 +8,10 @@ using MediaBrowser.Controller.Resolvers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using MediaBrowser.Naming.Audio;
using MediaBrowser.Naming.Common;
using System;
using System.Collections.Generic;
using System.IO;
using MediaBrowser.Naming.Common;
namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio
{
@@ -53,10 +52,10 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio
//Avoid mis-identifying top folders
if (args.Parent == null) return null;
if (args.Parent.IsRoot) return null;
if (args.Parent is MusicAlbum) return null;
if (args.HasParent<MusicAlbum>()) return null;
// Optimization
if (args.Parent is BoxSet || args.Parent is Series || args.Parent is Season)
if (args.HasParent<BoxSet>() || args.HasParent<Series>() || args.HasParent<Season>())
{
return null;
}

View File

@@ -51,13 +51,13 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio
if (args.Parent.IsRoot) return null;
// Don't allow nested artists
if (args.Parent is MusicArtist)
if (args.HasParent<MusicArtist>() || args.HasParent<MusicAlbum>())
{
return null;
}
// Optimization
if (args.Parent is BoxSet || args.Parent is Series || args.Parent is Season)
if (args.HasParent<BoxSet>() || args.HasParent<Series>() || args.HasParent<Season>())
{
return null;
}

View File

@@ -456,7 +456,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
// Don't do any resolving within a series structure
if (string.IsNullOrEmpty(collectionType))
{
if (parent is Season || parent is Series)
if (HasParent<Series>(parent) || HasParent<Season>(parent))
{
return true;
}
@@ -480,5 +480,25 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
return !validCollectionTypes.Contains(collectionType ?? string.Empty, StringComparer.OrdinalIgnoreCase);
}
private bool HasParent<T>(Folder parent)
where T : Folder
{
if (parent != null)
{
var item = parent as T;
// Just in case the user decided to nest episodes.
// Not officially supported but in some cases we can handle it.
if (item == null)
{
item = parent.Parents.OfType<T>().FirstOrDefault();
}
return item != null;
}
return false;
}
}
}

View File

@@ -1,6 +1,7 @@
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV
{
@@ -34,7 +35,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV
{
var season = new Season
{
IndexNumber = SeriesResolver.GetSeasonNumberFromPath(args.Path)
IndexNumber = SeriesResolver.GetSeasonNumberFromPath(args.Path, CollectionType.TvShows)
};
if (season.IndexNumber.HasValue && season.IndexNumber.Value == 0)

View File

@@ -60,7 +60,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV
}
// Optimization to avoid running these tests against Seasons
if (args.Parent is Series || args.Parent is Season || args.Parent is MusicArtist || args.Parent is MusicAlbum)
if (args.HasParent<Series>() || args.HasParent<Season>() || args.HasParent<MusicArtist>() || args.HasParent<MusicAlbum>())
{
return null;
}
@@ -78,7 +78,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV
return null;
}
if (IsSeriesFolder(args.Path, isTvShowsFolder, args.FileSystemChildren, args.DirectoryService, _fileSystem, _logger, _libraryManager))
if (IsSeriesFolder(args.Path, collectionType, args.FileSystemChildren, args.DirectoryService, _fileSystem, _logger, _libraryManager))
{
return new Series
{
@@ -95,14 +95,14 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV
/// Determines whether [is series folder] [the specified path].
/// </summary>
/// <param name="path">The path.</param>
/// <param name="considerSeasonlessEntries">if set to <c>true</c> [consider seasonless entries].</param>
/// <param name="collectionType">Type of the collection.</param>
/// <param name="fileSystemChildren">The file system children.</param>
/// <param name="directoryService">The directory service.</param>
/// <param name="fileSystem">The file system.</param>
/// <param name="logger">The logger.</param>
/// <param name="libraryManager">The library manager.</param>
/// <returns><c>true</c> if [is series folder] [the specified path]; otherwise, <c>false</c>.</returns>
public static bool IsSeriesFolder(string path, bool considerSeasonlessEntries, IEnumerable<FileSystemInfo> fileSystemChildren, IDirectoryService directoryService, IFileSystem fileSystem, ILogger logger, ILibraryManager libraryManager)
public static bool IsSeriesFolder(string path, string collectionType, IEnumerable<FileSystemInfo> fileSystemChildren, IDirectoryService directoryService, IFileSystem fileSystem, ILogger logger, ILibraryManager libraryManager)
{
foreach (var child in fileSystemChildren)
{
@@ -123,7 +123,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV
if ((attributes & FileAttributes.Directory) == FileAttributes.Directory)
{
if (IsSeasonFolder(child.FullName, directoryService, fileSystem))
if (IsSeasonFolder(child.FullName, collectionType, directoryService, fileSystem))
{
//logger.Debug("{0} is a series because of season folder {1}.", path, child.FullName);
return true;
@@ -135,7 +135,9 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV
if (libraryManager.IsVideoFile(fullName) || IsVideoPlaceHolder(fullName))
{
if (GetEpisodeNumberFromFile(fullName, considerSeasonlessEntries).HasValue)
var isTvShowsFolder = string.Equals(collectionType, CollectionType.TvShows, StringComparison.OrdinalIgnoreCase);
if (GetEpisodeNumberFromFile(fullName, isTvShowsFolder).HasValue)
{
return true;
}
@@ -169,12 +171,13 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV
/// Determines whether [is season folder] [the specified path].
/// </summary>
/// <param name="path">The path.</param>
/// <param name="collectionType">Type of the collection.</param>
/// <param name="directoryService">The directory service.</param>
/// <param name="fileSystem">The file system.</param>
/// <returns><c>true</c> if [is season folder] [the specified path]; otherwise, <c>false</c>.</returns>
private static bool IsSeasonFolder(string path, IDirectoryService directoryService, IFileSystem fileSystem)
private static bool IsSeasonFolder(string path, string collectionType, IDirectoryService directoryService, IFileSystem fileSystem)
{
var seasonNumber = GetSeasonNumberFromPath(path);
var seasonNumber = GetSeasonNumberFromPath(path, collectionType);
var hasSeasonNumber = seasonNumber != null;
if (!hasSeasonNumber)
@@ -309,18 +312,27 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV
// "blah - 01.avi", "blah 2 - 01.avi", "blah - 01 blah.avi", "blah 2 - 01 blah", "blah - 01 - blah.avi", "blah 2 - 01 - blah"
};
public static int? GetSeasonNumberFromPath(string path)
{
return GetSeasonNumberFromPath(path, CollectionType.TvShows);
}
/// <summary>
/// Gets the season number from path.
/// </summary>
/// <param name="path">The path.</param>
/// <param name="collectionType">Type of the collection.</param>
/// <returns>System.Nullable{System.Int32}.</returns>
public static int? GetSeasonNumberFromPath(string path)
public static int? GetSeasonNumberFromPath(string path, string collectionType)
{
var filename = Path.GetFileName(path);
if (string.Equals(filename, "specials", StringComparison.OrdinalIgnoreCase))
if (string.Equals(collectionType, CollectionType.TvShows, StringComparison.OrdinalIgnoreCase))
{
return 0;
if (string.Equals(filename, "specials", StringComparison.OrdinalIgnoreCase))
{
return 0;
}
}
int val;

View File

@@ -84,7 +84,6 @@ namespace MediaBrowser.Server.Implementations.Sync
DateCreated = DateTime.UtcNow,
DateLastModified = DateTime.UtcNow,
SyncNewContent = request.SyncNewContent,
RemoveWhenWatched = request.RemoveWhenWatched,
ItemCount = items.Count,
Quality = request.Quality
};

View File

@@ -35,13 +35,13 @@ namespace MediaBrowser.Server.Implementations.Sync
public async Task Initialize()
{
var dbFile = Path.Combine(_appPaths.DataPath, "sync4.db");
var dbFile = Path.Combine(_appPaths.DataPath, "sync5.db");
_connection = await SqliteExtensions.ConnectToDb(dbFile, _logger).ConfigureAwait(false);
string[] queries = {
"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, UnwatchedOnly BIT, ItemLimit INT, RemoveWhenWatched BIT, 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, Quality TEXT NOT NULL, Status TEXT NOT NULL, Progress FLOAT, UserId TEXT NOT NULL, ItemIds TEXT NOT NULL, 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, JobId TEXT, OutputPath TEXT, Status TEXT, TargetId TEXT, DateCreated DateTime, Progress FLOAT)",
@@ -65,7 +65,7 @@ namespace MediaBrowser.Server.Implementations.Sync
_deleteJobCommand.Parameters.Add(_deleteJobCommand, "@Id");
_saveJobCommand = _connection.CreateCommand();
_saveJobCommand.CommandText = "replace into SyncJobs (Id, TargetId, Name, Quality, Status, Progress, UserId, ItemIds, UnwatchedOnly, ItemLimit, RemoveWhenWatched, SyncNewContent, DateCreated, DateLastModified, ItemCount) values (@Id, @TargetId, @Name, @Quality, @Status, @Progress, @UserId, @ItemIds, @UnwatchedOnly, @ItemLimit, @RemoveWhenWatched, @SyncNewContent, @DateCreated, @DateLastModified, @ItemCount)";
_saveJobCommand.CommandText = "replace into SyncJobs (Id, TargetId, Name, Quality, Status, Progress, UserId, ItemIds, UnwatchedOnly, ItemLimit, SyncNewContent, DateCreated, DateLastModified, ItemCount) values (@Id, @TargetId, @Name, @Quality, @Status, @Progress, @UserId, @ItemIds, @UnwatchedOnly, @ItemLimit, @SyncNewContent, @DateCreated, @DateLastModified, @ItemCount)";
_saveJobCommand.Parameters.Add(_saveJobCommand, "@Id");
_saveJobCommand.Parameters.Add(_saveJobCommand, "@TargetId");
@@ -77,7 +77,6 @@ namespace MediaBrowser.Server.Implementations.Sync
_saveJobCommand.Parameters.Add(_saveJobCommand, "@ItemIds");
_saveJobCommand.Parameters.Add(_saveJobCommand, "@UnwatchedOnly");
_saveJobCommand.Parameters.Add(_saveJobCommand, "@ItemLimit");
_saveJobCommand.Parameters.Add(_saveJobCommand, "@RemoveWhenWatched");
_saveJobCommand.Parameters.Add(_saveJobCommand, "@SyncNewContent");
_saveJobCommand.Parameters.Add(_saveJobCommand, "@DateCreated");
_saveJobCommand.Parameters.Add(_saveJobCommand, "@DateLastModified");
@@ -96,7 +95,7 @@ namespace MediaBrowser.Server.Implementations.Sync
_saveJobItemCommand.Parameters.Add(_saveJobCommand, "@Progress");
}
private const string BaseJobSelectText = "select Id, TargetId, Name, Quality, Status, Progress, UserId, ItemIds, UnwatchedOnly, ItemLimit, RemoveWhenWatched, SyncNewContent, DateCreated, DateLastModified, ItemCount from SyncJobs";
private const string BaseJobSelectText = "select Id, TargetId, Name, Quality, Status, Progress, UserId, ItemIds, UnwatchedOnly, ItemLimit, SyncNewContent, DateCreated, DateLastModified, ItemCount from SyncJobs";
private const string BaseJobItemSelectText = "select Id, ItemId, JobId, OutputPath, Status, TargetId, DateCreated, Progress from SyncJobItems";
public SyncJob GetJob(string id)
@@ -175,12 +174,11 @@ namespace MediaBrowser.Server.Implementations.Sync
info.ItemLimit = reader.GetInt32(9);
}
info.RemoveWhenWatched = reader.GetBoolean(10);
info.SyncNewContent = reader.GetBoolean(11);
info.SyncNewContent = reader.GetBoolean(10);
info.DateCreated = reader.GetDateTime(12).ToUniversalTime();
info.DateLastModified = reader.GetDateTime(13).ToUniversalTime();
info.ItemCount = reader.GetInt32(14);
info.DateCreated = reader.GetDateTime(11).ToUniversalTime();
info.DateLastModified = reader.GetDateTime(12).ToUniversalTime();
info.ItemCount = reader.GetInt32(13);
return info;
}
@@ -217,7 +215,6 @@ namespace MediaBrowser.Server.Implementations.Sync
_saveJobCommand.GetParameter(index++).Value = string.Join(",", job.RequestedItemIds.ToArray());
_saveJobCommand.GetParameter(index++).Value = job.UnwatchedOnly;
_saveJobCommand.GetParameter(index++).Value = job.ItemLimit;
_saveJobCommand.GetParameter(index++).Value = job.RemoveWhenWatched;
_saveJobCommand.GetParameter(index++).Value = job.SyncNewContent;
_saveJobCommand.GetParameter(index++).Value = job.DateCreated;
_saveJobCommand.GetParameter(index++).Value = job.DateLastModified;