Skip to content

Commit

Permalink
Hopefully fix the metadata provider this time
Browse files Browse the repository at this point in the history
  • Loading branch information
revam committed Sep 12, 2021
1 parent cf4cb69 commit 435ddba
Show file tree
Hide file tree
Showing 3 changed files with 360 additions and 167 deletions.
36 changes: 33 additions & 3 deletions Shokofin/API/ShokoAPIManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ public class ShokoAPIManager

private static readonly ConcurrentDictionary<string, string> SeriesPathToIdDictionary = new ConcurrentDictionary<string, string>();

private static ConcurrentDictionary<string, string> SeriesIdToGroupIdDictionary = new ConcurrentDictionary<string, string>();
private static readonly ConcurrentDictionary<string, string> SeriesIdToGroupIdDictionary = new ConcurrentDictionary<string, string>();

private static ConcurrentDictionary<string, string> EpisodePathToEpisodeIdDirectory = new ConcurrentDictionary<string, string>();
private static readonly ConcurrentDictionary<string, string> EpisodePathToEpisodeIdDirectory = new ConcurrentDictionary<string, string>();

private static ConcurrentDictionary<string, string> EpisodeIdToSeriesIdDictionary = new ConcurrentDictionary<string, string>();
private static readonly ConcurrentDictionary<string, string> EpisodeIdToSeriesIdDictionary = new ConcurrentDictionary<string, string>();

/// <summary>
/// Episodes marked as ignored is skipped when adding missing episode metadata.
Expand All @@ -42,6 +42,8 @@ public class ShokoAPIManager
/// </summary>
private static readonly ConcurrentDictionary<string, ConcurrentDictionary<string, string>> SeriesIdToEpisodeIdDictionery = new ConcurrentDictionary<string, ConcurrentDictionary<string, string>>();

public static readonly ConcurrentDictionary<string, HashSet<string>> LockedIdDictionary = new ConcurrentDictionary<string, HashSet<string>>();

public ShokoAPIManager(ILogger<ShokoAPIManager> logger, ILibraryManager libraryManager)
{
Logger = logger;
Expand Down Expand Up @@ -88,13 +90,36 @@ public string StripMediaFolder(string fullPath)
return fullPath.Substring(mediaFolder.Path.Length);
}

#endregion
#region Update locks

public bool TryLockActionForIdOFType(string type, string id, string action = "default")
{
var key = $"{type}:{id}";
if (!LockedIdDictionary.TryGetValue(key, out var hashSet)) {
LockedIdDictionary.TryAdd(key, new HashSet<string>());
if (!LockedIdDictionary.TryGetValue(key, out hashSet))
throw new Exception("Unable to set hash set");
}
return hashSet.Add(action);
}

public bool TryUnlockActionForIdOFType(string type, string id, string action = "default")
{
var key = $"{type}:{id}";
if (!LockedIdDictionary.TryGetValue(key, out var hashSet))
return false;
return hashSet.Remove(action);
}

#endregion
#region Clear

public void Clear()
{
Logger.LogDebug("Clearing data.");
DataCache.Dispose();
LockedIdDictionary.Clear();
MediaFolderList.Clear();
EpisodeIdToSeriesIdDictionary.Clear();
EpisodePathToEpisodeIdDirectory.Clear();
Expand Down Expand Up @@ -439,6 +464,11 @@ public bool TryGetSeriesIdForPath(string path, out string seriesId)
return SeriesPathToIdDictionary.TryGetValue(path, out seriesId);
}

public bool TryGetGroupIdForSeriesId(string seriesId, out string groupId)
{
return SeriesIdToGroupIdDictionary.TryGetValue(seriesId, out groupId);
}

private async Task<SeriesInfo> CreateSeriesInfo(Series series, string seriesId = null)
{
if (series == null)
Expand Down
Loading

0 comments on commit 435ddba

Please sign in to comment.