Fixed: Replaced trakt with tvdb as data source

This commit is contained in:
Keivan Beigi
2014-12-30 14:08:08 -08:00
parent 0f56bfac2f
commit 19f5427dbf
25 changed files with 1589 additions and 4 deletions
+43
View File
@@ -0,0 +1,43 @@
using System.IO;
using System.Net;
using System.Xml.Linq;
using TVDBSharp.Models.Enums;
namespace TVDBSharp.Models.DAO
{
/// <summary>
/// Standard implementation of the <see cref="IDataProvider" /> interface.
/// </summary>
public class DataProvider : IDataProvider
{
public string ApiKey { get; set; }
private const string BaseUrl = "http://thetvdb.com";
public XDocument GetShow(int showID)
{
return GetXDocumentFromUrl(string.Format("{0}/api/{1}/series/{2}/all/", BaseUrl, ApiKey, showID));
}
public XDocument GetEpisode(int episodeId, string lang)
{
return GetXDocumentFromUrl(string.Format("{0}/api/{1}/episodes/{2}/{3}.xml", BaseUrl, ApiKey, episodeId, lang));
}
public XDocument GetUpdates(Interval interval)
{
return GetXDocumentFromUrl(string.Format("{0}/api/{1}/updates/updates_{2}.xml", BaseUrl, ApiKey, IntervalHelpers.Print(interval)));
}
public XDocument Search(string query)
{
return GetXDocumentFromUrl(string.Format("{0}/api/GetSeries.php?seriesname={1}", BaseUrl, query));
}
private static XDocument GetXDocumentFromUrl(string url)
{
using (var web = new WebClient())
using (var memoryStream = new MemoryStream(web.DownloadData(url)))
return XDocument.Load(memoryStream);
}
}
}
+45
View File
@@ -0,0 +1,45 @@
using System.Xml.Linq;
using TVDBSharp.Models.Enums;
namespace TVDBSharp.Models.DAO
{
/// <summary>
/// Defines a Dataprovider API.
/// </summary>
public interface IDataProvider
{
/// <summary>
/// The API key provided by TVDB.
/// </summary>
string ApiKey { get; set; }
/// <summary>
/// Retrieves the show with the given id and returns the corresponding XML tree.
/// </summary>
/// <param name="showID">ID of the show you wish to lookup.</param>
/// <returns>Returns an XML tree of the show object.</returns>
XDocument GetShow(int showID);
/// <summary>
/// Retrieves the episode with the given id and returns the corresponding XML tree.
/// </summary>
/// <param name="episodeId">ID of the episode to retrieve</param>
/// <param name="lang">ISO 639-1 language code of the episode</param>
/// <returns>XML tree of the episode object</returns>
XDocument GetEpisode(int episodeId, string lang);
/// <summary>
/// Retrieves updates on tvdb (Shows, Episodes and Banners)
/// </summary>
/// <param name="interval">The interval for the updates</param>
/// <returns>XML tree of the Updates object</returns>
XDocument GetUpdates(Interval interval);
/// <summary>
/// Returns an XML tree representing a search query for the given parameter.
/// </summary>
/// <param name="query">Query to perform the search with.</param>
/// <returns>Returns an XML tree of a search result.</returns>
XDocument Search(string query);
}
}