Skip to content

Commit 62cd559

Browse files
committed
fix: base season premiere date off first episode
1 parent e52f480 commit 62cd559

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

GelatoManager.cs

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ public async Task<int> SyncStreams(BaseItem item, Guid userId, CancellationToken
470470
isEpisode && video is Episode e
471471
? new Episode
472472
{
473-
Id = libraryManager.GetNewItemId(path, typeof(Episode)),
473+
//Id = libraryManager.GetNewItemId(path, typeof(Episode)),
474474
SeriesId = e.SeriesId,
475475
SeriesName = e.SeriesName,
476476
SeasonId = e.SeasonId,
@@ -479,7 +479,12 @@ public async Task<int> SyncStreams(BaseItem item, Guid userId, CancellationToken
479479
ParentIndexNumber = e.ParentIndexNumber,
480480
PremiereDate = e.PremiereDate,
481481
}
482-
: new Movie { Id = libraryManager.GetNewItemId(path, typeof(Movie)) };
482+
: new Movie
483+
{
484+
//Id = libraryManager.GetNewItemId(path, typeof(Movie))
485+
};
486+
target.Path = path;
487+
target.Id = libraryManager.GetNewItemId(target.Path, target.GetType());
483488
}
484489

485490
target.Name = video.Name;
@@ -713,10 +718,20 @@ is not Series series
713718
series.Name,
714719
seasonIndex
715720
);
721+
var epMeta = seasonGroup.First();
722+
epMeta.Type = StremioMediaType.Episode;
723+
if (IntoBaseItem(epMeta) is not Episode episode)
724+
{
725+
_log.LogWarning(
726+
"Could not load base item as episode for: {EpisodeName}, skipping",
727+
epMeta.GetName()
728+
);
729+
continue;
730+
}
716731

717732
season = new Season
718733
{
719-
Id = Guid.NewGuid(),
734+
Id = libraryManager.GetNewItemId(seasonPath, typeof(Season)),
720735
Name = $"Season {seasonIndex:D2}",
721736
IndexNumber = seasonIndex,
722737
SeriesId = series.Id,
@@ -726,7 +741,7 @@ is not Series series
726741
SeriesPresentationUniqueKey = seriesPresentationKey,
727742
DateModified = DateTime.UtcNow,
728743
DateLastSaved = DateTime.UtcNow,
729-
// important
744+
PremiereDate = episode.PremiereDate,
730745
ParentId = series.Id,
731746
};
732747

@@ -760,7 +775,7 @@ is not Series series
760775
.Where(x => !x.IsStream() && x.IndexNumber.HasValue)
761776
.Select(e => e.IndexNumber!.Value)
762777
.ToHashSet();
763-
778+
var episodeList = new List<Episode>();
764779
foreach (var epMeta in seasonGroup)
765780
{
766781
ct.ThrowIfCancellationRequested();
@@ -814,16 +829,16 @@ is not Series series
814829
episode.SeriesPresentationUniqueKey = season.SeriesPresentationUniqueKey;
815830
episode.PresentationUniqueKey = episode.GetPresentationUniqueKey();
816831

817-
season.AddChild(episode);
818-
832+
episodeList.Add(episode);
819833
episodesInserted++;
820834
_log.LogTrace("Created episode {EpisodeName}", epMeta.GetName());
821835
}
836+
repo.SaveItems(episodeList, CancellationToken.None);
822837
}
823838

824839
stopwatch.Stop();
825840

826-
_log.LogDebug(
841+
_log.LogInformation(
827842
"Sync completed for {SeriesName}: {SeasonsInserted} season(s) and {EpisodesInserted} episode(s) in {Dur}",
828843
series.Name,
829844
seasonsInserted,
@@ -938,21 +953,15 @@ private List<BaseItem> SaveItems(IEnumerable<BaseItem> items, Folder parent)
938953
switch (meta.Type)
939954
{
940955
case StremioMediaType.Series:
941-
item = new Series
942-
{
943-
Id = meta.Guid ?? libraryManager.GetNewItemId(id, typeof(Series)),
944-
};
956+
item = new Series { };
945957
break;
946958

947959
case StremioMediaType.Movie:
948-
item = new Movie
949-
{
950-
Id = meta.Guid ?? libraryManager.GetNewItemId(id, typeof(Movie)),
951-
};
960+
item = new Movie { };
952961
break;
953962

954963
case StremioMediaType.Episode:
955-
item = new Episode { Id = libraryManager.GetNewItemId(id, typeof(Episode)) };
964+
item = new Episode { };
956965
break;
957966
default:
958967
_log.LogWarning("unsupported type {type}", meta.Type);
@@ -1016,6 +1025,8 @@ private List<BaseItem> SaveItems(IEnumerable<BaseItem> items, Folder parent)
10161025
new() { Type = ImageType.Primary, Path = primary },
10171026
}.ToArray();
10181027
}
1028+
1029+
item.Id = libraryManager.GetNewItemId(item.Path, item.GetType());
10191030
item.PresentationUniqueKey = item.CreatePresentationUniqueKey();
10201031
return item;
10211032
}

0 commit comments

Comments
 (0)