* rework television media * refactor poster saving * television and movie views are working again * remove dead code * use paper styling for all cards * add show poster, plot to seasons page * remove missing shows; cleanup interfaces * fix split show display (same show in different folders/sources) * add placeholder "add to schedule" button * no more duplicate television shows, even with the same show split across sources * stop releasing CLI for now * use season number as season placeholder * add television shows to collections * add television seasons to collections * add television episodes to collections * add movies to collections * remove movies, shows, seasons, episodes from collections * fix page width and menus * fix buffer size defaults * fix chronological episode ordering * allow deleting media collections * don't get stuck building a playout with an empty collection * schedule editing and playouts work again * minor cleanup * remove dead code * fix bugs with viewing movies as they are loading * add scanner tests; support nested movie folders * update collections docs * rearrange order of schedule items * add show and season to schedule * delete schedules that use legacy collections, reset all posters * move cleanup to new migration * load fallback metadata when nfo fails; don't require metadata in ui * update readme and screenshots
63 lines
2.2 KiB
C#
63 lines
2.2 KiB
C#
using System;
|
|
using System.IO;
|
|
using ErsatzTV.Core.Domain;
|
|
|
|
namespace ErsatzTV.Application.MediaItems
|
|
{
|
|
internal static class Mapper
|
|
{
|
|
internal static MediaItemViewModel ProjectToViewModel(MediaItem mediaItem) =>
|
|
new(
|
|
mediaItem.Id,
|
|
mediaItem.MediaSourceId,
|
|
mediaItem.Path);
|
|
|
|
internal static MediaItemSearchResultViewModel ProjectToSearchViewModel(MediaItem mediaItem) =>
|
|
mediaItem switch
|
|
{
|
|
TelevisionEpisodeMediaItem e => ProjectToSearchViewModel(e),
|
|
MovieMediaItem m => ProjectToSearchViewModel(m),
|
|
_ => throw new ArgumentOutOfRangeException()
|
|
};
|
|
|
|
private static MediaItemSearchResultViewModel ProjectToSearchViewModel(TelevisionEpisodeMediaItem mediaItem) =>
|
|
new(
|
|
mediaItem.Id,
|
|
GetSourceName(mediaItem.Source),
|
|
"TV Show",
|
|
GetDisplayTitle(mediaItem),
|
|
GetDisplayDuration(mediaItem));
|
|
|
|
private static MediaItemSearchResultViewModel ProjectToSearchViewModel(MovieMediaItem mediaItem) =>
|
|
new(
|
|
mediaItem.Id,
|
|
GetSourceName(mediaItem.Source),
|
|
"Movie",
|
|
GetDisplayTitle(mediaItem),
|
|
GetDisplayDuration(mediaItem));
|
|
|
|
|
|
private static string GetDisplayTitle(MediaItem mediaItem) =>
|
|
mediaItem switch
|
|
{
|
|
TelevisionEpisodeMediaItem e => e.Metadata != null
|
|
? $"{e.Metadata.Title} - s{e.Metadata.Season:00}e{e.Metadata.Episode:00}"
|
|
: Path.GetFileName(e.Path),
|
|
MovieMediaItem m => m.Metadata?.Title ?? Path.GetFileName(m.Path),
|
|
_ => string.Empty
|
|
};
|
|
|
|
private static string GetDisplayDuration(MediaItem mediaItem) =>
|
|
string.Format(
|
|
mediaItem.Statistics.Duration.TotalHours >= 1 ? @"{0:h\:mm\:ss}" : @"{0:mm\:ss}",
|
|
mediaItem.Statistics.Duration);
|
|
|
|
private static string GetSourceName(MediaSource source) =>
|
|
source switch
|
|
{
|
|
LocalMediaSource lms => lms.Folder,
|
|
_ => source.Name
|
|
};
|
|
}
|
|
}
|