* starting database redesign * set season and episode numbers * use datetimes in db (utc); update movie metadata * get movie cards from new table * copy show/episode metadata * remove old movie metadata type * rename new movie metadata type * code cleanup * start to remove old television classes * remove old television tables from database * fix playout building * fix collection views * fix show/season views * clean up movie metadata table * fix scanner tests * add libraries ui * code cleanup * fix movie scanning/metadata * add library scan button to ui * delete library path from ui * temp disable movie scanning * remove orphan media items and prevent duplicate paths * attach artwork to metadata * fix split show/season display * fix television artwork * store year distinct from release date * fix collections ui * code cleanup * add library paths from ui * fix adding to collections from ui * fix schedule items loading * schedule editing works again * remove some todos * more cleanup * fix unit tests * fix episode sorting * fix deleting show library paths * remove unused class * fix playout list in ui * fix log viewer * start to use version/file instead of statistics * clean up old columns * fix playout display (time zone) * fix playback * fix channel guide time zone * cascade more deletes * fix compiler warnings * fix adding new seasons * use artwork for channel logo * clean cache folder on startup (move channel logos, delete everything else) * log database migration * update homepage docs for libraries * fix adding new channel with logo * fix episode numbers in epg
103 lines
3.6 KiB
C#
103 lines
3.6 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Text.RegularExpressions;
|
|
using ErsatzTV.Core.Domain;
|
|
using ErsatzTV.Core.Interfaces.Metadata;
|
|
using static LanguageExt.Prelude;
|
|
|
|
namespace ErsatzTV.Core.Metadata
|
|
{
|
|
public class FallbackMetadataProvider : IFallbackMetadataProvider
|
|
{
|
|
public ShowMetadata GetFallbackMetadataForShow(string showFolder)
|
|
{
|
|
string fileName = Path.GetFileName(showFolder);
|
|
var metadata = new ShowMetadata
|
|
{ MetadataKind = MetadataKind.Fallback, Title = fileName ?? showFolder };
|
|
return GetTelevisionShowMetadata(fileName, metadata);
|
|
}
|
|
|
|
public static Tuple<EpisodeMetadata, int> GetFallbackMetadata(Episode episode)
|
|
{
|
|
string path = episode.MediaVersions.Head().MediaFiles.Head().Path;
|
|
string fileName = Path.GetFileName(path);
|
|
var metadata = new EpisodeMetadata
|
|
{ MetadataKind = MetadataKind.Fallback, Title = fileName ?? path };
|
|
return fileName != null ? GetEpisodeMetadata(fileName, metadata) : Tuple(metadata, 0);
|
|
}
|
|
|
|
public static MovieMetadata GetFallbackMetadata(Movie movie)
|
|
{
|
|
string path = movie.MediaVersions.Head().MediaFiles.Head().Path;
|
|
string fileName = Path.GetFileName(path);
|
|
var metadata = new MovieMetadata { MetadataKind = MetadataKind.Fallback, Title = fileName ?? path };
|
|
|
|
return fileName != null ? GetMovieMetadata(fileName, metadata) : metadata;
|
|
}
|
|
|
|
private static Tuple<EpisodeMetadata, int> GetEpisodeMetadata(string fileName, EpisodeMetadata 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;
|
|
return Tuple(metadata, int.Parse(match.Groups[3].Value));
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
// ignored
|
|
}
|
|
|
|
return Tuple(metadata, 0);
|
|
}
|
|
|
|
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);
|
|
metadata.ReleaseDate = new DateTime(int.Parse(match.Groups[2].Value), 1, 1);
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
// ignored
|
|
}
|
|
|
|
return metadata;
|
|
}
|
|
|
|
private static ShowMetadata GetTelevisionShowMetadata(
|
|
string fileName,
|
|
ShowMetadata 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);
|
|
metadata.ReleaseDate = new DateTime(int.Parse(match.Groups[2].Value), 1, 1);
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
// ignored
|
|
}
|
|
|
|
return metadata;
|
|
}
|
|
}
|
|
}
|