roadie/Roadie.Api.Library/Data/ReleasePartial.cs

167 lines
4.7 KiB
C#
Raw Normal View History

2018-11-04 20:33:37 +00:00
using Roadie.Library.Extensions;
2018-11-03 21:21:36 +00:00
using Roadie.Library.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Roadie.Library.Data
{
public partial class Release
{
2018-11-11 17:27:13 +00:00
public static string CacheRegionUrn(Guid Id)
{
return string.Format("urn:release:{0}", Id);
}
2018-11-11 17:27:13 +00:00
public static string CacheUrn(Guid Id)
{
2018-12-23 21:36:38 +00:00
return $"urn:release_by_id:{ Id }";
2018-11-11 17:27:13 +00:00
}
public string CacheKey
{
get
{
return Artist.CacheUrn(this.RoadieId);
}
}
2018-11-03 21:21:36 +00:00
public string CacheRegion
{
get
{
2018-11-11 17:27:13 +00:00
return Release.CacheRegionUrn(this.RoadieId);
2018-11-03 21:21:36 +00:00
}
}
2018-11-04 20:33:37 +00:00
2018-11-03 21:21:36 +00:00
public string Etag
{
get
{
using (var md5 = System.Security.Cryptography.MD5.Create())
{
return String.Concat(md5.ComputeHash(System.Text.Encoding.Default.GetBytes(string.Format("{0}{1}", this.RoadieId, this.LastUpdated))).Select(x => x.ToString("D2")));
}
}
}
2018-11-04 20:33:37 +00:00
public bool IsCastRecording
2018-11-03 21:21:36 +00:00
{
get
{
2018-11-04 20:33:37 +00:00
if (string.IsNullOrEmpty(this.Title))
{
return false;
}
return this.IsReleaseTypeOf("Original Broadway Cast") || this.IsReleaseTypeOf("Original Cast");
2018-11-03 21:21:36 +00:00
}
}
public bool IsSoundTrack
{
get
{
if (string.IsNullOrEmpty(this.Title))
{
return false;
}
foreach (var soundTrackTrigger in new List<string> { "soundtrack", " ost", "(ost)" })
{
if (this.IsReleaseTypeOf(soundTrackTrigger))
{
return true;
}
}
return false;
}
}
2018-11-04 20:33:37 +00:00
public bool IsValid
2018-11-03 21:21:36 +00:00
{
get
{
2018-11-04 20:33:37 +00:00
return !string.IsNullOrEmpty(this.Title) && this.ReleaseDate > DateTime.MinValue;
2018-11-03 21:21:36 +00:00
}
}
public bool IsReleaseTypeOf(string type, bool doCheckTitles = false)
{
if (string.IsNullOrEmpty(type))
{
return false;
}
try
{
if (doCheckTitles)
{
if (this.Artist != null && !string.IsNullOrEmpty(this.Artist.Name))
{
if (this.Artist.Name.IndexOf(type, 0, StringComparison.OrdinalIgnoreCase) > -1)
{
return true;
}
}
if (!string.IsNullOrEmpty(this.Title))
{
if (this.Title.IndexOf(type, 0, StringComparison.OrdinalIgnoreCase) > -1)
{
return true;
}
}
if (this.AlternateNames != null)
{
if (this.AlternateNames.IsValueInDelimitedList(type))
{
return true;
}
}
}
if (this.Tags != null)
{
if (this.Tags.IsValueInDelimitedList(type))
{
return true;
}
}
if (this.Genres != null)
{
if (this.Genres.Any(x => x.Genre.Name.ToLower().Equals(type)))
{
return true;
}
}
}
catch
{
}
return false;
}
public int? ReleaseYear
{
get
{
if(this.ReleaseDate.HasValue)
{
return this.ReleaseDate.Value.Year;
}
return null;
}
}
2018-11-03 21:21:36 +00:00
/// <summary>
/// Return this releases file folder for the given artist folder
/// </summary>
/// <param name="artistFolder"></param>
/// <returns></returns>
public string ReleaseFileFolder(string artistFolder)
{
2018-11-04 15:16:52 +00:00
return FolderPathHelper.ReleasePath(artistFolder, this.Title, this.ReleaseDate.Value);
2018-11-03 21:21:36 +00:00
}
2018-11-04 20:33:37 +00:00
public override string ToString()
{
return $"Id [{ this.Id }], Title [{ this.Title }], Release Date [{this.ReleaseYear}]";
2018-11-04 20:33:37 +00:00
}
2018-11-03 21:21:36 +00:00
}
2018-11-04 20:33:37 +00:00
}