Skip to content

Commit

Permalink
fix: catch directory not existing
Browse files Browse the repository at this point in the history
  • Loading branch information
revam committed Sep 25, 2023
1 parent 36e5e52 commit 6a1edfb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 20 deletions.
26 changes: 14 additions & 12 deletions Shokofin/LibraryScanner.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.IO;
using System.Linq;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
Expand All @@ -8,8 +9,6 @@
using Shokofin.API.Models;
using Shokofin.Utils;

using Path = System.IO.Path;

namespace Shokofin
{
public class LibraryScanner : IResolverIgnoreRule
Expand Down Expand Up @@ -92,18 +91,21 @@ private bool ScanDirectory(string partialPath, string fullPath, string libraryTy
if (season == null) {
// If we're in strict mode, then check the sub-directories if we have a <Show>/<Season>/<Episodes> structure.
if (shouldIgnore && partialPath[1..].Split(Path.DirectorySeparatorChar).Length == 1) {
var entries = FileSystem.GetDirectories(fullPath, false).ToList();
Logger.LogDebug("Unable to find shoko series for {Path}, trying {DirCount} sub-directories.", entries.Count, partialPath);
foreach (var entry in entries) {
season = ApiManager.GetSeasonInfoByPath(entry.FullName)
.GetAwaiter()
.GetResult();
if (season != null)
{
Logger.LogDebug("Found shoko series {SeriesName} for sub-directory of path {Path} (Series={SeriesId})", season.Shoko.Name, partialPath, season.Id);
break;
try {
var entries = FileSystem.GetDirectories(fullPath, false).ToList();
Logger.LogDebug("Unable to find shoko series for {Path}, trying {DirCount} sub-directories.", partialPath, entries.Count);
foreach (var entry in entries) {
season = ApiManager.GetSeasonInfoByPath(entry.FullName)
.GetAwaiter()
.GetResult();
if (season != null)
{
Logger.LogDebug("Found shoko series {SeriesName} for sub-directory of path {Path} (Series={SeriesId})", season.Shoko.Name, partialPath, season.Id);
break;
}
}
}
catch (DirectoryNotFoundException) { }
}
if (season == null) {
if (shouldIgnore)
Expand Down
22 changes: 14 additions & 8 deletions Shokofin/Providers/SeriesProvider.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Threading;
Expand Down Expand Up @@ -42,15 +43,20 @@ public async Task<MetadataResult<Series>> GetMetadata(SeriesInfo info, Cancellat
var filterLibrary = Plugin.Instance.Configuration.FilterOnLibraryTypes ? Ordering.GroupFilterType.Others : Ordering.GroupFilterType.Default;
var show = await ApiManager.GetShowInfoByPath(info.Path, filterLibrary);
if (show == null) {
// Look for the "season" directories to probe for the group information
var entries = FileSystem.GetDirectories(info.Path, false);
foreach (var entry in entries) {
show = await ApiManager.GetShowInfoByPath(entry.FullName, filterLibrary);
if (show != null)
break;
try {
// Look for the "season" directories to probe for the group information
var entries = FileSystem.GetDirectories(info.Path, false);
foreach (var entry in entries) {
show = await ApiManager.GetShowInfoByPath(entry.FullName, filterLibrary);
if (show != null)
break;
}
if (show == null) {
Logger.LogWarning("Unable to find show info for path {Path}", info.Path);
return result;
}
}
if (show == null) {
Logger.LogWarning("Unable to find show info for path {Path}", info.Path);
catch (DirectoryNotFoundException) {
return result;
}
}
Expand Down

0 comments on commit 6a1edfb

Please sign in to comment.