roadie/Roadie.Api.Library/Models/Track.cs

127 lines
3.3 KiB
C#
Raw Permalink Normal View History

2020-06-21 20:39:14 +00:00
using Roadie.Library.Models.Releases;
2018-11-17 02:14:32 +00:00
using Roadie.Library.Models.Statistics;
2018-11-14 03:19:28 +00:00
using Roadie.Library.Models.Users;
2019-01-08 22:40:26 +00:00
using Roadie.Library.Utility;
2018-11-02 21:04:49 +00:00
using System;
2019-01-05 22:40:33 +00:00
using System.Collections.Generic;
2018-11-02 21:04:49 +00:00
using System.ComponentModel.DataAnnotations;
2019-01-05 22:40:33 +00:00
using System.Runtime.Serialization;
2020-06-21 20:39:14 +00:00
using System.Text.Json.Serialization;
2018-11-02 21:04:49 +00:00
2018-11-06 02:41:51 +00:00
namespace Roadie.Library.Models
2018-11-02 21:04:49 +00:00
{
[Serializable]
public class Track : EntityModelBase
{
public const string DefaultIncludes = "comments,stats,credits";
2018-11-17 02:14:32 +00:00
2019-07-03 16:21:29 +00:00
private IEnumerable<string> _partTitles;
2020-06-21 20:39:14 +00:00
[MaxLength(50)]
public string AmgId { get; set; }
2018-11-02 21:04:49 +00:00
2019-01-05 22:40:33 +00:00
public ArtistList Artist { get; set; }
2020-06-21 20:39:14 +00:00
2018-11-17 02:14:32 +00:00
public Image ArtistThumbnail { get; set; }
2020-06-21 20:39:14 +00:00
2019-07-03 16:21:29 +00:00
public IEnumerable<Comment> Comments { get; set; }
2020-06-21 20:39:14 +00:00
public IEnumerable<CreditList> Credits { get; set; }
2018-11-02 21:04:49 +00:00
public int Duration { get; set; }
2019-07-03 16:21:29 +00:00
2019-01-08 22:40:26 +00:00
public string DurationTime
{
get
{
2020-06-21 20:39:14 +00:00
if (Duration < 1)
{
return "--:--";
}
2019-07-03 16:21:29 +00:00
return new TimeInfo(Duration).ToFullFormattedString();
2019-01-08 22:40:26 +00:00
}
}
2018-11-02 21:04:49 +00:00
2019-07-03 16:21:29 +00:00
public long FileSize { get; set; }
2018-11-02 21:04:49 +00:00
2020-06-21 20:39:14 +00:00
[MaxLength(32)]
public string Hash { get; set; }
[MaxLength(15)]
public string ISRC { get; set; }
2018-11-02 21:04:49 +00:00
2020-06-21 20:39:14 +00:00
[MaxLength(50)]
public string LastFMId { get; set; }
2018-11-02 21:04:49 +00:00
public DateTime? LastPlayed { get; set; }
2019-07-03 16:21:29 +00:00
public Image MediumThumbnail { get; set; }
2020-06-21 20:39:14 +00:00
2019-07-03 16:21:29 +00:00
[MaxLength(100)] public string MusicBrainzId { get; set; }
2018-11-02 21:04:49 +00:00
2019-05-11 03:07:45 +00:00
// When populated a "data:image" base64 byte array of an image to use as new Thumbnail
public string NewThumbnailData { get; set; }
2018-11-02 21:04:49 +00:00
[MaxLength(65535)]
2019-01-05 22:40:33 +00:00
[JsonIgnore]
[IgnoreDataMember]
2018-11-02 21:04:49 +00:00
public string PartTitles { get; set; }
2019-01-05 22:40:33 +00:00
public IEnumerable<string> PartTitlesList
{
get
{
2019-07-03 16:21:29 +00:00
if (_partTitles == null)
2019-01-05 22:40:33 +00:00
{
2020-06-21 20:39:14 +00:00
if (string.IsNullOrEmpty(PartTitles))
{
return null;
}
2019-07-03 16:21:29 +00:00
return PartTitles.Replace("|", "\n").Split("\n");
2019-01-05 22:40:33 +00:00
}
2019-07-03 16:21:29 +00:00
return _partTitles;
2019-01-05 22:40:33 +00:00
}
2019-07-03 16:21:29 +00:00
set => _partTitles = value;
2019-01-05 22:40:33 +00:00
}
2018-11-02 21:04:49 +00:00
public int PlayedCount { get; set; }
2020-06-21 20:39:14 +00:00
2018-11-02 21:04:49 +00:00
public short Rating { get; set; }
2020-06-21 20:39:14 +00:00
2019-01-05 22:40:33 +00:00
public ReleaseList Release { get; set; }
2018-11-02 21:04:49 +00:00
public string ReleaseMediaId { get; set; }
2018-11-17 02:14:32 +00:00
public Image ReleaseThumbnail { get; set; }
2019-07-03 16:21:29 +00:00
[MaxLength(100)] public string SpotifyId { get; set; }
2018-11-02 21:04:49 +00:00
2018-11-17 02:14:32 +00:00
public TrackStatistics Statistics { get; set; }
2018-11-06 02:41:51 +00:00
public Image Thumbnail { get; set; }
2020-06-21 20:39:14 +00:00
[MaxLength(250)]
[Required]
public string Title { get; set; }
2018-11-02 21:04:49 +00:00
2018-11-17 02:14:32 +00:00
/// <summary>
2019-07-03 16:21:29 +00:00
/// Track Artist, not release artist. If this is present then the track has an artist different than the release.
2018-11-17 02:14:32 +00:00
/// </summary>
2019-01-05 22:40:33 +00:00
public ArtistList TrackArtist { get; set; }
2018-11-17 02:14:32 +00:00
public Image TrackArtistThumbnail { get; set; }
2020-06-21 20:39:14 +00:00
2019-07-03 16:21:29 +00:00
public DataToken TrackArtistToken { get; set; }
2020-06-21 20:39:14 +00:00
2019-07-03 16:21:29 +00:00
[Required] public short TrackNumber { get; set; }
2018-11-17 02:14:32 +00:00
2019-01-05 22:40:33 +00:00
public string TrackPlayUrl { get; set; }
2020-06-21 20:39:14 +00:00
2019-07-03 16:21:29 +00:00
public UserTrack UserRating { get; set; }
2019-08-04 16:30:19 +00:00
2020-06-21 20:39:14 +00:00
public override string ToString() => $"Id [{ Id }], Title [{ Title }]";
2018-11-02 21:04:49 +00:00
}
}