2012-07-12 06:55:27 +00:00
|
|
|
|
using System;
|
2012-07-26 02:33:11 +00:00
|
|
|
|
using System.ComponentModel.Composition;
|
2012-08-10 13:07:58 +00:00
|
|
|
|
using System.Net;
|
2012-07-12 06:55:27 +00:00
|
|
|
|
using System.Reactive.Linq;
|
2012-07-13 03:50:50 +00:00
|
|
|
|
using MediaBrowser.Api.HttpHandlers;
|
2012-07-21 18:39:47 +00:00
|
|
|
|
using MediaBrowser.Common.Net.Handlers;
|
2012-07-12 06:55:27 +00:00
|
|
|
|
using MediaBrowser.Common.Plugins;
|
|
|
|
|
using MediaBrowser.Controller;
|
2012-07-24 14:54:34 +00:00
|
|
|
|
using MediaBrowser.Model.Plugins;
|
2012-07-12 06:55:27 +00:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Api
|
|
|
|
|
{
|
2012-07-26 02:33:11 +00:00
|
|
|
|
[Export(typeof(BasePlugin))]
|
2012-07-24 14:54:34 +00:00
|
|
|
|
public class Plugin : BaseGenericPlugin<BasePluginConfiguration>
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
2012-07-24 14:54:34 +00:00
|
|
|
|
public override string Name
|
|
|
|
|
{
|
|
|
|
|
get { return "WebAPI"; }
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-29 15:19:25 +00:00
|
|
|
|
public override void Init()
|
2012-07-12 06:55:27 +00:00
|
|
|
|
{
|
2012-07-13 03:50:50 +00:00
|
|
|
|
var httpServer = Kernel.Instance.HttpServer;
|
2012-07-12 06:55:27 +00:00
|
|
|
|
|
2012-08-10 13:07:58 +00:00
|
|
|
|
httpServer.Where(ctx => ctx.Request.Url.LocalPath.IndexOf("/api/", StringComparison.OrdinalIgnoreCase) != -1).Subscribe(ctx =>
|
2012-07-20 02:22:44 +00:00
|
|
|
|
{
|
|
|
|
|
BaseHandler handler = GetHandler(ctx);
|
2012-07-16 16:50:44 +00:00
|
|
|
|
|
2012-07-20 02:22:44 +00:00
|
|
|
|
if (handler != null)
|
|
|
|
|
{
|
2012-08-10 13:07:58 +00:00
|
|
|
|
handler.ProcessRequest(ctx);
|
2012-07-20 02:22:44 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2012-07-12 06:55:27 +00:00
|
|
|
|
|
2012-08-10 13:07:58 +00:00
|
|
|
|
private BaseHandler GetHandler(HttpListenerContext ctx)
|
2012-07-20 02:22:44 +00:00
|
|
|
|
{
|
2012-08-10 13:07:58 +00:00
|
|
|
|
string localPath = ctx.Request.Url.LocalPath;
|
2012-07-16 16:50:44 +00:00
|
|
|
|
|
2012-07-20 02:22:44 +00:00
|
|
|
|
if (localPath.EndsWith("/api/item", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2012-08-10 13:07:58 +00:00
|
|
|
|
return new ItemHandler();
|
2012-07-20 02:22:44 +00:00
|
|
|
|
}
|
|
|
|
|
else if (localPath.EndsWith("/api/image", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2012-08-10 13:07:58 +00:00
|
|
|
|
return new ImageHandler();
|
2012-08-10 13:18:30 +00:00
|
|
|
|
}
|
2012-07-20 02:22:44 +00:00
|
|
|
|
else if (localPath.EndsWith("/api/users", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2012-08-10 13:07:58 +00:00
|
|
|
|
return new UsersHandler();
|
2012-07-20 02:22:44 +00:00
|
|
|
|
}
|
2012-08-14 16:06:46 +00:00
|
|
|
|
else if (localPath.EndsWith("/api/itemswithgenre", StringComparison.OrdinalIgnoreCase))
|
2012-07-20 02:22:44 +00:00
|
|
|
|
{
|
2012-08-14 16:06:46 +00:00
|
|
|
|
return new ItemsWithGenreHandler();
|
2012-07-20 02:22:44 +00:00
|
|
|
|
}
|
|
|
|
|
else if (localPath.EndsWith("/api/genres", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2012-08-10 13:07:58 +00:00
|
|
|
|
return new GenresHandler();
|
2012-07-20 02:22:44 +00:00
|
|
|
|
}
|
2012-08-14 16:06:46 +00:00
|
|
|
|
else if (localPath.EndsWith("/api/itemswithyear", StringComparison.OrdinalIgnoreCase))
|
2012-07-20 02:22:44 +00:00
|
|
|
|
{
|
2012-08-14 16:06:46 +00:00
|
|
|
|
return new ItemsWithYearHandler();
|
|
|
|
|
}
|
2012-08-14 19:06:25 +00:00
|
|
|
|
else if (localPath.EndsWith("/api/itemswithperson", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return new ItemsWithPersonHandler();
|
|
|
|
|
}
|
2012-08-14 16:06:46 +00:00
|
|
|
|
else if (localPath.EndsWith("/api/years", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return new YearsHandler();
|
|
|
|
|
}
|
|
|
|
|
else if (localPath.EndsWith("/api/itemswithstudio", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return new ItemsWithStudioHandler();
|
2012-07-20 02:22:44 +00:00
|
|
|
|
}
|
|
|
|
|
else if (localPath.EndsWith("/api/studios", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2012-08-10 13:07:58 +00:00
|
|
|
|
return new StudiosHandler();
|
2012-07-20 02:22:44 +00:00
|
|
|
|
}
|
|
|
|
|
else if (localPath.EndsWith("/api/recentlyaddeditems", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2012-08-10 13:07:58 +00:00
|
|
|
|
return new RecentlyAddedItemsHandler();
|
2012-07-20 02:22:44 +00:00
|
|
|
|
}
|
|
|
|
|
else if (localPath.EndsWith("/api/inprogressitems", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2012-08-10 13:07:58 +00:00
|
|
|
|
return new InProgressItemsHandler();
|
2012-07-20 02:22:44 +00:00
|
|
|
|
}
|
2012-07-23 15:05:30 +00:00
|
|
|
|
else if (localPath.EndsWith("/api/userconfiguration", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2012-08-10 13:07:58 +00:00
|
|
|
|
return new UserConfigurationHandler();
|
2012-07-23 15:05:30 +00:00
|
|
|
|
}
|
2012-07-24 14:54:34 +00:00
|
|
|
|
else if (localPath.EndsWith("/api/plugins", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2012-08-10 13:07:58 +00:00
|
|
|
|
return new PluginsHandler();
|
2012-07-24 14:54:34 +00:00
|
|
|
|
}
|
|
|
|
|
else if (localPath.EndsWith("/api/pluginconfiguration", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2012-08-10 13:07:58 +00:00
|
|
|
|
return new PluginConfigurationHandler();
|
2012-07-24 14:54:34 +00:00
|
|
|
|
}
|
2012-08-10 13:07:58 +00:00
|
|
|
|
else if (localPath.EndsWith("/api/static", StringComparison.OrdinalIgnoreCase))
|
2012-07-20 02:22:44 +00:00
|
|
|
|
{
|
2012-08-10 13:07:58 +00:00
|
|
|
|
return new StaticFileHandler();
|
2012-07-20 02:22:44 +00:00
|
|
|
|
}
|
2012-08-10 13:18:30 +00:00
|
|
|
|
else if (localPath.EndsWith("/api/audio", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return new AudioHandler();
|
|
|
|
|
}
|
2012-08-11 18:07:07 +00:00
|
|
|
|
else if (localPath.EndsWith("/api/video", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return new VideoHandler();
|
|
|
|
|
}
|
2012-07-14 20:45:11 +00:00
|
|
|
|
|
2012-08-10 13:07:58 +00:00
|
|
|
|
return null;
|
2012-07-12 06:55:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|