Skip to content

Commit

Permalink
Improve Messaging for Image and File Jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
da3dsoul committed Mar 12, 2024
1 parent 3db37d1 commit a863cb1
Show file tree
Hide file tree
Showing 22 changed files with 176 additions and 200 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ public void RehashFile(int videoLocalID)
scheduler.StartJobNow<HashFileJob>(
c =>
{
c.FileName = pl.FullServerPath;
c.FilePath = pl.FullServerPath;
c.ForceHash = true;
}
).GetAwaiter().GetResult();
Expand Down
6 changes: 3 additions & 3 deletions Shoko.Server/API/v2/Modules/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ public async Task<ActionResult> RehashVideoLocal(int id)
await scheduler.StartJobNow<HashFileJob>(
c =>
{
c.FileName = pl.FullServerPath;
c.FilePath = pl.FullServerPath;
c.ForceHash = true;
}
);
Expand Down Expand Up @@ -402,7 +402,7 @@ public async Task<ActionResult> RehashUnlinked()
await scheduler.StartJobNow<HashFileJob>(
c =>
{
c.FileName = pl.FullServerPath;
c.FilePath = pl.FullServerPath;
c.ForceHash = true;
}
);
Expand Down Expand Up @@ -438,7 +438,7 @@ public async Task<ActionResult> RehashManualLinks()
await scheduler.StartJobNow<HashFileJob>(
c =>
{
c.FileName = pl.FullServerPath;
c.FilePath = pl.FullServerPath;
c.ForceHash = true;
}
);
Expand Down
4 changes: 2 additions & 2 deletions Shoko.Server/API/v3/Controllers/FileController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -693,14 +693,14 @@ public async Task<ActionResult> RehashFile([FromRoute] int fileID, [FromQuery] b
if (priority)
await scheduler.StartJobNow<HashFileJob>(c =>
{
c.FileName = filePath;
c.FilePath = filePath;
c.ForceHash = true;
}
);
else
await scheduler.StartJob<HashFileJob>(c =>
{
c.FileName = filePath;
c.FilePath = filePath;
c.ForceHash = true;
}
);
Expand Down
22 changes: 11 additions & 11 deletions Shoko.Server/API/v3/Controllers/QueueController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
Expand Down Expand Up @@ -141,16 +140,17 @@ public async Task<ActionResult> Clear()
}).ToList());
}

return new ListResult<Queue.QueueItem>(total, (await _queueHandler.GetJobs(pageSize, offset, !showAll))
var result = (await _queueHandler.GetJobs(pageSize, offset, !showAll))
.Select(a => new Queue.QueueItem
{
Key = a.Key,
Type = a.JobType,
Title = a.Title,
Details = a.Details,
IsRunning = a.Running,
IsBlocked = a.Blocked,
StartTime = a.StartTime
}).ToList());
{
Key = a.Key,
Type = a.JobType,
Title = a.Title,
Details = a.Details,
IsRunning = a.Running,
IsBlocked = a.Blocked,
StartTime = a.StartTime
}).ToList();
return new ListResult<Queue.QueueItem>(total, result);
}
}
2 changes: 1 addition & 1 deletion Shoko.Server/API/v3/Controllers/SeriesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1431,7 +1431,7 @@ public async Task<ActionResult> RehashSeriesFiles([FromRoute] int seriesID)

await scheduler.StartJobNow<HashFileJob>(c =>
{
c.FileName = filePath;
c.FilePath = filePath;
c.ForceHash = true;
}
);
Expand Down
87 changes: 22 additions & 65 deletions Shoko.Server/Providers/MovieDB/MovieDBHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,8 @@ private async Task SaveMovieToDatabase(MovieDB_Movie_Result searchResult, bool s
// Only save movie info if source is not trakt, this presents adding tv shows as movies
// Needs better fix later on

if (!isTrakt)
{
RepoFactory.MovieDb_Movie.Save(movie);
}

if (!saveImages)
{
return;
}
if (!isTrakt) RepoFactory.MovieDb_Movie.Save(movie);
if (!saveImages) return;

var numFanartDownloaded = 0;
var numPostersDownloaded = 0;
Expand All @@ -63,10 +56,7 @@ private async Task SaveMovieToDatabase(MovieDB_Movie_Result searchResult, bool s
poster.Populate(img, movie.MovieId);
RepoFactory.MovieDB_Poster.Save(poster);

if (!string.IsNullOrEmpty(poster.GetFullImagePath()) && File.Exists(poster.GetFullImagePath()))
{
numPostersDownloaded++;
}
if (!string.IsNullOrEmpty(poster.GetFullImagePath()) && File.Exists(poster.GetFullImagePath())) numPostersDownloaded++;
}
else
{
Expand All @@ -75,30 +65,25 @@ private async Task SaveMovieToDatabase(MovieDB_Movie_Result searchResult, bool s
fanart.Populate(img, movie.MovieId);
RepoFactory.MovieDB_Fanart.Save(fanart);

if (!string.IsNullOrEmpty(fanart.GetFullImagePath()) && File.Exists(fanart.GetFullImagePath()))
{
numFanartDownloaded++;
}
if (!string.IsNullOrEmpty(fanart.GetFullImagePath()) && File.Exists(fanart.GetFullImagePath())) numFanartDownloaded++;
}
}

// download the posters
var settings = Utils.SettingsProvider.GetSettings();
if (settings.MovieDb.AutoPosters || isTrakt)
{
foreach (var poster in RepoFactory.MovieDB_Poster.GetByMovieID( movie.MovieId))
foreach (var poster in RepoFactory.MovieDB_Poster.GetByMovieID(movie.MovieId))
{
if (numPostersDownloaded < settings.MovieDb.AutoPostersAmount)
{
// download the image
if (string.IsNullOrEmpty(poster.GetFullImagePath()) || File.Exists(poster.GetFullImagePath()))
{
continue;
}
if (string.IsNullOrEmpty(poster.GetFullImagePath()) || File.Exists(poster.GetFullImagePath())) continue;

await scheduler.StartJob<DownloadTMDBImageJob>(
c =>
{
c.Anime = movie.MovieName;
c.ImageID = poster.MovieDB_PosterID;
c.ImageType = ImageEntityType.MovieDB_Poster;
}
Expand All @@ -108,12 +93,9 @@ await scheduler.StartJob<DownloadTMDBImageJob>(
else
{
//The MovieDB_AutoPostersAmount should prevent from saving image info without image
// we should clean those image that we didn't download because those dont exists in local repo
// we should clean those image that we didn't download because those don't exist in local repo
// first we check if file was downloaded
if (!File.Exists(poster.GetFullImagePath()))
{
RepoFactory.MovieDB_Poster.Delete(poster.MovieDB_PosterID);
}
if (!File.Exists(poster.GetFullImagePath())) RepoFactory.MovieDB_Poster.Delete(poster.MovieDB_PosterID);
}
}
}
Expand All @@ -126,14 +108,12 @@ await scheduler.StartJob<DownloadTMDBImageJob>(
if (numFanartDownloaded < settings.MovieDb.AutoFanartAmount)
{
// download the image
if (string.IsNullOrEmpty(fanart.GetFullImagePath()) || File.Exists(fanart.GetFullImagePath()))
{
continue;
}
if (string.IsNullOrEmpty(fanart.GetFullImagePath()) || File.Exists(fanart.GetFullImagePath())) continue;

await scheduler.StartJob<DownloadTMDBImageJob>(
c =>
{
c.Anime = movie.MovieName;
c.ImageID = fanart.MovieDB_FanartID;
c.ImageType = ImageEntityType.MovieDB_FanArt;
}
Expand All @@ -143,12 +123,9 @@ await scheduler.StartJob<DownloadTMDBImageJob>(
else
{
//The MovieDB_AutoFanartAmount should prevent from saving image info without image
// we should clean those image that we didn't download because those dont exists in local repo
// we should clean those image that we didn't download because those don't exist in local repo
// first we check if file was downloaded
if (!File.Exists(fanart.GetFullImagePath()))
{
RepoFactory.MovieDB_Fanart.Delete(fanart.MovieDB_FanartID);
}
if (!File.Exists(fanart.GetFullImagePath())) RepoFactory.MovieDB_Fanart.Delete(fanart.MovieDB_FanartID);
}
}
}
Expand Down Expand Up @@ -235,28 +212,16 @@ public async Task LinkAniDBMovieDB(int animeID, int movieDBID, bool fromWebCache
// database before the queued task runs later
await UpdateMovieInfo(movieDBID, false);
movie = RepoFactory.MovieDb_Movie.GetByOnlineID(movieDBID);
if (movie == null)
{
return;
}
if (movie == null) return;
}

// download and update series info and images
await UpdateMovieInfo(movieDBID, true);

var xref = RepoFactory.CrossRef_AniDB_Other.GetByAnimeIDAndType(animeID, CrossRefType.MovieDB) ??
new CrossRef_AniDB_Other();
var xref = RepoFactory.CrossRef_AniDB_Other.GetByAnimeIDAndType(animeID, CrossRefType.MovieDB) ?? new CrossRef_AniDB_Other();

xref.AnimeID = animeID;
if (fromWebCache)
{
xref.CrossRefSource = (int)CrossRefSource.WebCache;
}
else
{
xref.CrossRefSource = (int)CrossRefSource.User;
}

xref.CrossRefSource = fromWebCache ? (int)CrossRefSource.WebCache : (int)CrossRefSource.User;
xref.CrossRefType = (int)CrossRefType.MovieDB;
xref.CrossRefID = movieDBID.ToString();
RepoFactory.CrossRef_AniDB_Other.Save(xref);
Expand All @@ -269,10 +234,7 @@ public void RemoveLinkAniDBMovieDB(int animeID)
{
var xref =
RepoFactory.CrossRef_AniDB_Other.GetByAnimeIDAndType(animeID, CrossRefType.MovieDB);
if (xref == null)
{
return;
}
if (xref == null) return;

// Disable auto-matching when we remove an existing match for the series.
var series = RepoFactory.AnimeSeries.GetByAnimeID(animeID);
Expand All @@ -292,24 +254,19 @@ public async Task ScanForMatches()

foreach (var ser in allSeries)
{
if (ser.IsTMDBAutoMatchingDisabled)
continue;
if (ser.IsTMDBAutoMatchingDisabled) continue;

var anime = ser.GetAnime();
if (anime == null)
continue;
if (anime == null) continue;

// don't scan if it is associated on the TvDB
if (anime.GetCrossRefTvDB().Count > 0)
continue;
if (anime.GetCrossRefTvDB().Count > 0) continue;

// don't scan if it is associated on the MovieDB
if (anime.GetCrossRefMovieDB() != null)
continue;
if (anime.GetCrossRefMovieDB() != null) continue;

// don't scan if it is not a movie
if (!anime.GetSearchOnMovieDB())
continue;
if (!anime.GetSearchOnMovieDB()) continue;

_logger.LogTrace("Found anime movie without MovieDB association: {MainTitle}", anime.MainTitle);

Expand Down
3 changes: 2 additions & 1 deletion Shoko.Server/Scheduling/Jobs/AniDB/AddFileToMyListJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Shoko.Server.Scheduling.Jobs.Trakt;
using Shoko.Server.Server;
using Shoko.Server.Settings;
using Shoko.Server.Utilities;

namespace Shoko.Server.Scheduling.Jobs.AniDB;

Expand Down Expand Up @@ -45,7 +46,7 @@ public override void PostInit()
public override Dictionary<string, object> Details => new()
{
{
"File Path", _videoLocal.GetBestVideoLocalPlace()?.FullServerPath
"File Path", Utils.GetDistinctPath(_videoLocal.GetBestVideoLocalPlace()?.FullServerPath)
}
};

Expand Down
Loading

0 comments on commit a863cb1

Please sign in to comment.