mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
Compute next refresh date automatically for all resources
This commit is contained in:
parent
5c6bcee763
commit
526ac1b8ab
@ -26,4 +26,18 @@ public interface IRefreshable
|
||||
/// The date of the next metadata refresh. Null if auto-refresh is disabled.
|
||||
/// </summary>
|
||||
public DateTime? NextMetadataRefresh { get; set; }
|
||||
|
||||
public static DateTime ComputeNextRefreshDate(DateOnly? airDate)
|
||||
{
|
||||
if (airDate is null)
|
||||
return DateTime.UtcNow.AddDays(1);
|
||||
|
||||
int days = airDate.Value.DayNumber - DateOnly.FromDateTime(DateTime.UtcNow).DayNumber;
|
||||
return days switch
|
||||
{
|
||||
<= 7 => DateTime.UtcNow.AddDays(1),
|
||||
<= 21 => DateTime.UtcNow.AddDays(5),
|
||||
_ => DateTime.UtcNow.AddMonths(2)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -53,6 +53,7 @@ public class CollectionRepository(DatabaseContext database, IThumbnailsManager t
|
||||
|
||||
if (string.IsNullOrEmpty(resource.Name))
|
||||
throw new ArgumentException("The collection's name must be set and not empty");
|
||||
resource.NextMetadataRefresh ??= DateTime.UtcNow.AddMonths(2);
|
||||
await thumbnails.DownloadImages(resource);
|
||||
}
|
||||
|
||||
|
@ -92,15 +92,7 @@ public class EpisodeRepository(
|
||||
.FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
// Refresh metadata every day if the item aired this week, refresh every two mounts otherwise
|
||||
if (
|
||||
resource.ReleaseDate is not DateOnly date
|
||||
|| (date.DayNumber - DateOnly.FromDateTime(DateTime.UtcNow).DayNumber) < 7
|
||||
)
|
||||
resource.NextMetadataRefresh = DateTime.UtcNow.AddDays(1);
|
||||
else
|
||||
resource.NextMetadataRefresh = DateTime.UtcNow.AddMonths(2);
|
||||
|
||||
resource.NextMetadataRefresh ??= IRefreshable.ComputeNextRefreshDate(resource.ReleaseDate);
|
||||
await thumbnails.DownloadImages(resource);
|
||||
}
|
||||
|
||||
|
@ -74,6 +74,7 @@ public class MovieRepository(
|
||||
resource.StudioId = (await studios.CreateIfNotExists(resource.Studio)).Id;
|
||||
resource.Studio = null;
|
||||
}
|
||||
resource.NextMetadataRefresh ??= IRefreshable.ComputeNextRefreshDate(resource.AirDate);
|
||||
await thumbnails.DownloadImages(resource);
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,6 @@ using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Kyoo.Abstractions.Controllers;
|
||||
using Kyoo.Abstractions.Models;
|
||||
using Kyoo.Abstractions.Models.Exceptions;
|
||||
using Kyoo.Abstractions.Models.Utils;
|
||||
using Kyoo.Postgresql;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@ -78,6 +77,7 @@ public class SeasonRepository(
|
||||
throw new ValidationException("Missing show id");
|
||||
// This is storred in db so it needs to be set before every create/edit (and before events)
|
||||
resource.ShowSlug = (await shows.Get(resource.ShowId)).Slug;
|
||||
resource.NextMetadataRefresh ??= IRefreshable.ComputeNextRefreshDate(resource.StartDate);
|
||||
await thumbnails.DownloadImages(resource);
|
||||
}
|
||||
}
|
||||
|
@ -74,6 +74,7 @@ public class ShowRepository(
|
||||
resource.StudioId = (await studios.CreateIfNotExists(resource.Studio)).Id;
|
||||
resource.Studio = null;
|
||||
}
|
||||
resource.NextMetadataRefresh ??= IRefreshable.ComputeNextRefreshDate(resource.StartAir);
|
||||
await thumbnails.DownloadImages(resource);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user