Skip to content

Commit

Permalink
Support filtering by file size in GetByFilename
Browse files Browse the repository at this point in the history
  • Loading branch information
LordFlashmeow committed Jun 12, 2024
1 parent 56ffc8b commit ef7c281
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Shoko.Server/Plex/TVShow/SVR_Episode.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.IO;
using System.IO;
using Shoko.Models.Plex.TVShow;
using Shoko.Server.Models;
using Shoko.Server.Repositories;
Expand All @@ -15,7 +15,7 @@ public SVR_Episode(PlexHelper helper)
}

public SVR_AnimeEpisode AnimeEpisode =>
RepoFactory.AnimeEpisode.GetByFilename(Path.GetFileName(Media[0].Part[0].File));
RepoFactory.AnimeEpisode.GetByFilename(Path.GetFileName(Media[0].Part[0].File), Media[0].Part[0].Size);

public void Unscrobble()
{
Expand Down
6 changes: 4 additions & 2 deletions Shoko.Server/Repositories/Cached/AnimeEpisodeRepository.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -56,8 +56,9 @@ public SVR_AnimeEpisode GetByAniDBEpisodeID(int epid)
/// Get the AnimeEpisode
/// </summary>
/// <param name="name">The filename of the anime to search for.</param>
/// <param name="size">The size of the file in bytes</param>
/// <returns>the AnimeEpisode given the file information</returns>
public SVR_AnimeEpisode GetByFilename(string name)
public SVR_AnimeEpisode GetByFilename(string name, long? size = null)
{
if (string.IsNullOrEmpty(name))
{
Expand All @@ -68,6 +69,7 @@ public SVR_AnimeEpisode GetByFilename(string name)
.Where(v => name.Equals(v?.FilePath?.Split(Path.DirectorySeparatorChar).LastOrDefault(),
StringComparison.InvariantCultureIgnoreCase))
.Select(a => RepoFactory.VideoLocal.GetByID(a.VideoLocalID)).Where(a => a != null)
.Where(a => size == null || a.FileSize == size)
.SelectMany(a => GetByHash(a.Hash)).ToArray();
var ep = eps.FirstOrDefault(a => a.AniDB_Episode.EpisodeType == (int)EpisodeType.Episode);
return ep ?? eps.FirstOrDefault();
Expand Down

0 comments on commit ef7c281

Please sign in to comment.