Jackett/src/Jackett.Common/Models/ReleaseInfo.cs

132 lines
4.7 KiB
C#
Raw Normal View History

using System;
2015-04-13 06:25:21 +00:00
using System.Collections.Generic;
using System.Linq;
using Jackett.Common.Indexers;
using Jackett.Common.Utils;
using Newtonsoft.Json;
2015-04-13 06:25:21 +00:00
namespace Jackett.Common.Models
2015-04-13 06:25:21 +00:00
{
public class ReleaseInfo : ICloneable
2015-04-13 06:25:21 +00:00
{
public string Title { get; set; }
public Uri Guid { get; set; }
public Uri Link { get; set; }
public Uri Comments { get; set; }
public DateTime PublishDate { get; set; }
public ICollection<int> Category { get; set; }
public long? Size { get; set; }
public long? Files { get; set; }
public long? Grabs { get; set; }
2015-04-13 06:25:21 +00:00
public string Description { get; set; }
public long? RageID { get; set; }
public long? TVDBId { get; set; }
2015-04-13 06:25:21 +00:00
public long? Imdb { get; set; }
2017-01-31 17:44:23 +00:00
public long? TMDb { get; set; }
2015-04-13 06:25:21 +00:00
public int? Seeders { get; set; }
public int? Peers { get; set; }
public Uri BannerUrl { get; set; }
public string InfoHash { get; set; }
2015-04-25 19:37:03 +00:00
public Uri MagnetUri { get; set; }
2015-04-13 06:25:21 +00:00
public double? MinimumRatio { get; set; }
public long? MinimumSeedTime { get; set; }
public double? DownloadVolumeFactor { get; set; }
public double? UploadVolumeFactor { get; set; }
[JsonIgnore] // don't export the Origin to the manul search API, otherwise each result line contains a full recursive indexer JSON structure
public IIndexer Origin;
2015-04-13 06:25:21 +00:00
public double? Gain
{
get
{
var sizeInGB = Size / 1024.0 / 1024.0 / 1024.0;
return Seeders * sizeInGB;
}
}
public ReleaseInfo()
2015-06-28 18:07:25 +00:00
{
}
protected ReleaseInfo(ReleaseInfo copyFrom)
{
Title = copyFrom.Title;
Guid = copyFrom.Guid;
Link = copyFrom.Link;
Comments = copyFrom.Comments;
PublishDate = copyFrom.PublishDate;
Category = copyFrom.Category;
Size = copyFrom.Size;
Files = copyFrom.Files;
Grabs = copyFrom.Grabs;
Description = copyFrom.Description;
RageID = copyFrom.RageID;
Imdb = copyFrom.Imdb;
TMDb = copyFrom.TMDb;
Seeders = copyFrom.Seeders;
Peers = copyFrom.Peers;
BannerUrl = copyFrom.BannerUrl;
InfoHash = copyFrom.InfoHash;
MagnetUri = copyFrom.MagnetUri;
MinimumRatio = copyFrom.MinimumRatio;
MinimumSeedTime = copyFrom.MinimumSeedTime;
DownloadVolumeFactor = copyFrom.DownloadVolumeFactor;
UploadVolumeFactor = copyFrom.UploadVolumeFactor;
}
public virtual object Clone()
{
return new ReleaseInfo(this);
2015-06-28 18:07:25 +00:00
}
2015-04-13 06:25:21 +00:00
2015-07-26 02:33:01 +00:00
// ex: " 3.5 gb "
public static long GetBytes(string str)
{
var valStr = new string(str.Where(c => char.IsDigit(c) || c == '.').ToArray());
var unit = new string(str.Where(char.IsLetter).ToArray());
var val = ParseUtil.CoerceFloat(valStr);
return GetBytes(unit, val);
}
2015-04-18 21:08:00 +00:00
public static long GetBytes(string unit, float value)
{
2015-07-26 02:33:01 +00:00
unit = unit.Replace("i", "").ToLowerInvariant();
if (unit.Contains("kb"))
return BytesFromKB(value);
if (unit.Contains("mb"))
return BytesFromMB(value);
if (unit.Contains("gb"))
return BytesFromGB(value);
if (unit.Contains("tb"))
return BytesFromTB(value);
return (long)value;
}
public static long BytesFromTB(float tb)
{
return BytesFromGB(tb * 1024f);
2015-04-18 21:08:00 +00:00
}
2015-04-16 06:04:28 +00:00
public static long BytesFromGB(float gb)
{
return BytesFromMB(gb * 1024f);
}
public static long BytesFromMB(float mb)
{
return BytesFromKB(mb * 1024f);
}
public static long BytesFromKB(float kb)
{
return (long)(kb * 1024f);
}
public override string ToString()
{
return string.Format("[ReleaseInfo: Title={0}, Guid={1}, Link={2}, Comments={3}, PublishDate={4}, Category={5}, Size={6}, Files={7}, Grabs={8}, Description={9}, RageID={10}, TVDBId={11}, Imdb={12}, TMDb={13}, Seeders={14}, Peers={15}, BannerUrl={16}, InfoHash={17}, MagnetUri={18}, MinimumRatio={19}, MinimumSeedTime={20}, DownloadVolumeFactor={21}, UploadVolumeFactor={22}, Gain={23}]", Title, Guid, Link, Comments, PublishDate, Category, Size, Files, Grabs, Description, RageID, TVDBId, Imdb, TMDb, Seeders, Peers, BannerUrl, InfoHash, MagnetUri, MinimumRatio, MinimumSeedTime, DownloadVolumeFactor, UploadVolumeFactor, Gain);
}
2015-04-13 06:25:21 +00:00
}
}