From 6f3262c68abe7e0a024ba4dc95a80ede1f676f13 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sun, 5 Aug 2012 23:33:07 -0700 Subject: [PATCH] Release group is added to history and episodefile --- .../Datastore/Migrations/Migration20120802.cs | 2 ++ NzbDrone.Core/Model/EpisodeParseResult.cs | 2 ++ NzbDrone.Core/Parser.cs | 18 +++++++++------- NzbDrone.Core/Providers/DiskScanProvider.cs | 1 + NzbDrone.Core/Providers/DownloadProvider.cs | 1 + .../Providers/Indexer/IndexerBase.cs | 1 - NzbDrone.Core/Providers/Indexer/Newzbin.cs | 21 ++++++++++++++++--- NzbDrone.Core/Repository/EpisodeFile.cs | 1 + NzbDrone.Core/Repository/History.cs | 1 + 9 files changed, 37 insertions(+), 11 deletions(-) diff --git a/NzbDrone.Core/Datastore/Migrations/Migration20120802.cs b/NzbDrone.Core/Datastore/Migrations/Migration20120802.cs index 203d08874..fbe04ca84 100644 --- a/NzbDrone.Core/Datastore/Migrations/Migration20120802.cs +++ b/NzbDrone.Core/Datastore/Migrations/Migration20120802.cs @@ -12,6 +12,8 @@ namespace NzbDrone.Core.Datastore.Migrations protected override void MainDbUpgrade() { Database.AddColumn("EpisodeFiles", new Column("SceneName", DbType.String, ColumnProperty.Null)); + Database.AddColumn("EpisodeFiles", new Column("ReleaseGroup", DbType.String, ColumnProperty.Null)); + Database.AddColumn("History", new Column("ReleaseGroup", DbType.String, ColumnProperty.Null)); } } } \ No newline at end of file diff --git a/NzbDrone.Core/Model/EpisodeParseResult.cs b/NzbDrone.Core/Model/EpisodeParseResult.cs index 97a4a78a4..e2385d5ff 100644 --- a/NzbDrone.Core/Model/EpisodeParseResult.cs +++ b/NzbDrone.Core/Model/EpisodeParseResult.cs @@ -44,6 +44,8 @@ namespace NzbDrone.Core.Model public int Age { get; set; } + public string ReleaseGroup { get; set; } + public override string ToString() { diff --git a/NzbDrone.Core/Parser.cs b/NzbDrone.Core/Parser.cs index 462f81ad8..a151e0ef5 100644 --- a/NzbDrone.Core/Parser.cs +++ b/NzbDrone.Core/Parser.cs @@ -124,6 +124,7 @@ namespace NzbDrone.Core result.Language = ParseLanguage(title); result.Quality = ParseQuality(title); result.OriginalString = title; + result.ReleaseGroup = ParseReleaseGroup(title); return result; } } @@ -424,19 +425,22 @@ namespace NzbDrone.Core return LanguageType.English; } - internal static string ParseReleaseGroup(string name) + internal static string ParseReleaseGroup(string title) { - Logger.Trace("Trying to parse release group for {0}", name); + Logger.Trace("Trying to parse release group for {0}", title); - name = name.Trim(); - var index = name.LastIndexOf('-'); + title = title.Trim(); + var index = title.LastIndexOf('-'); if (index < 0) - index = name.LastIndexOf(' '); + index = title.LastIndexOf(' '); - var group = name.Substring(index + 1); + if (index < 0) + return String.Empty; - if (group.Length == name.Length) + var group = title.Substring(index + 1); + + if (group.Length == title.Length) return String.Empty; Logger.Trace("Release Group found: {0}", group); diff --git a/NzbDrone.Core/Providers/DiskScanProvider.cs b/NzbDrone.Core/Providers/DiskScanProvider.cs index dbad6d008..429a9b2bf 100644 --- a/NzbDrone.Core/Providers/DiskScanProvider.cs +++ b/NzbDrone.Core/Providers/DiskScanProvider.cs @@ -154,6 +154,7 @@ namespace NzbDrone.Core.Providers episodeFile.Proper = parseResult.Quality.Proper; episodeFile.SeasonNumber = parseResult.SeasonNumber; episodeFile.SceneName = Path.GetFileNameWithoutExtension(filePath.NormalizePath()); + episodeFile.ReleaseGroup = parseResult.ReleaseGroup; var fileId = _mediaFileProvider.Add(episodeFile); //Link file to all episodes diff --git a/NzbDrone.Core/Providers/DownloadProvider.cs b/NzbDrone.Core/Providers/DownloadProvider.cs index e70f87e74..d9ab4f3b2 100644 --- a/NzbDrone.Core/Providers/DownloadProvider.cs +++ b/NzbDrone.Core/Providers/DownloadProvider.cs @@ -63,6 +63,7 @@ namespace NzbDrone.Core.Providers history.EpisodeId = episode.EpisodeId; history.SeriesId = episode.SeriesId; history.NzbInfoUrl = parseResult.NzbInfoUrl; + history.ReleaseGroup = parseResult.ReleaseGroup; _historyProvider.Add(history); _episodeProvider.MarkEpisodeAsFetched(episode.EpisodeId); diff --git a/NzbDrone.Core/Providers/Indexer/IndexerBase.cs b/NzbDrone.Core/Providers/Indexer/IndexerBase.cs index 626104378..f6089a23c 100644 --- a/NzbDrone.Core/Providers/Indexer/IndexerBase.cs +++ b/NzbDrone.Core/Providers/Indexer/IndexerBase.cs @@ -63,7 +63,6 @@ namespace NzbDrone.Core.Providers.Indexer get { return null; } } - protected abstract IList GetEpisodeSearchUrls(string seriesTitle, int seasonNumber, int episodeNumber); protected abstract IList GetDailyEpisodeSearchUrls(string seriesTitle, DateTime date); protected abstract IList GetSeasonSearchUrls(string seriesTitle, int seasonNumber); diff --git a/NzbDrone.Core/Providers/Indexer/Newzbin.cs b/NzbDrone.Core/Providers/Indexer/Newzbin.cs index 733f70ce3..db91708cf 100644 --- a/NzbDrone.Core/Providers/Indexer/Newzbin.cs +++ b/NzbDrone.Core/Providers/Indexer/Newzbin.cs @@ -1,8 +1,10 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Net; using System.ServiceModel.Syndication; using System.Text.RegularExpressions; +using System.Xml.Linq; using Ninject; using NzbDrone.Common; using NzbDrone.Core.Model; @@ -44,7 +46,6 @@ namespace NzbDrone.Core.Providers.Indexer } } - protected override NetworkCredential Credentials { get { return new NetworkCredential(_configProvider.NewzbinUsername, _configProvider.NewzbinPassword); } @@ -90,7 +91,6 @@ namespace NzbDrone.Core.Providers.Indexer }; } - public override string Name { get { return "Newzbin"; } @@ -118,10 +118,25 @@ namespace NzbDrone.Core.Providers.Indexer var sizeString = Regex.Match(item.Summary.Text, @"\(Size: \d*\,?\d+\.\d{1,2}\w{2}\)", RegexOptions.IgnoreCase).Value; currentResult.Size = Parser.GetReportSize(sizeString); + + try + { + var releaseGroupText = item.ElementExtensions.Single(s => s.OuterName == "nfo") + .GetObject() + .Element(XName.Get("filename", "http://www.newzbin2.es/DTD/2007/feeds/report/")) + .Value; + + var releaseGroup = Parser.ParseReleaseGroup(releaseGroupText.Replace(".nfo", "")); + currentResult.ReleaseGroup = releaseGroup; + } + catch(Exception ex) + { + _logger.TraceException("Error getting release group for newzbin release", ex); + currentResult.ReleaseGroup = ""; + } } return currentResult; } - } } \ No newline at end of file diff --git a/NzbDrone.Core/Repository/EpisodeFile.cs b/NzbDrone.Core/Repository/EpisodeFile.cs index 86215ef9c..32758b8ce 100644 --- a/NzbDrone.Core/Repository/EpisodeFile.cs +++ b/NzbDrone.Core/Repository/EpisodeFile.cs @@ -35,6 +35,7 @@ namespace NzbDrone.Core.Repository public long Size { get; set; } public DateTime DateAdded { get; set; } public string SceneName { get; set; } + public string ReleaseGroup { get; set; } [Ignore] public Model.Quality QualityWrapper diff --git a/NzbDrone.Core/Repository/History.cs b/NzbDrone.Core/Repository/History.cs index 0c00ff2c9..597aab3da 100644 --- a/NzbDrone.Core/Repository/History.cs +++ b/NzbDrone.Core/Repository/History.cs @@ -17,6 +17,7 @@ namespace NzbDrone.Core.Repository public bool IsProper { get; set; } public string Indexer { get; set; } public string NzbInfoUrl { get; set; } + public string ReleaseGroup { get; set; } [ResultColumn] public Episode Episode { get; set; }