2012-10-14 03:36:16 +03:00
|
|
|
using System;
|
2012-10-14 20:10:23 +03:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2012-10-14 03:36:16 +03:00
|
|
|
|
2013-02-27 06:19:22 +03:00
|
|
|
namespace NzbDrone.Core.Qualities
|
2010-09-28 08:01:54 +03:00
|
|
|
{
|
2013-02-27 06:19:22 +03:00
|
|
|
public class Quality : IComparable<Quality>
|
2010-09-28 08:01:54 +03:00
|
|
|
{
|
2012-10-14 03:36:16 +03:00
|
|
|
public int Id { get; set; }
|
|
|
|
public string Name { get; set; }
|
|
|
|
public int Weight { get; set; }
|
|
|
|
|
2013-02-27 06:19:22 +03:00
|
|
|
public int CompareTo(Quality other)
|
2012-10-14 03:36:16 +03:00
|
|
|
{
|
|
|
|
if (other.Weight > Weight)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (other.Weight < Weight)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (other.Weight == Weight)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-02-27 06:19:22 +03:00
|
|
|
public static bool operator !=(Quality x, Quality y)
|
2012-10-14 03:36:16 +03:00
|
|
|
{
|
|
|
|
return !(x == y);
|
|
|
|
}
|
|
|
|
|
2013-02-27 06:19:22 +03:00
|
|
|
public static bool operator ==(Quality x, Quality y)
|
2012-10-14 03:36:16 +03:00
|
|
|
{
|
|
|
|
var xObj = (Object)x;
|
|
|
|
var yObj = (object)y;
|
|
|
|
|
|
|
|
if (xObj == null || yObj == null)
|
|
|
|
{
|
|
|
|
return xObj == yObj;
|
|
|
|
}
|
|
|
|
|
|
|
|
return x.CompareTo(y) == 0;
|
|
|
|
}
|
|
|
|
|
2013-02-27 06:19:22 +03:00
|
|
|
public static bool operator >(Quality x, Quality y)
|
2012-10-14 03:36:16 +03:00
|
|
|
{
|
|
|
|
return x.CompareTo(y) > 0;
|
|
|
|
}
|
|
|
|
|
2013-02-27 06:19:22 +03:00
|
|
|
public static bool operator <(Quality x, Quality y)
|
2012-10-14 03:36:16 +03:00
|
|
|
{
|
|
|
|
return x.CompareTo(y) < 0;
|
|
|
|
}
|
|
|
|
|
2013-02-27 06:19:22 +03:00
|
|
|
public static bool operator <=(Quality x, Quality y)
|
2012-10-14 03:36:16 +03:00
|
|
|
{
|
|
|
|
return x.CompareTo(y) <= 0;
|
|
|
|
}
|
|
|
|
|
2013-02-27 06:19:22 +03:00
|
|
|
public static bool operator >=(Quality x, Quality y)
|
2012-10-14 03:36:16 +03:00
|
|
|
{
|
|
|
|
return x.CompareTo(y) >= 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
{
|
|
|
|
return Name;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override int GetHashCode()
|
|
|
|
{
|
|
|
|
unchecked // Overflow is fine, just wrap
|
|
|
|
{
|
|
|
|
int hash = 17;
|
|
|
|
hash = hash * 23 + Weight.GetHashCode();
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-27 06:19:22 +03:00
|
|
|
public bool Equals(Quality other)
|
2012-10-14 03:36:16 +03:00
|
|
|
{
|
|
|
|
if (ReferenceEquals(null, other)) return false;
|
|
|
|
if (ReferenceEquals(this, other)) return true;
|
|
|
|
return Equals(other.Weight, Weight);
|
|
|
|
}
|
|
|
|
|
|
|
|
public override bool Equals(object obj)
|
|
|
|
{
|
|
|
|
if (ReferenceEquals(null, obj)) return false;
|
|
|
|
if (ReferenceEquals(this, obj)) return true;
|
2013-02-27 06:19:22 +03:00
|
|
|
if (obj.GetType() != typeof (Quality)) return false;
|
|
|
|
return Equals((Quality) obj);
|
2012-10-14 03:36:16 +03:00
|
|
|
}
|
|
|
|
|
2013-02-27 11:21:36 +03:00
|
|
|
public static readonly Quality Unknown = new Quality { Id = 0, Name = "Unknown", Weight = 0 };
|
|
|
|
public static readonly Quality SDTV = new Quality {Id = 1, Name = "SDTV", Weight = 1};
|
|
|
|
public static readonly Quality WEBDL480p = new Quality { Id = 8, Name = "WEBDL-480p", Weight = 2 };
|
|
|
|
public static readonly Quality DVD = new Quality { Id = 2, Name = "DVD", Weight = 3 };
|
|
|
|
public static readonly Quality HDTV720p = new Quality { Id = 4, Name = "HDTV-720p", Weight = 4 };
|
|
|
|
public static readonly Quality HDTV1080p = new Quality { Id = 9, Name = "HDTV-1080p", Weight = 5 };
|
|
|
|
public static readonly Quality RAWHD = new Quality { Id = 10, Name = "Raw-HD", Weight = 6 };
|
|
|
|
public static readonly Quality WEBDL720p = new Quality { Id = 5, Name = "WEBDL-720p", Weight = 7 };
|
|
|
|
public static readonly Quality Bluray720p = new Quality { Id = 6, Name = "Bluray720p", Weight = 8 };
|
|
|
|
public static readonly Quality WEBDL1080p = new Quality { Id = 3, Name = "WEBDL-1080p", Weight = 9 };
|
|
|
|
public static readonly Quality Bluray1080p = new Quality { Id = 7, Name = "Bluray1080p", Weight = 10 };
|
2013-01-09 11:15:06 +03:00
|
|
|
|
2012-10-14 03:36:16 +03:00
|
|
|
|
2013-02-27 06:19:22 +03:00
|
|
|
public static List<Quality> All()
|
2012-10-14 20:10:23 +03:00
|
|
|
{
|
2013-02-27 06:19:22 +03:00
|
|
|
return new List<Quality>
|
2012-10-14 20:10:23 +03:00
|
|
|
{
|
|
|
|
Unknown,
|
|
|
|
SDTV,
|
2012-12-16 12:08:02 +03:00
|
|
|
WEBDL480p,
|
2012-10-14 20:10:23 +03:00
|
|
|
DVD,
|
2013-01-01 06:45:57 +03:00
|
|
|
HDTV720p,
|
|
|
|
HDTV1080p,
|
2013-01-09 11:15:06 +03:00
|
|
|
RAWHD,
|
2012-10-15 07:30:07 +03:00
|
|
|
WEBDL720p,
|
|
|
|
WEBDL1080p,
|
2012-10-14 20:10:23 +03:00
|
|
|
Bluray720p,
|
|
|
|
Bluray1080p
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2013-02-27 06:19:22 +03:00
|
|
|
public static Quality FindById(int id)
|
2012-10-14 03:36:16 +03:00
|
|
|
{
|
2012-10-14 20:10:23 +03:00
|
|
|
var quality = All().SingleOrDefault(q => q.Id == id);
|
|
|
|
|
|
|
|
if (quality == null)
|
|
|
|
throw new ArgumentException("ID does not match a known quality", "id");
|
|
|
|
|
|
|
|
return quality;
|
2012-10-14 03:36:16 +03:00
|
|
|
}
|
|
|
|
|
2013-02-27 06:19:22 +03:00
|
|
|
public static explicit operator Quality(int id)
|
2012-10-14 03:36:16 +03:00
|
|
|
{
|
|
|
|
return FindById(id);
|
|
|
|
}
|
|
|
|
|
2013-02-27 06:19:22 +03:00
|
|
|
public static explicit operator int(Quality quality)
|
2012-10-14 03:36:16 +03:00
|
|
|
{
|
|
|
|
return quality.Id;
|
|
|
|
}
|
2010-09-28 08:01:54 +03:00
|
|
|
}
|
|
|
|
}
|