You've already forked Sonarr
mirror of
https://github.com/Sonarr/Sonarr.git
synced 2025-11-06 09:19:38 +02:00
Added sabtitle method
Added custom parse option to Indexrbase
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Core.Model;
|
||||
@@ -58,13 +59,29 @@ namespace NzbDrone.Core.Providers
|
||||
return _sonicRepo.Find<Episode>(e => e.SeasonId == seasonId);
|
||||
}
|
||||
|
||||
public virtual String GetSabTitle(Episode episode)
|
||||
public virtual String GetSabTitle(EpisodeParseResult parseResult)
|
||||
{
|
||||
var series = _series.GetSeries(episode.SeriesId);
|
||||
if (series == null) throw new ArgumentException("Unknown series. ID: " + episode.SeriesId);
|
||||
//Show Name - 1x01-1x02 - Episode Name
|
||||
//Show Name - 1x01 - Episode Name
|
||||
var episodeString = new List<String>();
|
||||
|
||||
//TODO: This method should return a standard title for the sab episode.
|
||||
throw new NotImplementedException();
|
||||
foreach (var episode in parseResult.Episodes)
|
||||
{
|
||||
episodeString.Add(String.Format("{0}x{1}", parseResult.SeasonNumber, episode));
|
||||
}
|
||||
|
||||
var epNumberString = String.Join("-", episodeString);
|
||||
var series = _series.GetSeries(parseResult.SeriesId);
|
||||
var folderName = new DirectoryInfo(series.Path).Name;
|
||||
|
||||
var result = String.Format("{0} - {1} - {2} {3}", folderName, epNumberString, parseResult.EpisodeTitle, parseResult.Quality);
|
||||
|
||||
if (parseResult.Proper)
|
||||
{
|
||||
result += " [Proper]";
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -80,10 +97,23 @@ namespace NzbDrone.Core.Providers
|
||||
|
||||
if (episodeInfo == null)
|
||||
{
|
||||
|
||||
//Todo: How do we want to handle this really? Episode could be released before information is on TheTvDB
|
||||
//(Parks and Rec did this a lot in the first season, from experience)
|
||||
//Keivan: Should automatically add the episode to db with minimal information. then update the description/title when avilable.
|
||||
throw new NotImplementedException("Episode was not found in the database");
|
||||
//Keivan: Should automatically add the episode to db with minimal information. then update the description/title when available.
|
||||
episodeInfo = new Episode()
|
||||
{
|
||||
SeriesId = parsedReport.SeriesId,
|
||||
AirDate = DateTime.Now.Date,
|
||||
EpisodeNumber = episode,
|
||||
SeasonNumber = parsedReport.SeasonNumber,
|
||||
Title = String.Empty,
|
||||
Overview = String.Empty,
|
||||
Language = "en"
|
||||
};
|
||||
|
||||
_sonicRepo.Add(episodeInfo);
|
||||
|
||||
}
|
||||
|
||||
var file = episodeInfo.EpisodeFile;
|
||||
@@ -221,6 +251,8 @@ namespace NzbDrone.Core.Providers
|
||||
Title = episode.EpisodeName
|
||||
};
|
||||
|
||||
|
||||
//TODO: Replace this db check with a local check. Should make things even faster
|
||||
if (_sonicRepo.Exists<Episode>(e => e.EpisodeId == newEpisode.EpisodeId))
|
||||
{
|
||||
updateList.Add(newEpisode);
|
||||
|
||||
@@ -32,49 +32,25 @@ namespace NzbDrone.Core.Providers.Indexer
|
||||
_indexerProvider = indexerProvider;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the source URL for the feed
|
||||
/// </summary>
|
||||
protected abstract string[] Url { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name for the feed
|
||||
/// </summary>
|
||||
public abstract string Name { get; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Generates direct link to download an NZB
|
||||
/// Gets the source URL for the feed
|
||||
/// </summary>
|
||||
/// <param name = "item">RSS Feed item to generate the link for</param>
|
||||
/// <returns>Download link URL</returns>
|
||||
protected abstract string NzbDownloadUrl(SyndicationItem item);
|
||||
protected abstract string[] Urls { get; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Parses the RSS feed item and.
|
||||
/// </summary>
|
||||
/// <param name = "item">RSS feed item to parse</param>
|
||||
/// <returns>Detailed episode info</returns>
|
||||
protected EpisodeParseResult ParseFeed(SyndicationItem item)
|
||||
protected IndexerSetting Settings
|
||||
{
|
||||
var episodeParseResult = Parser.ParseEpisodeInfo(item.Title.Text);
|
||||
if (episodeParseResult == null) return null;
|
||||
|
||||
var seriesInfo = _seriesProvider.FindSeries(episodeParseResult.SeriesTitle);
|
||||
|
||||
if (seriesInfo != null)
|
||||
get
|
||||
{
|
||||
episodeParseResult.SeriesId = seriesInfo.SeriesId;
|
||||
episodeParseResult.SeriesTitle = seriesInfo.Title;
|
||||
return episodeParseResult;
|
||||
return _indexerProvider.GetSettings(GetType());
|
||||
}
|
||||
|
||||
Logger.Debug("Unable to map {0} to any of series in database", episodeParseResult.SeriesTitle);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Fetches RSS feed and process each news item.
|
||||
/// </summary>
|
||||
@@ -82,7 +58,7 @@ namespace NzbDrone.Core.Providers.Indexer
|
||||
{
|
||||
Logger.Info("Fetching feeds from " + Settings.Name);
|
||||
|
||||
foreach (var url in Url)
|
||||
foreach (var url in Urls)
|
||||
{
|
||||
Logger.Debug("Downloading RSS " + url);
|
||||
var feed = SyndicationFeed.Load(_httpProvider.DownloadXml(url)).Items;
|
||||
@@ -132,16 +108,45 @@ namespace NzbDrone.Core.Providers.Indexer
|
||||
}
|
||||
}
|
||||
|
||||
protected IndexerSetting Settings
|
||||
/// <summary>
|
||||
/// Parses the RSS feed item and.
|
||||
/// </summary>
|
||||
/// <param name = "item">RSS feed item to parse</param>
|
||||
/// <returns>Detailed episode info</returns>
|
||||
protected EpisodeParseResult ParseFeed(SyndicationItem item)
|
||||
{
|
||||
get
|
||||
var episodeParseResult = Parser.ParseEpisodeInfo(item.Title.Text);
|
||||
if (episodeParseResult == null) return CustomParser(item, null);
|
||||
|
||||
var seriesInfo = _seriesProvider.FindSeries(episodeParseResult.SeriesTitle);
|
||||
|
||||
if (seriesInfo != null)
|
||||
{
|
||||
return _indexerProvider.GetSettings(GetType());
|
||||
episodeParseResult.SeriesId = seriesInfo.SeriesId;
|
||||
episodeParseResult.SeriesTitle = seriesInfo.Title;
|
||||
return CustomParser(item, episodeParseResult);
|
||||
}
|
||||
|
||||
Logger.Debug("Unable to map {0} to any of series in database", episodeParseResult.SeriesTitle);
|
||||
return CustomParser(item, episodeParseResult);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method can be overwritten to provide indexer specific info parsing
|
||||
/// </summary>
|
||||
/// <param name="item">RSS item that needs to be parsed</param>
|
||||
/// <param name="currentResult">Result of the built in parse function.</param>
|
||||
/// <returns></returns>
|
||||
protected virtual EpisodeParseResult CustomParser(SyndicationItem item, EpisodeParseResult currentResult)
|
||||
{
|
||||
return currentResult;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Generates direct link to download an NZB
|
||||
/// </summary>
|
||||
/// <param name = "item">RSS Feed item to generate the link for</param>
|
||||
/// <returns>Download link URL</returns>
|
||||
protected abstract string NzbDownloadUrl(SyndicationItem item);
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ namespace NzbDrone.Core.Providers.Indexer
|
||||
{
|
||||
}
|
||||
|
||||
protected override string[] Url
|
||||
protected override string[] Urls
|
||||
{
|
||||
get
|
||||
{
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace NzbDrone.Core.Providers.Indexer
|
||||
{
|
||||
}
|
||||
|
||||
protected override string[] Url
|
||||
protected override string[] Urls
|
||||
{
|
||||
get
|
||||
{
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace NzbDrone.Core.Providers.Indexer
|
||||
{
|
||||
}
|
||||
|
||||
protected override string[] Url
|
||||
protected override string[] Urls
|
||||
{
|
||||
get
|
||||
{
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace NzbDrone.Core.Providers.Indexer
|
||||
{
|
||||
}
|
||||
|
||||
protected override string[] Url
|
||||
protected override string[] Urls
|
||||
{
|
||||
get
|
||||
{
|
||||
|
||||
@@ -127,7 +127,18 @@ namespace NzbDrone.Core.Providers.Jobs
|
||||
{
|
||||
Logger.Debug("Initializing background thread");
|
||||
|
||||
ThreadStart starter = () => Execute(jobType, targetId);
|
||||
ThreadStart starter = () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
Execute(jobType, targetId);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_isRunning = false;
|
||||
}
|
||||
};
|
||||
|
||||
_jobThread = new Thread(starter) { Name = "TimerThread", Priority = ThreadPriority.BelowNormal };
|
||||
_jobThread.Start();
|
||||
|
||||
@@ -169,14 +180,7 @@ namespace NzbDrone.Core.Providers.Jobs
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.ErrorException("An error has occurred while executing timer job" + timerClass.Name, e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (_jobThread == Thread.CurrentThread)
|
||||
{
|
||||
_isRunning = false;
|
||||
}
|
||||
Logger.ErrorException("An error has occurred while executing timer job " + timerClass.Name, e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,14 +198,13 @@ namespace NzbDrone.Core.Providers.Jobs
|
||||
var timerProviderLocal = timer;
|
||||
if (!currentTimer.Exists(c => c.TypeName == timerProviderLocal.GetType().ToString()))
|
||||
{
|
||||
var settings = new JobSetting()
|
||||
var settings = new JobSetting
|
||||
{
|
||||
Enable = true,
|
||||
TypeName = timer.GetType().ToString(),
|
||||
Name = timerProviderLocal.Name,
|
||||
Interval = timerProviderLocal.DefaultInterval,
|
||||
LastExecution = DateTime.MinValue
|
||||
|
||||
};
|
||||
|
||||
SaveSettings(settings);
|
||||
|
||||
Reference in New Issue
Block a user