2017-09-04 02:20:56 +00:00
using System ;
using System.Collections.Generic ;
using System.Linq ;
2019-02-23 22:39:11 +00:00
using Newtonsoft.Json ;
2017-09-04 02:20:56 +00:00
using NzbDrone.Core.DecisionEngine ;
using NzbDrone.Core.Indexers ;
using NzbDrone.Core.Parser.Model ;
using NzbDrone.Core.Qualities ;
using Lidarr.Http.REST ;
2017-10-31 01:28:29 +00:00
namespace Lidarr.Api.V1.Indexers
2017-09-04 02:20:56 +00:00
{
public class ReleaseResource : RestResource
{
public string Guid { get ; set ; }
public QualityModel Quality { get ; set ; }
public int QualityWeight { get ; set ; }
public int Age { get ; set ; }
public double AgeHours { get ; set ; }
public double AgeMinutes { get ; set ; }
public long Size { get ; set ; }
public int IndexerId { get ; set ; }
public string Indexer { get ; set ; }
public string ReleaseGroup { get ; set ; }
public string SubGroup { get ; set ; }
public string ReleaseHash { get ; set ; }
public string Title { get ; set ; }
2018-02-10 04:03:12 +00:00
public bool Discography { get ; set ; }
2017-09-04 02:20:56 +00:00
public bool SceneSource { get ; set ; }
public string AirDate { get ; set ; }
public string ArtistName { get ; set ; }
2017-10-15 17:10:45 +00:00
public string AlbumTitle { get ; set ; }
2017-09-04 02:20:56 +00:00
public bool Approved { get ; set ; }
public bool TemporarilyRejected { get ; set ; }
public bool Rejected { get ; set ; }
public IEnumerable < string > Rejections { get ; set ; }
public DateTime PublishDate { get ; set ; }
public string CommentUrl { get ; set ; }
public string DownloadUrl { get ; set ; }
public string InfoUrl { get ; set ; }
public bool DownloadAllowed { get ; set ; }
public int ReleaseWeight { get ; set ; }
2019-02-23 22:39:11 +00:00
public int PreferredWordScore { get ; set ; }
2017-09-04 02:20:56 +00:00
public string MagnetUrl { get ; set ; }
public string InfoHash { get ; set ; }
public int? Seeders { get ; set ; }
public int? Leechers { get ; set ; }
public DownloadProtocol Protocol { get ; set ; }
2019-02-23 22:39:11 +00:00
// Sent when queuing an unknown release
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
// [JsonIgnore]
public int? ArtistId { get ; set ; }
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
// [JsonIgnore]
public int? AlbumId { get ; set ; }
2017-09-04 02:20:56 +00:00
}
public static class ReleaseResourceMapper
{
public static ReleaseResource ToResource ( this DownloadDecision model )
{
var releaseInfo = model . RemoteAlbum . Release ;
2017-09-15 03:33:13 +00:00
var parsedAlbumInfo = model . RemoteAlbum . ParsedAlbumInfo ;
2017-10-15 17:10:45 +00:00
var remoteAlbum = model . RemoteAlbum ;
2017-09-04 02:20:56 +00:00
var torrentInfo = ( model . RemoteAlbum . Release as TorrentInfo ) ? ? new TorrentInfo ( ) ;
// TODO: Clean this mess up. don't mix data from multiple classes, use sub-resources instead? (Got a huge Deja Vu, didn't we talk about this already once?)
return new ReleaseResource
{
Guid = releaseInfo . Guid ,
2017-09-15 03:33:13 +00:00
Quality = parsedAlbumInfo . Quality ,
2017-09-04 02:20:56 +00:00
//QualityWeight
Age = releaseInfo . Age ,
AgeHours = releaseInfo . AgeHours ,
AgeMinutes = releaseInfo . AgeMinutes ,
Size = releaseInfo . Size ,
IndexerId = releaseInfo . IndexerId ,
Indexer = releaseInfo . Indexer ,
2017-09-15 03:33:13 +00:00
ReleaseGroup = parsedAlbumInfo . ReleaseGroup ,
ReleaseHash = parsedAlbumInfo . ReleaseHash ,
2017-09-04 02:20:56 +00:00
Title = releaseInfo . Title ,
2017-09-15 03:33:13 +00:00
ArtistName = parsedAlbumInfo . ArtistName ,
2017-10-15 17:10:45 +00:00
AlbumTitle = parsedAlbumInfo . AlbumTitle ,
2018-02-10 04:03:12 +00:00
Discography = parsedAlbumInfo . Discography ,
2017-09-04 02:20:56 +00:00
Approved = model . Approved ,
TemporarilyRejected = model . TemporarilyRejected ,
Rejected = model . Rejected ,
Rejections = model . Rejections . Select ( r = > r . Reason ) . ToList ( ) ,
PublishDate = releaseInfo . PublishDate ,
CommentUrl = releaseInfo . CommentUrl ,
DownloadUrl = releaseInfo . DownloadUrl ,
InfoUrl = releaseInfo . InfoUrl ,
2017-10-15 17:10:45 +00:00
DownloadAllowed = remoteAlbum . DownloadAllowed ,
2017-09-04 02:20:56 +00:00
//ReleaseWeight
2019-02-23 22:39:11 +00:00
PreferredWordScore = remoteAlbum . PreferredWordScore ,
2017-09-04 02:20:56 +00:00
MagnetUrl = torrentInfo . MagnetUrl ,
InfoHash = torrentInfo . InfoHash ,
Seeders = torrentInfo . Seeders ,
Leechers = ( torrentInfo . Peers . HasValue & & torrentInfo . Seeders . HasValue ) ? ( torrentInfo . Peers . Value - torrentInfo . Seeders . Value ) : ( int? ) null ,
Protocol = releaseInfo . DownloadProtocol ,
2019-02-23 22:39:11 +00:00
} ;
2017-09-04 02:20:56 +00:00
}
public static ReleaseInfo ToModel ( this ReleaseResource resource )
{
ReleaseInfo model ;
if ( resource . Protocol = = DownloadProtocol . Torrent )
{
model = new TorrentInfo
{
MagnetUrl = resource . MagnetUrl ,
InfoHash = resource . InfoHash ,
Seeders = resource . Seeders ,
Peers = ( resource . Seeders . HasValue & & resource . Leechers . HasValue ) ? ( resource . Seeders + resource . Leechers ) : null
} ;
}
else
{
model = new ReleaseInfo ( ) ;
}
model . Guid = resource . Guid ;
model . Title = resource . Title ;
model . Size = resource . Size ;
model . DownloadUrl = resource . DownloadUrl ;
model . InfoUrl = resource . InfoUrl ;
model . CommentUrl = resource . CommentUrl ;
model . IndexerId = resource . IndexerId ;
model . Indexer = resource . Indexer ;
2019-04-12 01:48:08 +00:00
model . DownloadProtocol = resource . Protocol ;
2017-10-29 02:52:36 +00:00
model . PublishDate = resource . PublishDate . ToUniversalTime ( ) ;
2017-09-04 02:20:56 +00:00
return model ;
}
}
}