Would be fantastic if Plex could expose a series of web services, which would allow data to be retrieved and actions to be called. At the moment I am a .NET/C# developer so am unable to quickly program in Python, but would love to integrate with the solution.
Would be fantastic if Plex could expose a series of web services, which would allow data to be retrieved and actions to be called. At the moment I am a .NET/C# developer so am unable to quickly program in Python, but would love to integrate with the solution.
Check out http://127.0.0.1:32400/ and search the forums for docs.
Communication is simple with XML over HTTP or JSON over HTTP. The .NET framework has excellent facilities for XML out of the box, so I wrote a ‘Plex’ class that serves as a dynamic wrapper around the data. Here’s an usage example:
using (var wc = new WebClient()) {
wc.Encoding = Encoding.UTF8;
foreach (dynamic section in new Plex(wc.DownloadString(“http://127.0.0.1:32400/library/sections”))) {
Console.WriteLine(section.Title);
}
}And the class that serves as dynamic wrapper:using System;
using System.Collections;
using System.Dynamic;
using System.Linq;
using System.Xml.Linq;namespace PlexLibraryToHtml {
///
/// Represents dynamic XML for Plex.
///
public sealed class Plex : DynamicObject, IEnumerable {
///
/// Contains the attribute.
///
private readonly XAttribute _Attribute;/// <summary> /// Contains the element. /// </summary> private readonly XElement _Element; #region Constructor /// <summary> /// Initialize a new instance of the Plex class. /// </summary> /// <param name="Document">The document.</param> public Plex(string Document) { // Set the element. _Element = XElement.Parse(Document); } /// <summary> /// Initialize a new instance of the Plex class. /// </summary> /// <param name="Attribute">The attribute.</param> public Plex(XAttribute Attribute) { // Set the attribute. _Attribute = Attribute; } /// <summary> /// Initialize a new instance of the Plex class. /// </summary> /// <param name="Element">The element.</param> public Plex(XElement Element) { // Set the element. _Element = Element; } #endregion #region DynamicObject /// <summary> /// Provides implementation for type conversion operations. /// </summary> /// <param name="Binder">Provides information about the conversion operation.</param> /// <param name="Result">The result of the type conversion operation.</param> public override bool TryConvert(ConvertBinder Binder, out object Result) { // Attempt the following code. try { // Change the type of the value to the binder type. Result = Convert.ChangeType(ToString(), Binder.ReturnType); // Return true. return true; } catch { // Initialize the default. Result = Activator.CreateInstance(Binder.ReturnType); // Return true. return true; } } /// <summary> /// Provides the implementation for operations that get member values. /// </summary> /// <param name="Binder">Provides information about the object that called the dynamic operation.</param> /// <param name="Result">The result of the get operation.</param> public override bool TryGetMember(GetMemberBinder Binder, out object Result) { // Check if the element is invalid. if (_Element == null) { // Set the result. Result = null; // Return true. return true; } else { // Retrieve the attribute. var Attribute = _Element.Attributes().FirstOrDefault(x => string.Equals(x.Name.LocalName, Binder.Name, StringComparison.InvariantCultureIgnoreCase)); // Check if the attribute is invalid. if (Attribute == null) { // Set the result. Result = null; // Return true. return true; } else { // Set the result. Result = new Plex(Attribute); // Return true. return true; } } } #endregion #region Object /// <summary> /// Returns a string that represents the current object. /// </summary> public override string ToString() { // Return the attribute or element value. return _Attribute != null ? _Attribute.Value : _Element.Value; } #endregion #region IEnumerable /// <summary> /// Returns an enumerator that iterates through the collection. /// </summary> public IEnumerator GetEnumerator() { // Return the enumerator. return _Element.Elements().Select(x => new Plex(x)).GetEnumerator(); } #endregion }}
Fantastic, thanks guys!!!!
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.