add songs libraries (#490)

* first pass at adding song libraries

* start handling optional video

* fix song playback

* fix song transitions

* add songs page to UI
This commit is contained in:
Jason Dove
2021-11-22 22:26:06 -06:00
committed by GitHub
parent 096f2d42e8
commit 852728c816
63 changed files with 13235 additions and 187 deletions
@@ -62,6 +62,7 @@ namespace ErsatzTV.Infrastructure.Search
public const string MusicVideoType = "music_video";
public const string EpisodeType = "episode";
public const string OtherVideoType = "other_video";
public const string SongType = "song";
private readonly List<CultureInfo> _cultureInfos;
private readonly ILogger<SearchIndex> _logger;
@@ -126,6 +127,9 @@ namespace ErsatzTV.Infrastructure.Search
case OtherVideo otherVideo:
await UpdateOtherVideo(searchRepository, otherVideo);
break;
case Song song:
await UpdateSong(searchRepository, song);
break;
}
}
@@ -226,6 +230,9 @@ namespace ErsatzTV.Infrastructure.Search
case OtherVideo otherVideo:
await UpdateOtherVideo(searchRepository, otherVideo);
break;
case Song song:
await UpdateSong(searchRepository, song);
break;
}
}
}
@@ -815,6 +822,49 @@ namespace ErsatzTV.Infrastructure.Search
}
}
}
private async Task UpdateSong(ISearchRepository searchRepository, Song song)
{
Option<SongMetadata> maybeMetadata = song.SongMetadata.HeadOrNone();
if (maybeMetadata.IsSome)
{
SongMetadata metadata = maybeMetadata.ValueUnsafe();
try
{
var doc = new Document
{
new StringField(IdField, song.Id.ToString(), Field.Store.YES),
new StringField(TypeField, SongType, Field.Store.YES),
new TextField(TitleField, metadata.Title, Field.Store.NO),
new StringField(SortTitleField, metadata.SortTitle.ToLowerInvariant(), Field.Store.NO),
new TextField(LibraryNameField, song.LibraryPath.Library.Name, Field.Store.NO),
new StringField(LibraryIdField, song.LibraryPath.Library.Id.ToString(), Field.Store.NO),
new StringField(TitleAndYearField, GetTitleAndYear(metadata), Field.Store.NO),
new StringField(JumpLetterField, GetJumpLetter(metadata), Field.Store.YES),
};
await AddLanguages(searchRepository, doc, song.MediaVersions);
foreach (MediaVersion version in song.MediaVersions.HeadOrNone())
{
doc.Add(new Int32Field(MinutesField, (int)Math.Ceiling(version.Duration.TotalMinutes), Field.Store.NO));
}
foreach (Tag tag in metadata.Tags)
{
doc.Add(new TextField(TagField, tag.Name, Field.Store.NO));
}
_writer.UpdateDocument(new Term(IdField, song.Id.ToString()), doc);
}
catch (Exception ex)
{
metadata.Song = null;
_logger.LogWarning(ex, "Error indexing song with metadata {@Metadata}", metadata);
}
}
}
private SearchItem ProjectToSearchItem(Document doc) => new(
doc.Get(TypeField),