* 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
120 lines
3.7 KiB
C#
120 lines
3.7 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Text.RegularExpressions;
|
|
using ErsatzTV.Core.Domain;
|
|
using ErsatzTV.Core.Interfaces.Metadata;
|
|
|
|
namespace ErsatzTV.Core.Metadata
|
|
{
|
|
public class FallbackMetadataProvider : IFallbackMetadataProvider
|
|
{
|
|
public TelevisionShowMetadata GetFallbackMetadataForShow(string showFolder)
|
|
{
|
|
string fileName = Path.GetFileName(showFolder);
|
|
var metadata = new TelevisionShowMetadata
|
|
{ Source = MetadataSource.Fallback, Title = fileName ?? showFolder };
|
|
return GetTelevisionShowMetadata(fileName, metadata);
|
|
}
|
|
|
|
public static TelevisionEpisodeMetadata GetFallbackMetadata(TelevisionEpisodeMediaItem mediaItem)
|
|
{
|
|
string fileName = Path.GetFileName(mediaItem.Path);
|
|
var metadata = new TelevisionEpisodeMetadata
|
|
{ Source = MetadataSource.Fallback, Title = fileName ?? mediaItem.Path };
|
|
|
|
if (fileName != null)
|
|
{
|
|
if (!(mediaItem.Source is LocalMediaSource))
|
|
{
|
|
return metadata;
|
|
}
|
|
|
|
return GetEpisodeMetadata(fileName, metadata);
|
|
}
|
|
|
|
return metadata;
|
|
}
|
|
|
|
public static MovieMetadata GetFallbackMetadata(MovieMediaItem mediaItem)
|
|
{
|
|
string fileName = Path.GetFileName(mediaItem.Path);
|
|
var metadata = new MovieMetadata { Source = MetadataSource.Fallback, Title = fileName ?? mediaItem.Path };
|
|
|
|
if (fileName != null)
|
|
{
|
|
if (!(mediaItem.Source is LocalMediaSource))
|
|
{
|
|
return metadata;
|
|
}
|
|
|
|
return GetMovieMetadata(fileName, metadata);
|
|
}
|
|
|
|
return metadata;
|
|
}
|
|
|
|
private static TelevisionEpisodeMetadata GetEpisodeMetadata(string fileName, TelevisionEpisodeMetadata metadata)
|
|
{
|
|
try
|
|
{
|
|
const string PATTERN = @"^(.*?)[.\s-]+[sS](\d+)[eE](\d+).*\.\w+$";
|
|
Match match = Regex.Match(fileName, PATTERN);
|
|
if (match.Success)
|
|
{
|
|
metadata.Title = match.Groups[1].Value;
|
|
metadata.Season = int.Parse(match.Groups[2].Value);
|
|
metadata.Episode = int.Parse(match.Groups[3].Value);
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
// ignored
|
|
}
|
|
|
|
return metadata;
|
|
}
|
|
|
|
private static MovieMetadata GetMovieMetadata(string fileName, MovieMetadata metadata)
|
|
{
|
|
try
|
|
{
|
|
const string PATTERN = @"^(.*?)[.\(](\d{4})[.\)].*\.\w+$";
|
|
Match match = Regex.Match(fileName, PATTERN);
|
|
if (match.Success)
|
|
{
|
|
metadata.Title = match.Groups[1].Value;
|
|
metadata.Year = int.Parse(match.Groups[2].Value);
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
// ignored
|
|
}
|
|
|
|
return metadata;
|
|
}
|
|
|
|
private static TelevisionShowMetadata GetTelevisionShowMetadata(
|
|
string fileName,
|
|
TelevisionShowMetadata metadata)
|
|
{
|
|
try
|
|
{
|
|
const string PATTERN = @"^(.*?)[\s.]+?[.\(](\d{4})[.\)].*$";
|
|
Match match = Regex.Match(fileName, PATTERN);
|
|
if (match.Success)
|
|
{
|
|
metadata.Title = match.Groups[1].Value;
|
|
metadata.Year = int.Parse(match.Groups[2].Value);
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
// ignored
|
|
}
|
|
|
|
return metadata;
|
|
}
|
|
}
|
|
}
|