1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-08-16 23:39:44 +02:00

simplified quality fixed some broken tests

This commit is contained in:
Keivan 2011-02-03 11:47:51 -08:00
parent 764f67f8e8
commit ca27c75df5
10 changed files with 47 additions and 89 deletions

View File

@ -21,6 +21,7 @@ public class ParserTest
[Row(@"z:\tv shows\battlestar galactica (2003)\Season 3\S03E05 - Collaborators.mkv", 3, 5)] [Row(@"z:\tv shows\battlestar galactica (2003)\Season 3\S03E05 - Collaborators.mkv", 3, 5)]
[Row(@"z:\tv shows\modern marvels\Season 16\S16E03 - The Potato.mkv", 16, 3)] [Row(@"z:\tv shows\modern marvels\Season 16\S16E03 - The Potato.mkv", 16, 3)]
[Row(@"z:\tv shows\robot chicken\Specials\S00E16 - Dear Consumer - SD TV.avi", 0, 16)] [Row(@"z:\tv shows\robot chicken\Specials\S00E16 - Dear Consumer - SD TV.avi", 0, 16)]
[Row(@"Parenthood.2010.S02E14.HDTV.XviD-LOL", 2, 14)]
public void episode_parse(string path, int season, int episode) public void episode_parse(string path, int season, int episode)
{ {
var result = Parser.ParseEpisodeInfo(path); var result = Parser.ParseEpisodeInfo(path);
@ -30,8 +31,8 @@ public void episode_parse(string path, int season, int episode)
} }
[Test] [Test]
[Row("WEEDS.S03E01-06.DUAL.BDRip.XviD.AC3.-HELLYWOOD", QualityTypes.DVD)] [Row("WEEDS.S03E01-06.DUAL.BDRip.XviD.AC3.-HELLYWOOD", QualityTypes.BDRip)]
[Row("WEEDS.S03E01-06.DUAL.BDRip.AC3.-HELLYWOOD", QualityTypes.Bluray)] [Row("WEEDS.S03E01-06.DUAL.BDRip.AC3.-HELLYWOOD", QualityTypes.BDRip)]
[Row("Two.and.a.Half.Men.S08E05.720p.HDTV.X264-DIMENSION", QualityTypes.HDTV)] [Row("Two.and.a.Half.Men.S08E05.720p.HDTV.X264-DIMENSION", QualityTypes.HDTV)]
[Row("Chuck.S04E05.HDTV.XviD-LOL", QualityTypes.TV)] [Row("Chuck.S04E05.HDTV.XviD-LOL", QualityTypes.TV)]
[Row("The.Girls.Next.Door.S03E06.DVDRip.XviD-WiDE", QualityTypes.DVD)] [Row("The.Girls.Next.Door.S03E06.DVDRip.XviD-WiDE", QualityTypes.DVD)]

View File

@ -29,10 +29,10 @@ public void Test_Storage()
//Act //Act
var id = (int)repo.Add(testProfile); var id = (int)repo.Add(testProfile);
var fetch = repo.Single<QualityProfile>(c => c.Id == id); var fetch = repo.Single<QualityProfile>(c => c.ProfileId == id);
//Assert //Assert
Assert.AreEqual(id, fetch.Id); Assert.AreEqual(id, fetch.ProfileId);
Assert.AreEqual(testProfile.Cutoff, fetch.Cutoff); Assert.AreEqual(testProfile.Cutoff, fetch.Cutoff);
Assert.AreEqual(testProfile.Allowed, fetch.Allowed); Assert.AreEqual(testProfile.Allowed, fetch.Allowed);
} }

View File

@ -212,7 +212,6 @@
<Compile Include="Instrumentation\Log.cs" /> <Compile Include="Instrumentation\Log.cs" />
<Compile Include="Repository\History.cs" /> <Compile Include="Repository\History.cs" />
<Compile Include="Repository\Indexer.cs" /> <Compile Include="Repository\Indexer.cs" />
<Compile Include="Repository\Quality\AllowedQuality.cs" />
<Compile Include="Repository\Config.cs" /> <Compile Include="Repository\Config.cs" />
<Compile Include="Repository\Quality\QualityProfile.cs" /> <Compile Include="Repository\Quality\QualityProfile.cs" />
<Compile Include="Repository\Season.cs" /> <Compile Include="Repository\Season.cs" />

View File

@ -18,7 +18,7 @@ internal static class Parser
private static readonly Regex[] ReportTitleRegex = new[] private static readonly Regex[] ReportTitleRegex = new[]
{ {
new Regex(@"(?<title>.+?)?\W(S)?(?<season>\d+)[EeXx](?<episode>\d+)\W(?!\\)", RegexOptions.IgnoreCase | RegexOptions.Compiled) new Regex(@"(?<title>.+?)?\W(S)?(?<season>\d+)\w(?<episode>\d+)\W(?!\\)", RegexOptions.IgnoreCase | RegexOptions.Compiled)
}; };
private static readonly Regex NormalizeRegex = new Regex(@"((\s|^)the(\s|$))|((\s|^)and(\s|$))|[^a-z]", RegexOptions.IgnoreCase | RegexOptions.Compiled); private static readonly Regex NormalizeRegex = new Regex(@"((\s|^)the(\s|$))|((\s|^)and(\s|$))|[^a-z]", RegexOptions.IgnoreCase | RegexOptions.Compiled);
@ -80,21 +80,25 @@ internal static QualityTypes ParseQuality(string name)
if (name.Contains("dvd")) if (name.Contains("dvd"))
return QualityTypes.DVD; return QualityTypes.DVD;
if (name.Contains("bdrip") || name.Contains("brrip"))
{
return QualityTypes.BDRip;
}
if (name.Contains("xvid") || name.Contains("divx")) if (name.Contains("xvid") || name.Contains("divx"))
{ {
if (name.Contains("bluray") || name.Contains("bdrip")) if (name.Contains("bluray"))
{ {
return QualityTypes.DVD; return QualityTypes.BDRip;
} }
return QualityTypes.TV; return QualityTypes.TV;
} }
if (name.Contains("bluray") || name.Contains("bdrip")) if (name.Contains("bluray"))
{ {
if (name.Contains("1080p")) return QualityTypes.Bluray;
return QualityTypes.Bluray1080p;
return QualityTypes.Bluray720p;
} }
if (name.Contains("web-dl")) if (name.Contains("web-dl"))
return QualityTypes.WEBDL; return QualityTypes.WEBDL;
@ -142,14 +146,14 @@ public static string NormalizePath(string path)
if (String.IsNullOrEmpty(path)) if (String.IsNullOrEmpty(path))
throw new ArgumentException("Path can not be null or empty"); throw new ArgumentException("Path can not be null or empty");
var info = new FileInfo(path); var info = new FileInfo(path);
if( info.FullName.StartsWith(@"\\")) //UNC if (info.FullName.StartsWith(@"\\")) //UNC
{ {
return info.FullName.ToLower().TrimEnd('/', '\\', ' '); return info.FullName.ToLower().TrimEnd('/', '\\', ' ');
} }
return info.FullName.ToLower().Trim('/', '\\', ' '); return info.FullName.ToLower().Trim('/', '\\', ' ');
} }
public static NzbInfoModel ParseNzbInfo(FeedInfoModel feed, RssItem item) public static NzbInfoModel ParseNzbInfo(FeedInfoModel feed, RssItem item)

View File

@ -8,9 +8,9 @@ namespace NzbDrone.Core.Providers
{ {
public interface IQualityProvider public interface IQualityProvider
{ {
void AddProfile(QualityProfile profile, List<AllowedQuality> allowedQualities); void Add(QualityProfile profile);
void UpdateProfile(QualityProfile profile, List<AllowedQuality> allowedQualities); void Update(QualityProfile profile);
void RemoveProfile(int profileId); void Delete(int profileId);
List<QualityProfile> GetProfiles(); List<QualityProfile> GetAllProfiles();
} }
} }

View File

@ -18,61 +18,31 @@ public QualityProvider(IRepository sonicRepo)
#region IQualityProvider Members #region IQualityProvider Members
public void AddProfile(QualityProfile profile, List<AllowedQuality> allowedQualities) public void Add(QualityProfile profile)
{ {
var profileId = _sonicRepo.Add(profile); _sonicRepo.Add(profile);
foreach (var allowed in allowedQualities)
{
allowed.ProfileId = (int)profileId;
_sonicRepo.Add<AllowedQuality>(allowed);
}
} }
public void UpdateProfile(QualityProfile profile, List<AllowedQuality> allowedQualities) public void Update(QualityProfile profile)
{ {
if (!_sonicRepo.Exists<QualityProfile>(q => q.ProfileId == profile.ProfileId)) if (!_sonicRepo.Exists<QualityProfile>(q => q.ProfileId == profile.ProfileId))
{ {
//Log Error //Log Error
throw new NotImplementedException(); throw new InvalidOperationException("Unable to update none existing profile");
} }
_sonicRepo.Update<QualityProfile>(profile); _sonicRepo.Update(profile);
//Check to see if any items in the DB do not exist in this list
//Check to see if any of the allowedQualities already exist, if so update, else add
foreach (var inDb in _sonicRepo.All<AllowedQuality>().Where(q => q.ProfileId == profile.ProfileId))
{
if (!allowedQualities.Exists(l => l.ProfileId == inDb.ProfileId && l.Quality == inDb.Quality))
_sonicRepo.Delete<AllowedQuality>(inDb.Id);
}
foreach (var allowed in allowedQualities)
{
allowed.ProfileId = profile.ProfileId;
if (!_sonicRepo.Exists<AllowedQuality>(q => q.ProfileId == profile.ProfileId && q.Quality == allowed.Quality))
_sonicRepo.Add(allowed);
else
_sonicRepo.Update(allowed);
}
} }
public void RemoveProfile(int profileId) public void Delete(int profileId)
{ {
_sonicRepo.DeleteMany<AllowedQuality>(q => q.ProfileId == profileId);
_sonicRepo.Delete<QualityProfile>(profileId); _sonicRepo.Delete<QualityProfile>(profileId);
} }
public List<QualityProfile> GetProfiles() public List<QualityProfile> GetAllProfiles()
{ {
var profiles = _sonicRepo.All<QualityProfile>().ToList(); var profiles = _sonicRepo.All<QualityProfile>().ToList();
foreach (var profile in profiles)
{
profile.AllowedQualities = _sonicRepo.Find<AllowedQuality>(q => q.ProfileId == profile.ProfileId).ToList();
}
return profiles; return profiles;
} }

View File

@ -1,16 +0,0 @@
using SubSonic.SqlGeneration.Schema;
namespace NzbDrone.Core.Repository.Quality
{
public class AllowedQuality
{
public int Id { get; set; }
public int ProfileId { get; set; }
public int Order { get; set; }
public bool MarkComplete { get; set; }
public QualityTypes Quality { get; set; }
[SubSonicToOneRelation(ThisClassContainsJoinKey = true)]
public virtual QualityProfile QualityProfile { get; private set; }
}
}

View File

@ -12,10 +12,9 @@ public class QualityProfile
public string Name { get; set; } public string Name { get; set; }
public bool UserProfile { get; set; } //Allows us to tell the difference between default and user profiles public bool UserProfile { get; set; } //Allows us to tell the difference between default and user profiles
[SubSonicToManyRelation] public List<QualityTypes> Allowed { get; set; }
public virtual List<AllowedQuality> Allowed { get; private set; } public QualityTypes Cutoff { get; set; }
[SubSonicIgnore]
public List<AllowedQuality> AllowedQualities { get; set; }
} }
} }

View File

@ -19,6 +19,10 @@ public enum QualityTypes
/// </summary> /// </summary>
DVD = 2, DVD = 2,
/// <summary> /// <summary>
/// SD File (HD Source)
/// </summary>
BDRip = 2,
/// <summary>
/// HD File (HDTV Source) /// HD File (HDTV Source)
/// </summary> /// </summary>
HDTV = 3, HDTV = 3,
@ -27,12 +31,9 @@ public enum QualityTypes
/// </summary> /// </summary>
WEBDL = 4, WEBDL = 4,
/// <summary> /// <summary>
/// 720P HD File (Blu-ray Source) /// HD File (Blu-ray Source could be 1080p or 720p)
/// </summary> /// </summary>
Bluray720p = 5, Bluray = 5,
/// <summary>
/// 1080P HD File (Blu-ray Source)
/// </summary>
Bluray1080p = 6
} }
} }

View File

@ -97,8 +97,8 @@ public ActionResult Quality()
{ {
ViewData["viewName"] = "Quality"; ViewData["viewName"] = "Quality";
var userProfiles = _qualityProvider.GetProfiles().Where(q => q.UserProfile).ToList(); var userProfiles = _qualityProvider.GetAllProfiles().Where(q => q.UserProfile).ToList();
var profiles = _qualityProvider.GetProfiles().Where(q => q.UserProfile == false).ToList(); var profiles = _qualityProvider.GetAllProfiles().Where(q => q.UserProfile == false).ToList();
QualityModel model = new QualityModel {Profiles = profiles, UserProfiles = userProfiles}; QualityModel model = new QualityModel {Profiles = profiles, UserProfiles = userProfiles};