1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-05 10:32:35 +01:00
Radarr/NzbDrone.Core/Providers/TvDbProvider.cs

69 lines
2.2 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
2011-06-18 03:46:22 +02:00
using System.Linq;
using System.Text.RegularExpressions;
using NLog;
using NzbDrone.Common;
using TvdbLib;
using TvdbLib.Cache;
using TvdbLib.Data;
2010-09-23 05:19:47 +02:00
namespace NzbDrone.Core.Providers
2010-09-23 05:19:47 +02:00
{
public class TvDbProvider
2010-09-23 05:19:47 +02:00
{
private readonly EnvironmentProvider _environmentProvider;
2012-07-10 06:37:24 +02:00
public const string TVDB_APIKEY = "5D2D188E86E07F4F";
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private readonly TvdbHandler _handler;
2010-09-23 05:19:47 +02:00
public TvDbProvider(EnvironmentProvider environmentProvider)
{
_environmentProvider = environmentProvider;
_handler = new TvdbHandler(new XmlCacheProvider(_environmentProvider.GetCacheFolder()), TVDB_APIKEY);
}
public TvDbProvider()
2010-09-23 05:19:47 +02:00
{
2010-09-23 05:19:47 +02:00
}
public virtual IList<TvdbSearchResult> SearchSeries(string title)
{
lock (_handler)
{
Logger.Debug("Searching TVDB for '{0}'", title);
if(title.Contains(" & "))
{
Logger.Debug("Removing ampersand before searching");
title = title.Replace(" & ", " ");
}
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, bool loadActors = false)
2010-09-23 05:19:47 +02:00
{
lock (_handler)
{
Logger.Debug("Fetching SeriesId'{0}' from tvdb", id);
var result = _handler.GetSeries(id, TvdbLanguage.DefaultLanguage, loadEpisodes, loadActors, true, true);
//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 05:19:47 +02:00
}
}
}