Skip to content

Commit

Permalink
refactor: add tmdb episode data and constructor for episode info
Browse files Browse the repository at this point in the history
  • Loading branch information
revam committed Nov 15, 2024
1 parent cdf3d39 commit dc584c5
Show file tree
Hide file tree
Showing 9 changed files with 323 additions and 73 deletions.
41 changes: 36 additions & 5 deletions Shokofin/API/Info/EpisodeInfo.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
using Shokofin.API.Models;
using Shokofin.API.Models.AniDB;
using Shokofin.API.Models.TMDB;
using Shokofin.Configuration;
using Shokofin.Utils;

Expand Down Expand Up @@ -33,7 +33,7 @@ public class EpisodeInfo

public MediaBrowser.Model.Entities.ExtraType? ExtraType;

public TimeSpan Runtime;
public TimeSpan? Runtime;

public DateTime? AiredAt;

Expand All @@ -51,8 +51,13 @@ public class EpisodeInfo

public List<CrossReference.EpisodeCrossReferenceIDs> CrossReferences;

public EpisodeInfo(Episode episode)
public EpisodeInfo(Episode episode, IReadOnlyList<TmdbEpisode> tmdbEpisodes)
{
var tmdbEpisode = tmdbEpisodes
.OrderBy(e => e.ShowId)
.ThenBy(e => e.SeasonNumber)
.ThenBy(e => e.EpisodeNumber)
.FirstOrDefault();
Id = episode.IDs.Shoko.ToString();
SeriesId = episode.IDs.ParentSeries.ToString();
AnidbId = episode.AniDB.Id.ToString();
Expand All @@ -65,7 +70,10 @@ public EpisodeInfo(Episode episode)
Runtime = episode.AniDB.Duration;
AiredAt = episode.AniDB.AirDate;
DefaultTitle = episode.Name;
Titles = episode.AniDB.Titles;
Titles = [
..episode.AniDB.Titles,
..(tmdbEpisode is not null ? tmdbEpisode.Titles : []),
];
DefaultOverview = episode.Description;
Overviews = [
new TextOverview() {
Expand All @@ -75,9 +83,32 @@ public EpisodeInfo(Episode episode)
Source = "AniDB",
Value = episode.AniDB.Description,
},
..(tmdbEpisode is not null ? tmdbEpisode.Overviews : []),
];
FileCount = episode.Size;
OfficialRating = episode.AniDB.Rating;
CrossReferences = episode.CrossReferences;
}

public EpisodeInfo(TmdbEpisode episode)
{
Id = episode.Id.ToString();
SeriesId = episode.ShowId.ToString();
TmdbId = episode.Id.ToString();
StructureType = SeriesStructureType.TMDB_SeriesAndMovies;
Type = episode.SeasonNumber is 0 ? EpisodeType.Special : EpisodeType.Normal;
SeasonNumber = episode.SeasonNumber;
EpisodeNumber = episode.EpisodeNumber;
Runtime = episode.Runtime;
AiredAt = episode.AiredAt?.ToDateTime(TimeOnly.ParseExact("00:00:00.000000", "en-US", CultureInfo.InvariantCulture), DateTimeKind.Utc);
DefaultTitle = episode.Title;
Titles = episode.Titles;
DefaultOverview = episode.Overview;
Overviews = episode.Overviews;
FileCount = episode.FileCrossReferences.Sum(a => a.Episodes.Count);
OfficialRating = episode.UserRating;
CrossReferences = episode.FileCrossReferences
.SelectMany(a => a.Episodes)
.ToList();
}
}
8 changes: 8 additions & 0 deletions Shokofin/API/Models/CrossReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ public class EpisodeCrossReferenceIDs
/// </summary>
public int AniDB { get; set; }

/// <summary>
/// The Movie DataBase (TMDB) Cross-Reference IDs.
/// </summary>
public Episode.TmdbEpisodeIDs TMDB { get; set; } = new();

/// <summary>
/// The Release Group ID.
/// </summary>
public int? ReleaseGroup { get; set; }

/// <summary>
Expand Down
70 changes: 12 additions & 58 deletions Shokofin/API/Models/Episode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

namespace Shokofin.API.Models;

public class Episode
{
public class Episode {
/// <summary>
/// All identifiers related to the episode entry, e.g. the Shoko, AniDB,
/// TMDB, etc.
Expand Down Expand Up @@ -51,68 +50,23 @@ public class Episode
/// </summary>
public List<CrossReference.EpisodeCrossReferenceIDs> CrossReferences { get; set; } = [];

public class EpisodeIDs : IDs
{
public class EpisodeIDs : IDs {
public int ParentSeries { get; set; }
}
}


public enum EpisodeType
{
/// <summary>
/// A catch-all type for future extensions when a provider can't use a current episode type, but knows what the future type should be.
/// </summary>
Other = 2,

/// <summary>
/// The episode type is unknown.
/// </summary>
Unknown = Other,

/// <summary>
/// A normal episode.
/// </summary>
Normal = 1,

/// <summary>
/// A special episode.
/// </summary>
Special = 3,

/// <summary>
/// A trailer.
/// </summary>
Trailer = 4,
public int AniDB { get; set; }

/// <summary>
/// Either an opening-song, or an ending-song.
/// </summary>
ThemeSong = 5,
public List<int> TvDB { get; set; } = [];

/// <summary>
/// Intro, and/or opening-song.
/// </summary>
OpeningSong = 6,
public List<string> IMDB { get; set; } = [];

/// <summary>
/// Outro, end-roll, credits, and/or ending-song.
/// </summary>
EndingSong = 7,
public TmdbEpisodeIDs TMDB { get; init; } = new();
}

/// <summary>
/// AniDB parody type. Where else would this be useful?
/// </summary>
Parody = 8,
public class TmdbEpisodeIDs {
public List<int> Episode { get; init; } = [];

/// <summary>
/// A interview tied to the series.
/// </summary>
Interview = 9,
public List<int> Movie { get; init; } = [];

/// <summary>
/// A DVD or BD extra, e.g. BD-menu or deleted scenes.
/// </summary>
Extra = 10,
public List<int> Show { get; init; } = [];
}
}

62 changes: 62 additions & 0 deletions Shokofin/API/Models/EpisodeType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System.Text.Json.Serialization;

namespace Shokofin.API.Models;

[JsonConverter(typeof(JsonStringEnumConverter))]
public enum EpisodeType
{
/// <summary>
/// A catch-all type for future extensions when a provider can't use a current episode type, but knows what the future type should be.
/// </summary>
Other = 2,

/// <summary>
/// The episode type is unknown.
/// </summary>
Unknown = Other,

/// <summary>
/// A normal episode.
/// </summary>
Normal = 1,

/// <summary>
/// A special episode.
/// </summary>
Special = 3,

/// <summary>
/// A trailer.
/// </summary>
Trailer = 4,

/// <summary>
/// Either an opening-song, or an ending-song.
/// </summary>
ThemeSong = 5,

/// <summary>
/// Intro, and/or opening-song.
/// </summary>
OpeningSong = 6,

/// <summary>
/// Outro, end-roll, credits, and/or ending-song.
/// </summary>
EndingSong = 7,

/// <summary>
/// AniDB parody type. Where else would this be useful?
/// </summary>
Parody = 8,

/// <summary>
/// A interview tied to the series.
/// </summary>
Interview = 9,

/// <summary>
/// A DVD or BD extra, e.g. BD-menu or deleted scenes.
/// </summary>
Extra = 10,
}
13 changes: 13 additions & 0 deletions Shokofin/API/Models/TMDB/AlternateOrderingType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

namespace Shokofin.API.Models.TMDB;

public enum AlternateOrderingType {
Unknown = 0,
OriginalAirDate = 1,
Absolute = 2,
DVD = 3,
Digital = 4,
StoryArc = 5,
Production = 6,
TV = 7,
}
Loading

0 comments on commit dc584c5

Please sign in to comment.