Browse Source

store year distinct from release date

pull/31/head
Jason Dove 6 years ago
parent
commit
53e5f4b353
  1. 4
      ErsatzTV.Application/MediaCards/Mapper.cs
  2. 2
      ErsatzTV.Application/Movies/Mapper.cs
  3. 4
      ErsatzTV.Application/Television/Mapper.cs
  4. 1
      ErsatzTV.Core/Domain/Metadata/Metadata.cs
  5. 2
      ErsatzTV.Core/Metadata/FallbackMetadataProvider.cs
  6. 18
      ErsatzTV.Core/Metadata/LocalMetadataProvider.cs
  7. 8
      ErsatzTV.Infrastructure/Data/Repositories/TelevisionRepository.cs
  8. 1508
      ErsatzTV.Infrastructure/Migrations/20210227134707_Add_MetadataYear.Designer.cs
  9. 53
      ErsatzTV.Infrastructure/Migrations/20210227134707_Add_MetadataYear.cs
  10. 1508
      ErsatzTV.Infrastructure/Migrations/20210227134812_Reset_MetadataDateUpdated.Designer.cs
  11. 20
      ErsatzTV.Infrastructure/Migrations/20210227134812_Reset_MetadataDateUpdated.cs
  12. 12
      ErsatzTV.Infrastructure/Migrations/TvContextModelSnapshot.cs
  13. 1
      ErsatzTV.Infrastructure/Plex/PlexServerApiClient.cs

4
ErsatzTV.Application/MediaCards/Mapper.cs

@ -11,7 +11,7 @@ namespace ErsatzTV.Application.MediaCards @@ -11,7 +11,7 @@ namespace ErsatzTV.Application.MediaCards
new(
showMetadata.ShowId,
showMetadata.Title,
showMetadata.ReleaseDate?.Year.ToString(),
showMetadata.Year?.ToString(),
showMetadata.SortTitle,
GetPoster(showMetadata));
@ -42,7 +42,7 @@ namespace ErsatzTV.Application.MediaCards @@ -42,7 +42,7 @@ namespace ErsatzTV.Application.MediaCards
new(
movieMetadata.MovieId,
movieMetadata.Title,
movieMetadata.ReleaseDate?.Year.ToString(),
movieMetadata.Year?.ToString(),
movieMetadata.SortTitle,
GetPoster(movieMetadata));

2
ErsatzTV.Application/Movies/Mapper.cs

@ -11,7 +11,7 @@ namespace ErsatzTV.Application.Movies @@ -11,7 +11,7 @@ namespace ErsatzTV.Application.Movies
MovieMetadata metadata = Optional(movie.MovieMetadata).Flatten().Head();
return new MovieViewModel(
metadata.Title,
metadata.ReleaseDate?.Year.ToString(),
metadata.Year?.ToString(),
metadata.Plot,
Optional(metadata.Artwork.FirstOrDefault(a => a.ArtworkKind == ArtworkKind.Poster))
.Match(a => a.Path, string.Empty));

4
ErsatzTV.Application/Television/Mapper.cs

@ -10,7 +10,7 @@ namespace ErsatzTV.Application.Television @@ -10,7 +10,7 @@ namespace ErsatzTV.Application.Television
new(
show.Id,
show.ShowMetadata.HeadOrNone().Map(m => m.Title).IfNone(string.Empty),
show.ShowMetadata.HeadOrNone().Map(m => m.ReleaseDate?.Year.ToString()).IfNone(string.Empty),
show.ShowMetadata.HeadOrNone().Map(m => m.Year?.ToString()).IfNone(string.Empty),
show.ShowMetadata.HeadOrNone().Map(m => m.Plot).IfNone(string.Empty),
show.ShowMetadata.HeadOrNone().Map(GetPoster).IfNone(string.Empty));
@ -19,7 +19,7 @@ namespace ErsatzTV.Application.Television @@ -19,7 +19,7 @@ namespace ErsatzTV.Application.Television
season.Id,
season.ShowId,
season.Show.ShowMetadata.HeadOrNone().Map(m => m.Title).IfNone(string.Empty),
season.Show.ShowMetadata.HeadOrNone().Map(m => m.ReleaseDate?.Year.ToString()).IfNone(string.Empty),
season.Show.ShowMetadata.HeadOrNone().Map(m => m.Year?.ToString()).IfNone(string.Empty),
season.SeasonNumber == 0 ? "Specials" : $"Season {season.SeasonNumber}",
season.SeasonMetadata.HeadOrNone().Map(GetPoster).IfNone(string.Empty));

1
ErsatzTV.Core/Domain/Metadata/Metadata.cs

@ -10,6 +10,7 @@ namespace ErsatzTV.Core.Domain @@ -10,6 +10,7 @@ namespace ErsatzTV.Core.Domain
public string Title { get; set; }
public string OriginalTitle { get; set; }
public string SortTitle { get; set; }
public int? Year { get; set; }
public DateTime? ReleaseDate { get; set; }
public DateTime DateAdded { get; set; }
public DateTime DateUpdated { get; set; }

2
ErsatzTV.Core/Metadata/FallbackMetadataProvider.cs

@ -86,6 +86,7 @@ namespace ErsatzTV.Core.Metadata @@ -86,6 +86,7 @@ namespace ErsatzTV.Core.Metadata
if (match.Success)
{
metadata.Title = match.Groups[1].Value;
metadata.Year = int.Parse(match.Groups[2].Value);
metadata.ReleaseDate = new DateTime(int.Parse(match.Groups[2].Value), 1, 1);
}
}
@ -108,6 +109,7 @@ namespace ErsatzTV.Core.Metadata @@ -108,6 +109,7 @@ namespace ErsatzTV.Core.Metadata
if (match.Success)
{
metadata.Title = match.Groups[1].Value;
metadata.Year = int.Parse(match.Groups[2].Value);
metadata.ReleaseDate = new DateTime(int.Parse(match.Groups[2].Value), 1, 1);
}
}

18
ErsatzTV.Core/Metadata/LocalMetadataProvider.cs

@ -97,6 +97,7 @@ namespace ErsatzTV.Core.Metadata @@ -97,6 +97,7 @@ namespace ErsatzTV.Core.Metadata
existing.MetadataKind = metadata.MetadataKind;
existing.OriginalTitle = metadata.OriginalTitle;
existing.ReleaseDate = metadata.ReleaseDate;
existing.Year = metadata.Year;
existing.SortTitle = metadata.SortTitle ?? GetSortTitle(metadata.Title);
},
() =>
@ -122,6 +123,7 @@ namespace ErsatzTV.Core.Metadata @@ -122,6 +123,7 @@ namespace ErsatzTV.Core.Metadata
existing.MetadataKind = metadata.MetadataKind;
existing.OriginalTitle = metadata.OriginalTitle;
existing.ReleaseDate = metadata.ReleaseDate;
existing.Year = metadata.Year;
existing.SortTitle = metadata.SortTitle ?? GetSortTitle(metadata.Title);
},
() =>
@ -147,6 +149,7 @@ namespace ErsatzTV.Core.Metadata @@ -147,6 +149,7 @@ namespace ErsatzTV.Core.Metadata
existing.MetadataKind = metadata.MetadataKind;
existing.OriginalTitle = metadata.OriginalTitle;
existing.ReleaseDate = metadata.ReleaseDate;
existing.Year = metadata.Year;
existing.SortTitle = metadata.SortTitle ?? GetSortTitle(metadata.Title);
},
() =>
@ -218,7 +221,10 @@ namespace ErsatzTV.Core.Metadata @@ -218,7 +221,10 @@ namespace ErsatzTV.Core.Metadata
DateUpdated = File.GetLastWriteTimeUtc(nfoFileName),
Title = nfo.Title,
Plot = nfo.Plot,
ReleaseDate = new DateTime(nfo.Year, 1, 1)
Outline = nfo.Outline,
Tagline = nfo.Tagline,
Year = nfo.Year,
ReleaseDate = GetAired(nfo.Premiered) ?? new DateTime(nfo.Year, 1, 1)
},
None);
}
@ -270,6 +276,7 @@ namespace ErsatzTV.Core.Metadata @@ -270,6 +276,7 @@ namespace ErsatzTV.Core.Metadata
MetadataKind = MetadataKind.Sidecar,
DateUpdated = File.GetLastWriteTimeUtc(nfoFileName),
Title = nfo.Title,
Year = nfo.Year,
ReleaseDate = nfo.Premiered,
Plot = nfo.Plot,
Outline = nfo.Outline,
@ -355,6 +362,15 @@ namespace ErsatzTV.Core.Metadata @@ -355,6 +362,15 @@ namespace ErsatzTV.Core.Metadata
[XmlElement("plot")]
public string Plot { get; set; }
[XmlElement("outline")]
public string Outline { get; set; }
[XmlElement("tagline")]
public string Tagline { get; set; }
[XmlElement("premiered")]
public string Premiered { get; set; }
}
[XmlRoot("episodedetails")]

8
ErsatzTV.Infrastructure/Data/Repositories/TelevisionRepository.cs

@ -60,13 +60,13 @@ namespace ErsatzTV.Infrastructure.Data.Repositories @@ -60,13 +60,13 @@ namespace ErsatzTV.Infrastructure.Data.Repositories
public Task<int> GetShowCount() =>
_dbContext.ShowMetadata
.AsNoTracking()
.GroupBy(sm => new { sm.Title, sm.ReleaseDate })
.GroupBy(sm => new { sm.Title, sm.Year })
.CountAsync();
public Task<List<ShowMetadata>> GetPagedShows(int pageNumber, int pageSize) =>
_dbContext.ShowMetadata.FromSqlRaw(
@"SELECT * FROM ShowMetadata WHERE Id IN
(SELECT MIN(Id) FROM ShowMetadata GROUP BY Title, ReleaseDate, MetadataKind HAVING MetadataKind = MAX(MetadataKind))
(SELECT MIN(Id) FROM ShowMetadata GROUP BY Title, Year, MetadataKind HAVING MetadataKind = MAX(MetadataKind))
ORDER BY SortTitle
LIMIT {0} OFFSET {1}",
pageSize,
@ -104,7 +104,7 @@ namespace ErsatzTV.Infrastructure.Data.Repositories @@ -104,7 +104,7 @@ namespace ErsatzTV.Infrastructure.Data.Repositories
@"SELECT m1.ShowId
FROM ShowMetadata m1
LEFT OUTER JOIN ShowMetadata m2 ON m2.ShowId = @ShowId
WHERE m1.Title = m2.Title AND m1.ReleaseDate = m2.ReleaseDate",
WHERE m1.Title = m2.Title AND m1.Year = m2.Year",
new { ShowId = televisionShowId })
.Map(results => results.ToList());
@ -153,7 +153,7 @@ namespace ErsatzTV.Infrastructure.Data.Repositories @@ -153,7 +153,7 @@ namespace ErsatzTV.Infrastructure.Data.Repositories
public async Task<Option<Show>> GetShowByMetadata(int libraryPathId, ShowMetadata metadata)
{
Option<int> maybeId = await _dbContext.ShowMetadata
.Where(s => s.Title == metadata.Title && s.ReleaseDate == metadata.ReleaseDate)
.Where(s => s.Title == metadata.Title && s.Year == metadata.Year)
.Where(s => s.Show.LibraryPathId == libraryPathId)
.SingleOrDefaultAsync()
.Map(Optional)

1508
ErsatzTV.Infrastructure/Migrations/20210227134707_Add_MetadataYear.Designer.cs generated

File diff suppressed because it is too large Load Diff

53
ErsatzTV.Infrastructure/Migrations/20210227134707_Add_MetadataYear.cs

@ -0,0 +1,53 @@ @@ -0,0 +1,53 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace ErsatzTV.Infrastructure.Migrations
{
public partial class Add_MetadataYear : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
"Year",
"ShowMetadata",
"INTEGER",
nullable: true);
migrationBuilder.AddColumn<int>(
"Year",
"SeasonMetadata",
"INTEGER",
nullable: true);
migrationBuilder.AddColumn<int>(
"Year",
"MovieMetadata",
"INTEGER",
nullable: true);
migrationBuilder.AddColumn<int>(
"Year",
"EpisodeMetadata",
"INTEGER",
nullable: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
"Year",
"ShowMetadata");
migrationBuilder.DropColumn(
"Year",
"SeasonMetadata");
migrationBuilder.DropColumn(
"Year",
"MovieMetadata");
migrationBuilder.DropColumn(
"Year",
"EpisodeMetadata");
}
}
}

1508
ErsatzTV.Infrastructure/Migrations/20210227134812_Reset_MetadataDateUpdated.Designer.cs generated

File diff suppressed because it is too large Load Diff

20
ErsatzTV.Infrastructure/Migrations/20210227134812_Reset_MetadataDateUpdated.cs

@ -0,0 +1,20 @@ @@ -0,0 +1,20 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace ErsatzTV.Infrastructure.Migrations
{
public partial class Reset_MetadataDateUpdated : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql(@"UPDATE MovieMetadata SET DateUpdated = '0001-01-01 00:00:00'");
migrationBuilder.Sql(@"UPDATE ShowMetadata SET Year = substr(ReleaseDate, 1, 4)");
migrationBuilder.Sql(@"UPDATE SeasonMetadata SET DateUpdated = '0001-01-01 00:00:00'");
migrationBuilder.Sql(@"UPDATE EpisodeMetadata SET DateUpdated = '0001-01-01 00:00:00'");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
}
}
}

12
ErsatzTV.Infrastructure/Migrations/TvContextModelSnapshot.cs

@ -193,6 +193,9 @@ namespace ErsatzTV.Infrastructure.Migrations @@ -193,6 +193,9 @@ namespace ErsatzTV.Infrastructure.Migrations
b.Property<string>("Title")
.HasColumnType("TEXT");
b.Property<int?>("Year")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("EpisodeId");
@ -475,6 +478,9 @@ namespace ErsatzTV.Infrastructure.Migrations @@ -475,6 +478,9 @@ namespace ErsatzTV.Infrastructure.Migrations
b.Property<string>("Title")
.HasColumnType("TEXT");
b.Property<int?>("Year")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("MovieId");
@ -741,6 +747,9 @@ namespace ErsatzTV.Infrastructure.Migrations @@ -741,6 +747,9 @@ namespace ErsatzTV.Infrastructure.Migrations
b.Property<string>("Title")
.HasColumnType("TEXT");
b.Property<int?>("Year")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("SeasonId");
@ -789,6 +798,9 @@ namespace ErsatzTV.Infrastructure.Migrations @@ -789,6 +798,9 @@ namespace ErsatzTV.Infrastructure.Migrations
b.Property<string>("Title")
.HasColumnType("TEXT");
b.Property<int?>("Year")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("ShowId");

1
ErsatzTV.Infrastructure/Plex/PlexServerApiClient.cs

@ -128,6 +128,7 @@ namespace ErsatzTV.Infrastructure.Plex @@ -128,6 +128,7 @@ namespace ErsatzTV.Infrastructure.Plex
Title = response.Title,
Plot = response.Summary,
ReleaseDate = new DateTime(response.Year, 1, 1), // TODO: actual release date?
Year = response.Year,
Tagline = response.Tagline,
DateAdded = DateTime.UtcNow, // TODO: actual date added?
DateUpdated = lastWriteTime

Loading…
Cancel
Save