From 6a332c03d77d1c36b2a784c51e427dd694d0be69 Mon Sep 17 00:00:00 2001 From: Todd King Date: Sat, 10 Apr 2021 22:02:06 +1000 Subject: [PATCH 1/8] Standardize Error Logging Error logging takes place at the call of the error rather than by throwing a new exception. Preventing unneeded 500 errors and restoring errors to the front user interface --- Emby.AutoOrganize/Core/EpisodeFileOrganizer.cs | 17 +++++++++-------- .../Core/FileOrganizationService.cs | 17 +---------------- Emby.AutoOrganize/Core/MovieFileOrganizer.cs | 5 +++-- Emby.AutoOrganize/Core/MovieFolderOrganizer.cs | 2 +- Emby.AutoOrganize/Core/TvFolderOrganizer.cs | 2 +- 5 files changed, 15 insertions(+), 28 deletions(-) diff --git a/Emby.AutoOrganize/Core/EpisodeFileOrganizer.cs b/Emby.AutoOrganize/Core/EpisodeFileOrganizer.cs index 8ce5d5c..795550d 100644 --- a/Emby.AutoOrganize/Core/EpisodeFileOrganizer.cs +++ b/Emby.AutoOrganize/Core/EpisodeFileOrganizer.cs @@ -193,7 +193,7 @@ await OrganizeEpisode(path, { result.Status = FileSortingStatus.Failure; result.StatusMessage = ex.Message; - _logger.ErrorException("Error organizing file", ex); + _logger.ErrorException("Error organizing file {0}", ex, path); } _organizationService.SaveResult(result, CancellationToken.None); @@ -337,6 +337,7 @@ await OrganizeEpisode(result.OriginalPath, { result.Status = FileSortingStatus.Failure; result.StatusMessage = ex.Message; + _logger.ErrorException("Error organizing file {0}", ex, result.OriginalPath); } return result; @@ -475,8 +476,8 @@ private void OrganizeEpisode(string sourcePath, { if (options.CopyOriginalFile && fileExists && IsSameEpisode(sourcePath, newPath)) { - var msg = string.Format("File '{0}' already copied to new path '{1}', stopping organization", sourcePath, newPath); - _logger.Info(msg); + var msg = string.Format("File '{0}' already copied to new path '{1}'", sourcePath, newPath); + _logger.Info(msg + " Stopping organization"); result.Status = FileSortingStatus.SkippedExisting; result.StatusMessage = msg; return; @@ -484,8 +485,8 @@ private void OrganizeEpisode(string sourcePath, if (fileExists) { - var msg = string.Format("File '{0}' already exists as '{1}', stopping organization", sourcePath, newPath); - _logger.Info(msg); + var msg = string.Format("File '{0}' already exists as '{1}'.", sourcePath, newPath); + _logger.Info(msg + " Stopping organization"); result.Status = FileSortingStatus.SkippedExisting; result.StatusMessage = msg; result.TargetPath = newPath; @@ -494,8 +495,8 @@ private void OrganizeEpisode(string sourcePath, if (otherDuplicatePaths.Count > 0) { - var msg = string.Format("File '{0}' already exists as these:'{1}'. Stopping organization", sourcePath, string.Join("', '", otherDuplicatePaths)); - _logger.Info(msg); + var msg = string.Format("File '{0}' already exists as these:'{1}'.", sourcePath, string.Join("', '", otherDuplicatePaths)); + _logger.Info(msg + " Stopping organization"); result.Status = FileSortingStatus.SkippedExisting; result.StatusMessage = msg; result.DuplicatePaths = otherDuplicatePaths; @@ -733,7 +734,7 @@ private void PerformFileSorting(TvFileOrganizationOptions options, FileOrganizat } catch (Exception ex) { - _logger.ErrorException("Error deleting {0}", ex, result.OriginalPath); + _logger.ErrorException("Error deleting file {0}", ex, result.OriginalPath); } } } diff --git a/Emby.AutoOrganize/Core/FileOrganizationService.cs b/Emby.AutoOrganize/Core/FileOrganizationService.cs index 67ba8d4..1df5884 100644 --- a/Emby.AutoOrganize/Core/FileOrganizationService.cs +++ b/Emby.AutoOrganize/Core/FileOrganizationService.cs @@ -128,7 +128,7 @@ public void DeleteOriginalFile(string resultId) } catch (Exception ex) { - _logger.ErrorException("Error deleting {0}", ex, result.OriginalPath); + _logger.ErrorException("Error deleting file {0}", ex, result.OriginalPath); } finally { @@ -177,11 +177,6 @@ public async Task PerformOrganization(string resultId) default: throw new OrganizationException("No organizer exist for the type " + result.Type); } - - if (organizeResult.Status != FileSortingStatus.Success) - { - throw new OrganizationException(result.StatusMessage); - } } public void ClearLog() @@ -203,11 +198,6 @@ public async Task PerformOrganization(EpisodeFileOrganizationRequest request) var options = GetAutoOrganizeOptions(); var result = await organizer.OrganizeWithCorrection(request, options.TvOptions, CancellationToken.None).ConfigureAwait(false); - - if (result.Status != FileSortingStatus.Success) - { - throw new Exception(result.StatusMessage); - } } public void PerformOrganization(MovieFileOrganizationRequest request) @@ -217,11 +207,6 @@ public void PerformOrganization(MovieFileOrganizationRequest request) var options = GetAutoOrganizeOptions(); var result = organizer.OrganizeWithCorrection(request, options.MovieOptions, CancellationToken.None); - - if (result.Status != FileSortingStatus.Success) - { - throw new Exception(result.StatusMessage); - } } public QueryResult GetSmartMatchInfos(FileOrganizationResultQuery query) diff --git a/Emby.AutoOrganize/Core/MovieFileOrganizer.cs b/Emby.AutoOrganize/Core/MovieFileOrganizer.cs index 83d32d8..551f457 100644 --- a/Emby.AutoOrganize/Core/MovieFileOrganizer.cs +++ b/Emby.AutoOrganize/Core/MovieFileOrganizer.cs @@ -107,7 +107,7 @@ await OrganizeMovie(path, { result.Status = FileSortingStatus.Failure; result.StatusMessage = ex.Message; - _logger.ErrorException("Error organizing file", ex); + _logger.ErrorException("Error organizing file {0}", ex, path); } _organizationService.SaveResult(result, CancellationToken.None); @@ -197,6 +197,7 @@ public FileOrganizationResult OrganizeWithCorrection(MovieFileOrganizationReques { result.Status = FileSortingStatus.Failure; result.StatusMessage = ex.Message; + _logger.ErrorException("Error organizing file {0}", ex, result.OriginalPath); } return result; @@ -378,7 +379,7 @@ private void PerformFileSorting(MovieFileOrganizationOptions options, FileOrgani } catch (Exception ex) { - _logger.ErrorException("Error deleting {0}", ex, result.OriginalPath); + _logger.ErrorException("Error deleting file {0}", ex, result.OriginalPath); } } } diff --git a/Emby.AutoOrganize/Core/MovieFolderOrganizer.cs b/Emby.AutoOrganize/Core/MovieFolderOrganizer.cs index bd86f81..e5144d9 100644 --- a/Emby.AutoOrganize/Core/MovieFolderOrganizer.cs +++ b/Emby.AutoOrganize/Core/MovieFolderOrganizer.cs @@ -109,7 +109,7 @@ public async Task Organize(MovieFileOrganizationOptions options, CancellationTok } catch (Exception ex) { - _logger.ErrorException("Error organizing episode {0}", ex, file.FullName); + _logger.ErrorException("Error organizing file {0}", ex, file.FullName); } numComplete++; diff --git a/Emby.AutoOrganize/Core/TvFolderOrganizer.cs b/Emby.AutoOrganize/Core/TvFolderOrganizer.cs index 701e06b..42e0bea 100644 --- a/Emby.AutoOrganize/Core/TvFolderOrganizer.cs +++ b/Emby.AutoOrganize/Core/TvFolderOrganizer.cs @@ -110,7 +110,7 @@ public async Task Organize(TvFileOrganizationOptions options, } catch (Exception ex) { - _logger.ErrorException("Error organizing episode {0}", ex, file.FullName); + _logger.ErrorException("Error organizing file {0}", ex, file.FullName); } numComplete++; From 5250cd08030cd96211e2c314bd61bb3f31345485 Mon Sep 17 00:00:00 2001 From: Todd King Date: Sun, 11 Apr 2021 00:35:53 +1000 Subject: [PATCH 2/8] fix throbber.gif removed dependency on throbber.gif and instead use mdl-spinner with custom css --- Emby.AutoOrganize/Configuration/autoorganizelog.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Emby.AutoOrganize/Configuration/autoorganizelog.js b/Emby.AutoOrganize/Configuration/autoorganizelog.js index 214c72e..6982721 100644 --- a/Emby.AutoOrganize/Configuration/autoorganizelog.js +++ b/Emby.AutoOrganize/Configuration/autoorganizelog.js @@ -386,9 +386,14 @@ var html = ''; - html += ''; + html += ''; var hide = item.IsInProgress ? '' : ' hide'; - html += ''; + html += '
'; + html += '
'; + html += '
'; + html += '
'; + html += '
'; + html += '
'; html += ''; html += ''; From 0c2c16fffe5fdf06894818738b829180d6a4799a Mon Sep 17 00:00:00 2001 From: kingy444 Date: Wed, 14 Apr 2021 21:41:09 +1000 Subject: [PATCH 3/8] Allow/Not Allow multiple episode copies Changes to allow keeping only one copy of an episode --- .../Configuration/autoorganizelog.js | 11 +- .../Configuration/autoorganizetv.html | 13 ++- .../Configuration/autoorganizetv.js | 2 + .../Core/EpisodeFileOrganizer.cs | 107 ++++++++++-------- .../Model/TvFileOrganizationOptions.cs | 4 + 5 files changed, 86 insertions(+), 51 deletions(-) diff --git a/Emby.AutoOrganize/Configuration/autoorganizelog.js b/Emby.AutoOrganize/Configuration/autoorganizelog.js index 6982721..f94e62d 100644 --- a/Emby.AutoOrganize/Configuration/autoorganizelog.js +++ b/Emby.AutoOrganize/Configuration/autoorganizelog.js @@ -193,11 +193,16 @@ return; } - var message = 'The following file will be moved from:' + '

' + item.OriginalPath + '

' + 'To:' + '

' + item.TargetPath; + for (var i = 0; i < item.DuplicatePaths.length; i++) { //remove the target filename from the list (as we will overwrite it and better for display) + if (item.DuplicatePaths[i].replace(/^.*[\\\/]/, '') === item.TargetPath.replace(/^.*[\\\/]/, '')) { + item.DuplicatePaths.splice(i, 1); + i--; + } + } - if (item.DuplicatePaths.length) { + var message = 'The following file will be moved from:' + '

' + item.OriginalPath + '

' + 'To:' + '

' + item.TargetPath; + if (item.DuplicatePaths.length > 0) { message += '

' + 'The following duplicates will be deleted:'; - message += '

' + item.DuplicatePaths.join('
'); } diff --git a/Emby.AutoOrganize/Configuration/autoorganizetv.html b/Emby.AutoOrganize/Configuration/autoorganizetv.html index 094a2e7..2f1e7f5 100644 --- a/Emby.AutoOrganize/Configuration/autoorganizetv.html +++ b/Emby.AutoOrganize/Configuration/autoorganizetv.html @@ -189,11 +189,20 @@
Copy or move files from the watch folder
-
-
- -

+
+
+ +
'TBA' is often set before the true name of an episode is known. Disabling this will prevent episodes being moved until a valid name is provided.
+