mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-26 22:46:37 -04:00
Fixed: Replaced trakt with tvdb as data source
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
using System.Xml.Linq;
|
||||
using System.Xml.Schema;
|
||||
|
||||
namespace TVDBSharp.Utilities
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension methods used to simplify data extraction.
|
||||
/// </summary>
|
||||
public static class Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Retrieves a value from an XML tree representing a show.
|
||||
/// </summary>
|
||||
/// <param name="doc">XML tree representing a show.</param>
|
||||
/// <param name="element">Name of the element with the data.</param>
|
||||
/// <returns>Returns the value corresponding to the given element name.</returns>
|
||||
/// <exception cref="XmlSchemaException">Thrown when the element doesn't exist or the XML tree is incorrect.</exception>
|
||||
public static string GetSeriesData(this XDocument doc, string element)
|
||||
{
|
||||
var root = doc.Element("Data");
|
||||
if (root != null)
|
||||
{
|
||||
var xElement = root.Element("Series");
|
||||
if (xElement != null)
|
||||
{
|
||||
var result = xElement.Element(element);
|
||||
if (result != null)
|
||||
{
|
||||
return result.Value;
|
||||
}
|
||||
throw new XmlSchemaException("Could not find element <" + element + ">");
|
||||
}
|
||||
throw new XmlSchemaException("Could not find element <Series>");
|
||||
}
|
||||
throw new XmlSchemaException("Could not find element <Data>");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves a value from an XML tree.
|
||||
/// </summary>
|
||||
/// <param name="xmlObject">The given XML (sub)tree.</param>
|
||||
/// <param name="element">Name of the element with the data.</param>
|
||||
/// <returns>Returns the value corresponding to the given element name;</returns>
|
||||
/// <exception cref="XmlSchemaException">Thrown when the element doesn't exist.</exception>
|
||||
public static string GetXmlData(this XElement xmlObject, string element)
|
||||
{
|
||||
var result = xmlObject.Element(element);
|
||||
|
||||
return result != null ? result.Value : null;
|
||||
|
||||
// Removed in favor of returning a null value
|
||||
// This will allow us to catch a non-existing tag with the null-coalescing operator
|
||||
// Never trust the XML provider.
|
||||
|
||||
//throw new XmlSchemaException("Element <" + element + "> could not be found.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using TVDBSharp.Models.Enums;
|
||||
|
||||
namespace TVDBSharp.Utilities
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides static utility methods.
|
||||
/// </summary>
|
||||
public static class Utils
|
||||
{
|
||||
/// <summary>
|
||||
/// Parses a string of format yyyy-MM-dd to a <see cref="DateTime" /> object.
|
||||
/// </summary>
|
||||
/// <param name="value">String to be parsed.</param>
|
||||
/// <returns>Returns a <see cref="DateTime" /> representation.</returns>
|
||||
public static DateTime ParseDate(string value)
|
||||
{
|
||||
DateTime date;
|
||||
DateTime.TryParseExact(value, "yyyy-MM-dd", CultureInfo.CurrentCulture, DateTimeStyles.AssumeLocal, out date);
|
||||
return date;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parses a string of format hh:mm tt to a <see cref="TimeSpan" /> object.
|
||||
/// </summary>
|
||||
/// <param name="value">String to be parsed.</param>
|
||||
/// <returns>Returns a <see cref="TimeSpan" /> representation.</returns>
|
||||
public static TimeSpan ParseTime(string value)
|
||||
{
|
||||
DateTime date;
|
||||
|
||||
if (!DateTime.TryParse(value, out date))
|
||||
{
|
||||
return new TimeSpan();
|
||||
}
|
||||
return date.TimeOfDay;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Translates the incoming string to a <see cref="ContentRating" /> enum, if applicable.
|
||||
/// </summary>
|
||||
/// <param name="rating">The rating in string format.</param>
|
||||
/// <returns>Returns the appropriate <see cref="ContentRating" /> value.</returns>
|
||||
/// <exception cref="ArgumentException">Throws an exception if no conversion could be applied.</exception>
|
||||
public static ContentRating GetContentRating(string rating)
|
||||
{
|
||||
switch (rating)
|
||||
{
|
||||
case "TV-14":
|
||||
return ContentRating.TV14;
|
||||
|
||||
case "TV-PG":
|
||||
return ContentRating.TVPG;
|
||||
|
||||
case "TV-Y":
|
||||
return ContentRating.TVY;
|
||||
|
||||
case "TV-Y7":
|
||||
return ContentRating.TVY7;
|
||||
|
||||
case "TV-G":
|
||||
return ContentRating.TVG;
|
||||
|
||||
case "TV-MA":
|
||||
return ContentRating.TVMA;
|
||||
|
||||
default:
|
||||
return ContentRating.Unknown;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user