1
0
Fork 0
mirror of https://github.com/Sonarr/Sonarr synced 2024-12-28 02:37:40 +00:00
Sonarr/NzbDrone.Core/Providers/TvDbProvider.cs

82 lines
2.9 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
2011-06-18 01:46:22 +00:00
using System.Linq;
using System.Text.RegularExpressions;
using NLog;
2010-09-23 03:19:47 +00:00
using TvdbLib;
using TvdbLib.Cache;
using TvdbLib.Data;
namespace NzbDrone.Core.Providers
2010-09-23 03:19:47 +00:00
{
public class TvDbProvider
2010-09-23 03:19:47 +00:00
{
2011-04-10 02:44:01 +00:00
private const string TVDB_APIKEY = "5D2D188E86E07F4F";
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
2011-04-10 02:44:01 +00:00
private static readonly Regex CleanUpRegex = new Regex(@"((\s|^)the(\s|$))|((\s|^)and(\s|$))|[^a-z]",
RegexOptions.IgnoreCase | RegexOptions.Compiled);
2010-09-23 03:19:47 +00:00
private readonly TvdbHandler _handler;
public TvDbProvider()
2010-09-23 03:19:47 +00:00
{
2010-10-05 06:21:18 +00:00
_handler = new TvdbHandler(new XmlCacheProvider(CentralDispatch.AppPath + @"\cache\tvdb"), TVDB_APIKEY);
2010-09-23 03:19:47 +00:00
}
public virtual IList<TvdbSearchResult> SearchSeries(string title)
{
lock (_handler)
{
Logger.Debug("Searching TVDB for '{0}'", title);
var result = _handler.SearchSeries(title);
Logger.Debug("Search for '{0}' returned {1} possible results", title, result.Count);
return result;
}
}
public virtual TvdbSeries GetSeries(int id, bool loadEpisodes)
2010-09-23 03:19:47 +00:00
{
lock (_handler)
{
Logger.Debug("Fetching SeriesId'{0}' from tvdb", id);
2011-06-21 05:44:01 +00:00
var result = _handler.GetSeries(id, TvdbLanguage.DefaultLanguage, loadEpisodes, false, true, true);
//Fix American Dad's scene gongshow
if (result != null && result.Id == 73141)
{
2011-06-13 04:24:57 +00:00
var seasonOneEpisodeCount = result.Episodes.Where(e => e.SeasonNumber == 1).Count();
var seasonOneId = result.Episodes.Where(e => e.SeasonNumber == 1).First().SeasonId;
foreach (var episode in result.Episodes)
{
if (episode.SeasonNumber > 1)
{
if (episode.SeasonNumber == 2)
{
episode.EpisodeNumber = episode.EpisodeNumber + seasonOneEpisodeCount;
episode.SeasonId = seasonOneId;
}
episode.SeasonNumber = episode.SeasonNumber - 1;
}
}
}
//Remove duplicated episodes
var episodes = result.Episodes.OrderByDescending(e => e.FirstAired).ThenByDescending(e => e.EpisodeName)
.GroupBy(e => e.SeriesId.ToString("000000") + e.SeasonNumber.ToString("000") + e.EpisodeNumber.ToString("000"))
.Select(e => e.First());
result.Episodes = episodes.ToList();
return result;
}
2010-09-23 03:19:47 +00:00
}
}
}