2012-07-12 08:55:27 +02:00
|
|
|
|
using System;
|
2012-07-26 04:33:11 +02:00
|
|
|
|
using System.ComponentModel.Composition;
|
2012-08-10 15:07:58 +02:00
|
|
|
|
using System.Net;
|
2012-07-12 08:55:27 +02:00
|
|
|
|
using System.Reactive.Linq;
|
2012-07-13 05:50:50 +02:00
|
|
|
|
using MediaBrowser.Api.HttpHandlers;
|
2012-07-21 20:39:47 +02:00
|
|
|
|
using MediaBrowser.Common.Net.Handlers;
|
2012-07-12 08:55:27 +02:00
|
|
|
|
using MediaBrowser.Common.Plugins;
|
|
|
|
|
using MediaBrowser.Controller;
|
2012-07-24 16:54:34 +02:00
|
|
|
|
using MediaBrowser.Model.Plugins;
|
2012-07-12 08:55:27 +02:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Api
|
|
|
|
|
{
|
2012-07-26 04:33:11 +02:00
|
|
|
|
[Export(typeof(BasePlugin))]
|
2012-07-24 16:54:34 +02:00
|
|
|
|
public class Plugin : BaseGenericPlugin<BasePluginConfiguration>
|
2012-07-12 08:55:27 +02:00
|
|
|
|
{
|
2012-07-24 16:54:34 +02:00
|
|
|
|
public override string Name
|
|
|
|
|
{
|
2012-09-04 19:43:09 +02:00
|
|
|
|
get { return "Media Browser API"; }
|
2012-07-24 16:54:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-09-06 16:18:54 +02:00
|
|
|
|
protected override void InitializeOnServer()
|
2012-07-12 08:55:27 +02:00
|
|
|
|
{
|
2012-07-13 05:50:50 +02:00
|
|
|
|
var httpServer = Kernel.Instance.HttpServer;
|
2012-07-12 08:55:27 +02:00
|
|
|
|
|
2012-08-22 04:50:59 +02:00
|
|
|
|
httpServer.Where(ctx => ctx.Request.Url.LocalPath.IndexOf("/api/", StringComparison.OrdinalIgnoreCase) != -1).Subscribe((ctx) =>
|
2012-07-20 04:22:44 +02:00
|
|
|
|
{
|
|
|
|
|
BaseHandler handler = GetHandler(ctx);
|
2012-07-16 18:50:44 +02:00
|
|
|
|
|
2012-07-20 04:22:44 +02:00
|
|
|
|
if (handler != null)
|
|
|
|
|
{
|
2012-08-22 04:50:59 +02:00
|
|
|
|
handler.ProcessRequest(ctx);
|
2012-07-20 04:22:44 +02:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2012-07-12 08:55:27 +02:00
|
|
|
|
|
2012-08-10 15:07:58 +02:00
|
|
|
|
private BaseHandler GetHandler(HttpListenerContext ctx)
|
2012-07-20 04:22:44 +02:00
|
|
|
|
{
|
2012-08-10 15:07:58 +02:00
|
|
|
|
string localPath = ctx.Request.Url.LocalPath;
|
2012-07-16 18:50:44 +02:00
|
|
|
|
|
2012-09-04 19:43:09 +02:00
|
|
|
|
if (IsUrlMatch("/api/item", localPath))
|
2012-07-20 04:22:44 +02:00
|
|
|
|
{
|
2012-08-10 15:07:58 +02:00
|
|
|
|
return new ItemHandler();
|
2012-07-20 04:22:44 +02:00
|
|
|
|
}
|
2012-09-04 19:43:09 +02:00
|
|
|
|
else if (IsUrlMatch("/api/image", localPath))
|
2012-07-20 04:22:44 +02:00
|
|
|
|
{
|
2012-08-10 15:07:58 +02:00
|
|
|
|
return new ImageHandler();
|
2012-08-10 15:18:30 +02:00
|
|
|
|
}
|
2012-09-04 19:43:09 +02:00
|
|
|
|
else if (IsUrlMatch("/api/users", localPath))
|
2012-07-20 04:22:44 +02:00
|
|
|
|
{
|
2012-08-10 15:07:58 +02:00
|
|
|
|
return new UsersHandler();
|
2012-07-20 04:22:44 +02:00
|
|
|
|
}
|
2012-09-04 19:43:09 +02:00
|
|
|
|
else if (IsUrlMatch("/api/itemlist", localPath))
|
2012-07-20 04:22:44 +02:00
|
|
|
|
{
|
2012-08-17 18:47:35 +02:00
|
|
|
|
return new ItemListHandler();
|
2012-07-20 04:22:44 +02:00
|
|
|
|
}
|
2012-09-04 19:43:09 +02:00
|
|
|
|
else if (IsUrlMatch("/api/genres", localPath))
|
2012-07-20 04:22:44 +02:00
|
|
|
|
{
|
2012-08-10 15:07:58 +02:00
|
|
|
|
return new GenresHandler();
|
2012-07-20 04:22:44 +02:00
|
|
|
|
}
|
2012-09-04 19:43:09 +02:00
|
|
|
|
else if (IsUrlMatch("/api/years", localPath))
|
2012-08-14 18:06:46 +02:00
|
|
|
|
{
|
|
|
|
|
return new YearsHandler();
|
|
|
|
|
}
|
2012-09-04 19:43:09 +02:00
|
|
|
|
else if (IsUrlMatch("/api/studios", localPath))
|
2012-07-20 04:22:44 +02:00
|
|
|
|
{
|
2012-08-10 15:07:58 +02:00
|
|
|
|
return new StudiosHandler();
|
2012-07-20 04:22:44 +02:00
|
|
|
|
}
|
2012-09-04 19:43:09 +02:00
|
|
|
|
else if (IsUrlMatch("/api/plugins", localPath))
|
2012-07-24 16:54:34 +02:00
|
|
|
|
{
|
2012-08-10 15:07:58 +02:00
|
|
|
|
return new PluginsHandler();
|
2012-07-24 16:54:34 +02:00
|
|
|
|
}
|
2012-09-04 19:43:09 +02:00
|
|
|
|
else if (IsUrlMatch("/api/pluginconfiguration", localPath))
|
2012-07-24 16:54:34 +02:00
|
|
|
|
{
|
2012-08-10 15:07:58 +02:00
|
|
|
|
return new PluginConfigurationHandler();
|
2012-07-24 16:54:34 +02:00
|
|
|
|
}
|
2012-09-04 19:43:09 +02:00
|
|
|
|
else if (IsUrlMatch("/api/static", localPath))
|
2012-07-20 04:22:44 +02:00
|
|
|
|
{
|
2012-08-10 15:07:58 +02:00
|
|
|
|
return new StaticFileHandler();
|
2012-07-20 04:22:44 +02:00
|
|
|
|
}
|
2012-09-04 19:43:09 +02:00
|
|
|
|
else if (IsUrlMatch("/api/audio", localPath))
|
2012-08-10 15:18:30 +02:00
|
|
|
|
{
|
|
|
|
|
return new AudioHandler();
|
|
|
|
|
}
|
2012-09-04 19:43:09 +02:00
|
|
|
|
else if (IsUrlMatch("/api/video", localPath))
|
2012-08-11 20:07:07 +02:00
|
|
|
|
{
|
|
|
|
|
return new VideoHandler();
|
|
|
|
|
}
|
2012-09-04 19:43:09 +02:00
|
|
|
|
else if (IsUrlMatch("/api/person", localPath))
|
2012-08-18 18:27:34 +02:00
|
|
|
|
{
|
|
|
|
|
return new PersonHandler();
|
|
|
|
|
}
|
2012-09-04 19:43:09 +02:00
|
|
|
|
else if (IsUrlMatch("/api/genre", localPath))
|
2012-08-18 18:27:34 +02:00
|
|
|
|
{
|
|
|
|
|
return new GenreHandler();
|
|
|
|
|
}
|
2012-09-04 19:43:09 +02:00
|
|
|
|
else if (IsUrlMatch("/api/year", localPath))
|
2012-08-18 18:27:34 +02:00
|
|
|
|
{
|
|
|
|
|
return new YearHandler();
|
|
|
|
|
}
|
2012-09-04 19:43:09 +02:00
|
|
|
|
else if (IsUrlMatch("/api/studio", localPath))
|
2012-08-18 18:27:34 +02:00
|
|
|
|
{
|
|
|
|
|
return new StudioHandler();
|
|
|
|
|
}
|
2012-09-04 19:43:09 +02:00
|
|
|
|
else if (IsUrlMatch("/api/weather", localPath))
|
2012-09-02 07:30:25 +02:00
|
|
|
|
{
|
|
|
|
|
return new WeatherHandler();
|
|
|
|
|
}
|
2012-09-04 19:43:09 +02:00
|
|
|
|
else if (IsUrlMatch("/api/serverconfiguration", localPath))
|
2012-09-02 15:45:02 +02:00
|
|
|
|
{
|
|
|
|
|
return new ServerConfigurationHandler();
|
|
|
|
|
}
|
2012-09-04 19:43:09 +02:00
|
|
|
|
else if (IsUrlMatch("/api/defaultuser", localPath))
|
2012-09-02 16:56:36 +02:00
|
|
|
|
{
|
|
|
|
|
return new DefaultUserHandler();
|
|
|
|
|
}
|
2012-09-04 19:43:09 +02:00
|
|
|
|
else if (IsUrlMatch("/api/pluginassembly", localPath))
|
2012-09-03 21:12:02 +02:00
|
|
|
|
{
|
|
|
|
|
return new PluginAssemblyHandler();
|
|
|
|
|
}
|
2012-07-14 22:45:11 +02:00
|
|
|
|
|
2012-08-10 15:07:58 +02:00
|
|
|
|
return null;
|
2012-07-12 08:55:27 +02:00
|
|
|
|
}
|
2012-09-04 19:43:09 +02:00
|
|
|
|
|
|
|
|
|
private bool IsUrlMatch(string url, string localPath)
|
|
|
|
|
{
|
|
|
|
|
return localPath.EndsWith(url, StringComparison.OrdinalIgnoreCase);
|
|
|
|
|
}
|
2012-07-12 08:55:27 +02:00
|
|
|
|
}
|
|
|
|
|
}
|