Skip to content

Commit

Permalink
Add exception for ytdl-sub when deleting series
Browse files Browse the repository at this point in the history
  • Loading branch information
shemanaev committed Jan 28, 2024
1 parent de24b3d commit 417b3b5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
4 changes: 2 additions & 2 deletions MediaCleaner/MediaCleaner.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<RootNamespace>MediaCleaner</RootNamespace>
<AssemblyVersion>2.9.0.0</AssemblyVersion>
<FileVersion>2.9.0.0</FileVersion>
<AssemblyVersion>2.10.0.0</AssemblyVersion>
<FileVersion>2.10.0.0</FileVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
19 changes: 17 additions & 2 deletions MediaCleaner/MediaCleanupTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using MediaBrowser.Model.IO;
using MediaCleaner.Filtering;
using MediaCleaner.Configuration;
using System.IO;

namespace MediaCleaner
{
Expand Down Expand Up @@ -304,7 +305,7 @@ private void DeleteItem(BaseItem item)
_libraryManager.DeleteItem(eps, opts, true);
}
_libraryManager.DeleteItem(season, opts, true);
if (!season.Series?.GetEpisodes().Any() ?? false)
if (!(season.Series?.GetEpisodes().Any() ?? false) && !HasExtraFiles(season.Series))
{
_libraryManager.DeleteItem(season.Series, opts, true);
}
Expand All @@ -316,7 +317,7 @@ private void DeleteItem(BaseItem item)
{
_libraryManager.DeleteItem(episode.Season, opts, true);
}
if (!episode.Series?.GetEpisodes().Any() ?? false)
if (!(episode.Series?.GetEpisodes().Any() ?? false) && !HasExtraFiles(episode.Series))
{
_libraryManager.DeleteItem(episode.Series, opts, true);
}
Expand Down Expand Up @@ -383,5 +384,19 @@ await _activityManager.CreateAsync(new ActivityLog(title, "MediaCleaner", Guid.E
Overview = overview,
});
}

/// <summary>
/// Check if item has extra files and shouldn't be deleted.
/// </summary>
private bool HasExtraFiles(BaseItem? item)
{
if (item == null) return false;
if (!Directory.Exists(item.Path)) return false;

// https://github.com/jmbannon/ytdl-sub
var hasYtdlSubMeta = Directory.EnumerateFiles(item.Path, ".ytdl-sub-*-download-archive.json").Any();

return hasYtdlSubMeta;
}
}
}
4 changes: 2 additions & 2 deletions build.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
name: "Media Cleaner"
guid: "607fee77-97eb-41fe-bf22-26844d99ffb0"
version: "2.9.0.0"
version: "2.10.0.0"
targetAbi: "10.8.11.0"
framework: "net6.0"
overview: "Delete played media after specified time"
Expand All @@ -13,4 +13,4 @@ owner: "shemanaev"
artifacts:
- "MediaCleaner.dll"
changelog: >
Add new "keep while" option: Any user (latest playback)
Add exception for ytdl-sub when deleting series

0 comments on commit 417b3b5

Please sign in to comment.