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

125 lines
4.4 KiB
C#
Raw Normal View History

2018-11-14 03:19:28 +00:00
using Newtonsoft.Json;
2018-12-07 21:02:38 +00:00
using Roadie.Library.Models.Releases;
2018-11-14 03:19:28 +00:00
using Roadie.Library.Models.Users;
using Roadie.Library.Utility;
2018-11-14 03:19:28 +00:00
using System;
2018-11-06 03:26:46 +00:00
using System.Collections.Generic;
2018-11-14 03:19:28 +00:00
using System.ComponentModel.DataAnnotations;
2019-03-06 01:18:21 +00:00
using System.Diagnostics;
2018-11-14 03:19:28 +00:00
using System.Runtime.Serialization;
2018-11-06 03:26:46 +00:00
using System.Text;
namespace Roadie.Library.Models
{
[Serializable]
2019-03-06 01:18:21 +00:00
[DebuggerDisplay("Trackid [{ Track.Value }], Track Name [{ Track.Text }}")]
2018-11-06 03:26:46 +00:00
public class TrackList : EntityInfoModelBase
{
2018-11-15 00:16:25 +00:00
public int? MediaNumber { get; set; }
2018-11-06 03:26:46 +00:00
public int? TrackNumber { get; set; }
2018-11-15 00:16:25 +00:00
public DataToken Track { get; set; }
2018-12-07 21:02:38 +00:00
public ReleaseList Release { get; set; }
public ArtistList Artist { get; set; }
2018-12-07 04:45:09 +00:00
public ArtistList TrackArtist { get; set; }
2018-11-06 03:26:46 +00:00
public string Title { get; set; }
public int? Duration { get; set; }
public string DurationTime
{
get
{
return this.Duration.HasValue ? new TimeInfo((decimal)this.Duration.Value).ToFullFormattedString() : "--:--";
2018-11-06 03:26:46 +00:00
}
}
2018-11-06 03:43:17 +00:00
public string DurationTimeShort
{
get
{
return this.Duration.HasValue ? new TimeInfo((decimal)this.Duration.Value).ToShortFormattedString() : "--:--";
2018-11-06 03:43:17 +00:00
}
}
2018-12-08 19:47:19 +00:00
public DateTime? LastPlayed { get; set; }
2018-11-21 06:34:53 +00:00
public short? ReleaseRating { get; set; }
2018-11-06 03:26:46 +00:00
public short? Rating { get; set; }
2018-11-15 00:16:25 +00:00
public UserTrack UserRating { get; set; }
2018-11-06 03:26:46 +00:00
public int? PlayedCount { get; set; }
public int? FavoriteCount { get; set; }
2018-11-14 03:19:28 +00:00
public Image Thumbnail { get; set; }
2018-11-06 03:26:46 +00:00
public string TrackPlayUrl { get; set; }
2018-11-14 03:19:28 +00:00
[MaxLength(65535)]
[JsonIgnore]
[IgnoreDataMember]
public string PartTitles { get; set; }
public IEnumerable<string> PartTitlesList
{
get
{
if (string.IsNullOrEmpty(this.PartTitles))
{
return null;
}
2018-12-08 03:10:21 +00:00
return this.PartTitles.Split('\n');
2018-11-14 03:19:28 +00:00
}
}
2018-11-21 06:34:53 +00:00
[JsonIgnore]
public DateTime? ReleaseDate { get; set; }
public int? Year
{
get
{
if(this.ReleaseDate.HasValue)
{
return this.ReleaseDate.Value.Year;
}
return null;
}
}
public int? FileSize { get; set; }
2018-12-08 19:47:19 +00:00
2018-12-11 23:09:52 +00:00
2019-01-02 02:03:17 +00:00
public static TrackList FromDataTrack(string trackPlayUrl,
Data.Track track,
2018-12-11 23:09:52 +00:00
int releaseMediaNumber,
Data.Release release,
Data.Artist artist,
Data.Artist trackArtist,
string baseUrl,
Image trackThumbnail,
Image releaseThumbnail,
Image artistThumbnail,
Image trackArtistThumbnail)
{
return new TrackList
{
DatabaseId = track.Id,
Id = track.RoadieId,
Track = new DataToken
{
Text = track.Title,
Value = track.RoadieId.ToString()
},
Release = ReleaseList.FromDataRelease(release, artist, baseUrl, artistThumbnail, releaseThumbnail),
LastPlayed = track.LastPlayed,
Artist = ArtistList.FromDataArtist(artist, artistThumbnail),
TrackArtist = trackArtist == null ? null : ArtistList.FromDataArtist(trackArtist, trackArtistThumbnail),
TrackNumber = track.TrackNumber,
MediaNumber = releaseMediaNumber,
CreatedDate = track.CreatedDate,
LastUpdated = track.LastUpdated,
Duration = track.Duration,
FileSize = track.FileSize,
ReleaseDate = release.ReleaseDate,
PlayedCount = track.PlayedCount,
Rating = track.Rating,
Title = track.Title,
2019-01-02 02:03:17 +00:00
TrackPlayUrl = trackPlayUrl,
2018-12-11 23:09:52 +00:00
Thumbnail = trackThumbnail
};
}
2018-11-06 03:26:46 +00:00
}
}