aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Api
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Api')
-rw-r--r--MediaBrowser.Api/ApiService.cs438
-rw-r--r--MediaBrowser.Api/Drawing/DrawingUtils.cs81
-rw-r--r--MediaBrowser.Api/Drawing/ImageProcessor.cs148
-rw-r--r--MediaBrowser.Api/HttpHandlers/AudioHandler.cs119
-rw-r--r--MediaBrowser.Api/HttpHandlers/BaseMediaHandler.cs255
-rw-r--r--MediaBrowser.Api/HttpHandlers/FavoriteStatusHandler.cs38
-rw-r--r--MediaBrowser.Api/HttpHandlers/GenreHandler.cs57
-rw-r--r--MediaBrowser.Api/HttpHandlers/GenresHandler.cs78
-rw-r--r--MediaBrowser.Api/HttpHandlers/ImageHandler.cs224
-rw-r--r--MediaBrowser.Api/HttpHandlers/ItemHandler.cs35
-rw-r--r--MediaBrowser.Api/HttpHandlers/ItemListHandler.cs84
-rw-r--r--MediaBrowser.Api/HttpHandlers/MovieSpecialFeaturesHandler.cs46
-rw-r--r--MediaBrowser.Api/HttpHandlers/PersonHandler.cs55
-rw-r--r--MediaBrowser.Api/HttpHandlers/PlayedStatusHandler.cs38
-rw-r--r--MediaBrowser.Api/HttpHandlers/PluginAssemblyHandler.cs38
-rw-r--r--MediaBrowser.Api/HttpHandlers/PluginConfigurationHandler.cs53
-rw-r--r--MediaBrowser.Api/HttpHandlers/PluginsHandler.cs38
-rw-r--r--MediaBrowser.Api/HttpHandlers/ServerConfigurationHandler.cs37
-rw-r--r--MediaBrowser.Api/HttpHandlers/StudioHandler.cs57
-rw-r--r--MediaBrowser.Api/HttpHandlers/StudiosHandler.cs78
-rw-r--r--MediaBrowser.Api/HttpHandlers/UserAuthenticationHandler.cs29
-rw-r--r--MediaBrowser.Api/HttpHandlers/UserHandler.cs29
-rw-r--r--MediaBrowser.Api/HttpHandlers/UserItemRatingHandler.cs46
-rw-r--r--MediaBrowser.Api/HttpHandlers/UsersHandler.cs25
-rw-r--r--MediaBrowser.Api/HttpHandlers/VideoHandler.cs424
-rw-r--r--MediaBrowser.Api/HttpHandlers/WeatherHandler.cs43
-rw-r--r--MediaBrowser.Api/HttpHandlers/YearHandler.cs55
-rw-r--r--MediaBrowser.Api/HttpHandlers/YearsHandler.cs75
-rw-r--r--MediaBrowser.Api/MediaBrowser.Api.csproj117
-rw-r--r--MediaBrowser.Api/Plugin.cs14
-rw-r--r--MediaBrowser.Api/Properties/AssemblyInfo.cs35
-rw-r--r--MediaBrowser.Api/packages.config6
32 files changed, 2895 insertions, 0 deletions
diff --git a/MediaBrowser.Api/ApiService.cs b/MediaBrowser.Api/ApiService.cs
new file mode 100644
index 000000000..0fef1cb57
--- /dev/null
+++ b/MediaBrowser.Api/ApiService.cs
@@ -0,0 +1,438 @@
+using MediaBrowser.Controller;
+using MediaBrowser.Controller.Entities;
+using MediaBrowser.Controller.Entities.Movies;
+using MediaBrowser.Controller.Entities.TV;
+using MediaBrowser.Model.DTO;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net;
+using System.Threading.Tasks;
+
+namespace MediaBrowser.Api
+{
+ /// <summary>
+ /// Contains some helpers for the api
+ /// </summary>
+ public static class ApiService
+ {
+ /// <summary>
+ /// Gets an Item by Id, or the root item if none is supplied
+ /// </summary>
+ public static BaseItem GetItemById(string id)
+ {
+ Guid guid = string.IsNullOrEmpty(id) ? Guid.Empty : new Guid(id);
+
+ return Kernel.Instance.GetItemById(guid);
+ }
+
+ /// <summary>
+ /// Gets a User by Id
+ /// </summary>
+ /// <param name="logActivity">Whether or not to update the user's LastActivityDate</param>
+ public static User GetUserById(string id, bool logActivity)
+ {
+ var guid = new Guid(id);
+
+ var user = Kernel.Instance.Users.FirstOrDefault(u => u.Id == guid);
+
+ if (logActivity)
+ {
+ LogUserActivity(user);
+ }
+
+ return user;
+ }
+
+ /// <summary>
+ /// Gets the default User
+ /// </summary>
+ /// <param name="logActivity">Whether or not to update the user's LastActivityDate</param>
+ public static User GetDefaultUser(bool logActivity)
+ {
+ User user = Kernel.Instance.GetDefaultUser();
+
+ if (logActivity)
+ {
+ LogUserActivity(user);
+ }
+
+ return user;
+ }
+
+ /// <summary>
+ /// Updates LastActivityDate for a given User
+ /// </summary>
+ public static void LogUserActivity(User user)
+ {
+ user.LastActivityDate = DateTime.UtcNow;
+ Kernel.Instance.SaveUser(user);
+ }
+
+ /// <summary>
+ /// Converts a BaseItem to a DTOBaseItem
+ /// </summary>
+ public async static Task<DtoBaseItem> GetDtoBaseItem(BaseItem item, User user,
+ bool includeChildren = true,
+ bool includePeople = true)
+ {
+ var dto = new DtoBaseItem();
+
+ var tasks = new List<Task>();
+
+ tasks.Add(AttachStudios(dto, item));
+
+ if (includeChildren)
+ {
+ tasks.Add(AttachChildren(dto, item, user));
+ tasks.Add(AttachLocalTrailers(dto, item, user));
+ }
+
+ if (includePeople)
+ {
+ tasks.Add(AttachPeople(dto, item));
+ }
+
+ AttachBasicFields(dto, item, user);
+
+ // Make sure all the tasks we kicked off have completed.
+ if (tasks.Count > 0)
+ {
+ await Task.WhenAll(tasks).ConfigureAwait(false);
+ }
+
+ return dto;
+ }
+
+ /// <summary>
+ /// Sets simple property values on a DTOBaseItem
+ /// </summary>
+ private static void AttachBasicFields(DtoBaseItem dto, BaseItem item, User user)
+ {
+ dto.AspectRatio = item.AspectRatio;
+ dto.BackdropCount = item.BackdropImagePaths == null ? 0 : item.BackdropImagePaths.Count();
+ dto.DateCreated = item.DateCreated;
+ dto.DisplayMediaType = item.DisplayMediaType;
+
+ if (item.Genres != null)
+ {
+ dto.Genres = item.Genres.ToArray();
+ }
+
+ dto.HasArt = !string.IsNullOrEmpty(item.ArtImagePath);
+ dto.HasBanner = !string.IsNullOrEmpty(item.BannerImagePath);
+ dto.HasLogo = !string.IsNullOrEmpty(item.LogoImagePath);
+ dto.HasPrimaryImage = !string.IsNullOrEmpty(item.PrimaryImagePath);
+ dto.HasThumb = !string.IsNullOrEmpty(item.ThumbnailImagePath);
+ dto.Id = item.Id;
+ dto.IsNew = item.IsRecentlyAdded(user);
+ dto.IndexNumber = item.IndexNumber;
+ dto.IsFolder = item.IsFolder;
+ dto.Language = item.Language;
+ dto.LocalTrailerCount = item.LocalTrailers == null ? 0 : item.LocalTrailers.Count();
+ dto.Name = item.Name;
+ dto.OfficialRating = item.OfficialRating;
+ dto.Overview = item.Overview;
+
+ // If there are no backdrops, indicate what parent has them in case the Ui wants to allow inheritance
+ if (dto.BackdropCount == 0)
+ {
+ int backdropCount;
+ dto.ParentBackdropItemId = GetParentBackdropItemId(item, out backdropCount);
+ dto.ParentBackdropCount = backdropCount;
+ }
+
+ if (item.Parent != null)
+ {
+ dto.ParentId = item.Parent.Id;
+ }
+
+ dto.ParentIndexNumber = item.ParentIndexNumber;
+
+ // If there is no logo, indicate what parent has one in case the Ui wants to allow inheritance
+ if (!dto.HasLogo)
+ {
+ dto.ParentLogoItemId = GetParentLogoItemId(item);
+ }
+
+ dto.Path = item.Path;
+
+ dto.PremiereDate = item.PremiereDate;
+ dto.ProductionYear = item.ProductionYear;
+ dto.ProviderIds = item.ProviderIds;
+ dto.RunTimeTicks = item.RunTimeTicks;
+ dto.SortName = item.SortName;
+
+ if (item.Taglines != null)
+ {
+ dto.Taglines = item.Taglines.ToArray();
+ }
+
+ dto.TrailerUrl = item.TrailerUrl;
+ dto.Type = item.GetType().Name;
+ dto.CommunityRating = item.CommunityRating;
+
+ dto.UserData = GetDtoUserItemData(item.GetUserData(user, false));
+
+ var folder = item as Folder;
+
+ if (folder != null)
+ {
+ dto.SpecialCounts = folder.GetSpecialCounts(user);
+
+ dto.IsRoot = folder.IsRoot;
+ dto.IsVirtualFolder = folder.IsVirtualFolder;
+ }
+
+ // Add AudioInfo
+ var audio = item as Audio;
+
+ if (audio != null)
+ {
+ dto.AudioInfo = new AudioInfo
+ {
+ Album = audio.Album,
+ AlbumArtist = audio.AlbumArtist,
+ Artist = audio.Artist,
+ BitRate = audio.BitRate,
+ Channels = audio.Channels
+ };
+ }
+
+ // Add VideoInfo
+ var video = item as Video;
+
+ if (video != null)
+ {
+ dto.VideoInfo = new VideoInfo
+ {
+ Height = video.Height,
+ Width = video.Width,
+ Codec = video.Codec,
+ VideoType = video.VideoType,
+ ScanType = video.ScanType
+ };
+
+ if (video.AudioStreams != null)
+ {
+ dto.VideoInfo.AudioStreams = video.AudioStreams.ToArray();
+ }
+
+ if (video.Subtitles != null)
+ {
+ dto.VideoInfo.Subtitles = video.Subtitles.ToArray();
+ }
+ }
+
+ // Add SeriesInfo
+ var series = item as Series;
+
+ if (series != null)
+ {
+ DayOfWeek[] airDays = series.AirDays == null ? new DayOfWeek[] { } : series.AirDays.ToArray();
+
+ dto.SeriesInfo = new SeriesInfo
+ {
+ AirDays = airDays,
+ AirTime = series.AirTime,
+ Status = series.Status
+ };
+ }
+
+ // Add MovieInfo
+ var movie = item as Movie;
+
+ if (movie != null)
+ {
+ int specialFeatureCount = movie.SpecialFeatures == null ? 0 : movie.SpecialFeatures.Count();
+
+ dto.MovieInfo = new MovieInfo
+ {
+ SpecialFeatureCount = specialFeatureCount
+ };
+ }
+ }
+
+ /// <summary>
+ /// Attaches Studio DTO's to a DTOBaseItem
+ /// </summary>
+ private static async Task AttachStudios(DtoBaseItem dto, BaseItem item)
+ {
+ // Attach Studios by transforming them into BaseItemStudio (DTO)
+ if (item.Studios != null)
+ {
+ Studio[] entities = await Task.WhenAll(item.Studios.Select(c => Kernel.Instance.ItemController.GetStudio(c))).ConfigureAwait(false);
+
+ dto.Studios = new BaseItemStudio[entities.Length];
+
+ for (int i = 0; i < entities.Length; i++)
+ {
+ Studio entity = entities[i];
+ var baseItemStudio = new BaseItemStudio{};
+
+ baseItemStudio.Name = entity.Name;
+
+ baseItemStudio.HasImage = !string.IsNullOrEmpty(entity.PrimaryImagePath);
+
+ dto.Studios[i] = baseItemStudio;
+ }
+ }
+ }
+
+ /// <summary>
+ /// Attaches child DTO's to a DTOBaseItem
+ /// </summary>
+ private static async Task AttachChildren(DtoBaseItem dto, BaseItem item, User user)
+ {
+ var folder = item as Folder;
+
+ if (folder != null)
+ {
+ IEnumerable<BaseItem> children = folder.GetChildren(user);
+
+ dto.Children = await Task.WhenAll(children.Select(c => GetDtoBaseItem(c, user, false, false))).ConfigureAwait(false);
+ }
+ }
+
+ /// <summary>
+ /// Attaches trailer DTO's to a DTOBaseItem
+ /// </summary>
+ private static async Task AttachLocalTrailers(DtoBaseItem dto, BaseItem item, User user)
+ {
+ if (item.LocalTrailers != null && item.LocalTrailers.Any())
+ {
+ dto.LocalTrailers = await Task.WhenAll(item.LocalTrailers.Select(c => GetDtoBaseItem(c, user, false, false))).ConfigureAwait(false);
+ }
+ }
+
+ /// <summary>
+ /// Attaches People DTO's to a DTOBaseItem
+ /// </summary>
+ private static async Task AttachPeople(DtoBaseItem dto, BaseItem item)
+ {
+ // Attach People by transforming them into BaseItemPerson (DTO)
+ if (item.People != null)
+ {
+ IEnumerable<Person> entities = await Task.WhenAll(item.People.Select(c => Kernel.Instance.ItemController.GetPerson(c.Key))).ConfigureAwait(false);
+
+ dto.People = item.People.Select(p =>
+ {
+ var baseItemPerson = new BaseItemPerson{};
+
+ baseItemPerson.Name = p.Key;
+ baseItemPerson.Overview = p.Value.Overview;
+ baseItemPerson.Type = p.Value.Type;
+
+ Person ibnObject = entities.First(i => i.Name.Equals(p.Key, StringComparison.OrdinalIgnoreCase));
+
+ if (ibnObject != null)
+ {
+ baseItemPerson.HasImage = !string.IsNullOrEmpty(ibnObject.PrimaryImagePath);
+ }
+
+ return baseItemPerson;
+ }).ToArray();
+ }
+ }
+
+ /// <summary>
+ /// If an item does not any backdrops, this can be used to find the first parent that does have one
+ /// </summary>
+ private static Guid? GetParentBackdropItemId(BaseItem item, out int backdropCount)
+ {
+ backdropCount = 0;
+
+ var parent = item.Parent;
+
+ while (parent != null)
+ {
+ if (parent.BackdropImagePaths != null && parent.BackdropImagePaths.Any())
+ {
+ backdropCount = parent.BackdropImagePaths.Count();
+ return parent.Id;
+ }
+
+ parent = parent.Parent;
+ }
+
+ return null;
+ }
+
+ /// <summary>
+ /// If an item does not have a logo, this can be used to find the first parent that does have one
+ /// </summary>
+ private static Guid? GetParentLogoItemId(BaseItem item)
+ {
+ var parent = item.Parent;
+
+ while (parent != null)
+ {
+ if (!string.IsNullOrEmpty(parent.LogoImagePath))
+ {
+ return parent.Id;
+ }
+
+ parent = parent.Parent;
+ }
+
+ return null;
+ }
+
+ /// <summary>
+ /// Gets an ImagesByName entity along with the number of items containing it
+ /// </summary>
+ public static IbnItem GetIbnItem(BaseEntity entity, int itemCount)
+ {
+ return new IbnItem
+ {
+ Id = entity.Id,
+ BaseItemCount = itemCount,
+ HasImage = !string.IsNullOrEmpty(entity.PrimaryImagePath),
+ Name = entity.Name
+ };
+ }
+
+ /// <summary>
+ /// Converts a User to a DTOUser
+ /// </summary>
+ public static DtoUser GetDtoUser(User user)
+ {
+ return new DtoUser
+ {
+ Id = user.Id,
+ Name = user.Name,
+ HasImage = !string.IsNullOrEmpty(user.PrimaryImagePath),
+ HasPassword = !string.IsNullOrEmpty(user.Password),
+ LastActivityDate = user.LastActivityDate,
+ LastLoginDate = user.LastLoginDate
+ };
+ }
+
+ /// <summary>
+ /// Converts a UserItemData to a DTOUserItemData
+ /// </summary>
+ public static DtoUserItemData GetDtoUserItemData(UserItemData data)
+ {
+ if (data == null)
+ {
+ return null;
+ }
+
+ return new DtoUserItemData
+ {
+ IsFavorite = data.IsFavorite,
+ Likes = data.Likes,
+ PlaybackPositionTicks = data.PlaybackPositionTicks,
+ PlayCount = data.PlayCount,
+ Rating = data.Rating
+ };
+ }
+
+ public static bool IsApiUrlMatch(string url, HttpListenerRequest request)
+ {
+ url = "/api/" + url;
+
+ return request.Url.LocalPath.EndsWith(url, StringComparison.OrdinalIgnoreCase);
+ }
+ }
+}
diff --git a/MediaBrowser.Api/Drawing/DrawingUtils.cs b/MediaBrowser.Api/Drawing/DrawingUtils.cs
new file mode 100644
index 000000000..f76a74218
--- /dev/null
+++ b/MediaBrowser.Api/Drawing/DrawingUtils.cs
@@ -0,0 +1,81 @@
+using System;
+using System.Drawing;
+
+namespace MediaBrowser.Api.Drawing
+{
+ public static class DrawingUtils
+ {
+ /// <summary>
+ /// Resizes a set of dimensions
+ /// </summary>
+ public static Size Resize(int currentWidth, int currentHeight, int? width, int? height, int? maxWidth, int? maxHeight)
+ {
+ return Resize(new Size(currentWidth, currentHeight), width, height, maxWidth, maxHeight);
+ }
+
+ /// <summary>
+ /// Resizes a set of dimensions
+ /// </summary>
+ /// <param name="size">The original size object</param>
+ /// <param name="width">A new fixed width, if desired</param>
+ /// <param name="height">A new fixed neight, if desired</param>
+ /// <param name="maxWidth">A max fixed width, if desired</param>
+ /// <param name="maxHeight">A max fixed height, if desired</param>
+ /// <returns>A new size object</returns>
+ public static Size Resize(Size size, int? width, int? height, int? maxWidth, int? maxHeight)
+ {
+ decimal newWidth = size.Width;
+ decimal newHeight = size.Height;
+
+ if (width.HasValue && height.HasValue)
+ {
+ newWidth = width.Value;
+ newHeight = height.Value;
+ }
+
+ else if (height.HasValue)
+ {
+ newWidth = GetNewWidth(newHeight, newWidth, height.Value);
+ newHeight = height.Value;
+ }
+
+ else if (width.HasValue)
+ {
+ newHeight = GetNewHeight(newHeight, newWidth, width.Value);
+ newWidth = width.Value;
+ }
+
+ if (maxHeight.HasValue && maxHeight < newHeight)
+ {
+ newWidth = GetNewWidth(newHeight, newWidth, maxHeight.Value);
+ newHeight = maxHeight.Value;
+ }
+
+ if (maxWidth.HasValue && maxWidth < newWidth)
+ {
+ newHeight = GetNewHeight(newHeight, newWidth, maxWidth.Value);
+ newWidth = maxWidth.Value;
+ }
+
+ return new Size(Convert.ToInt32(newWidth), Convert.ToInt32(newHeight));
+ }
+
+ private static decimal GetNewWidth(decimal currentHeight, decimal currentWidth, int newHeight)
+ {
+ decimal scaleFactor = newHeight;
+ scaleFactor /= currentHeight;
+ scaleFactor *= currentWidth;
+
+ return scaleFactor;
+ }
+
+ private static decimal GetNewHeight(decimal currentHeight, decimal currentWidth, int newWidth)
+ {
+ decimal scaleFactor = newWidth;
+ scaleFactor /= currentWidth;
+ scaleFactor *= currentHeight;
+
+ return scaleFactor;
+ }
+ }
+}
diff --git a/MediaBrowser.Api/Drawing/ImageProcessor.cs b/MediaBrowser.Api/Drawing/ImageProcessor.cs
new file mode 100644
index 000000000..1a471acf5
--- /dev/null
+++ b/MediaBrowser.Api/Drawing/ImageProcessor.cs
@@ -0,0 +1,148 @@
+using MediaBrowser.Controller.Entities;
+using MediaBrowser.Model.Entities;
+using System;
+using System.Drawing;
+using System.Drawing.Drawing2D;
+using System.Drawing.Imaging;
+using System.IO;
+using System.Linq;
+
+namespace MediaBrowser.Api.Drawing
+{
+ public static class ImageProcessor
+ {
+ /// <summary>
+ /// Processes an image by resizing to target dimensions
+ /// </summary>
+ /// <param name="entity">The entity that owns the image</param>
+ /// <param name="imageType">The image type</param>
+ /// <param name="imageIndex">The image index (currently only used with backdrops)</param>
+ /// <param name="toStream">The stream to save the new image to</param>
+ /// <param name="width">Use if a fixed width is required. Aspect ratio will be preserved.</param>
+ /// <param name="height">Use if a fixed height is required. Aspect ratio will be preserved.</param>
+ /// <param name="maxWidth">Use if a max width is required. Aspect ratio will be preserved.</param>
+ /// <param name="maxHeight">Use if a max height is required. Aspect ratio will be preserved.</param>
+ /// <param name="quality">Quality level, from 0-100. Currently only applies to JPG. The default value should suffice.</param>
+ public static void ProcessImage(BaseEntity entity, ImageType imageType, int imageIndex, Stream toStream, int? width, int? height, int? maxWidth, int? maxHeight, int? quality)
+ {
+ Image originalImage = Image.FromFile(GetImagePath(entity, imageType, imageIndex));
+
+ // Determine the output size based on incoming parameters
+ Size newSize = DrawingUtils.Resize(originalImage.Size, width, height, maxWidth, maxHeight);
+
+ Bitmap thumbnail;
+
+ // Graphics.FromImage will throw an exception if the PixelFormat is Indexed, so we need to handle that here
+ if (originalImage.PixelFormat.HasFlag(PixelFormat.Indexed))
+ {
+ thumbnail = new Bitmap(originalImage, newSize.Width, newSize.Height);
+ }
+ else
+ {
+ thumbnail = new Bitmap(newSize.Width, newSize.Height, originalImage.PixelFormat);
+ }
+
+ thumbnail.MakeTransparent();
+
+ // Preserve the original resolution
+ thumbnail.SetResolution(originalImage.HorizontalResolution, originalImage.VerticalResolution);
+
+ Graphics thumbnailGraph = Graphics.FromImage(thumbnail);
+
+ thumbnailGraph.CompositingQuality = CompositingQuality.HighQuality;
+ thumbnailGraph.SmoothingMode = SmoothingMode.HighQuality;
+ thumbnailGraph.InterpolationMode = InterpolationMode.HighQualityBicubic;
+ thumbnailGraph.PixelOffsetMode = PixelOffsetMode.HighQuality;
+ thumbnailGraph.CompositingMode = CompositingMode.SourceOver;
+
+ thumbnailGraph.DrawImage(originalImage, 0, 0, newSize.Width, newSize.Height);
+
+ ImageFormat outputFormat = originalImage.RawFormat;
+
+ // Write to the output stream
+ SaveImage(outputFormat, thumbnail, toStream, quality);
+
+ thumbnailGraph.Dispose();
+ thumbnail.Dispose();
+ originalImage.Dispose();
+ }
+
+ public static string GetImagePath(BaseEntity entity, ImageType imageType, int imageIndex)
+ {
+ var item = entity as BaseItem;
+
+ if (item != null)
+ {
+ if (imageType == ImageType.Logo)
+ {
+ return item.LogoImagePath;
+ }
+ if (imageType == ImageType.Backdrop)
+ {
+ return item.BackdropImagePaths.ElementAt(imageIndex);
+ }
+ if (imageType == ImageType.Banner)
+ {
+ return item.BannerImagePath;
+ }
+ if (imageType == ImageType.Art)
+ {
+ return item.ArtImagePath;
+ }
+ if (imageType == ImageType.Thumbnail)
+ {
+ return item.ThumbnailImagePath;
+ }
+ }
+
+ return entity.PrimaryImagePath;
+ }
+
+ public static void SaveImage(ImageFormat outputFormat, Image newImage, Stream toStream, int? quality)
+ {
+ // Use special save methods for jpeg and png that will result in a much higher quality image
+ // All other formats use the generic Image.Save
+ if (ImageFormat.Jpeg.Equals(outputFormat))
+ {
+ SaveJpeg(newImage, toStream, quality);
+ }
+ else if (ImageFormat.Png.Equals(outputFormat))
+ {
+ newImage.Save(toStream, ImageFormat.Png);
+ }
+ else
+ {
+ newImage.Save(toStream, outputFormat);
+ }
+ }
+
+ public static void SaveJpeg(Image image, Stream target, int? quality)
+ {
+ if (!quality.HasValue)
+ {
+ quality = 90;
+ }
+
+ using (var encoderParameters = new EncoderParameters(1))
+ {
+ encoderParameters.Param[0] = new EncoderParameter(Encoder.Quality, quality.Value);
+ image.Save(target, GetImageCodecInfo("image/jpeg"), encoderParameters);
+ }
+ }
+
+ public static ImageCodecInfo GetImageCodecInfo(string mimeType)
+ {
+ ImageCodecInfo[] info = ImageCodecInfo.GetImageEncoders();
+
+ for (int i = 0; i < info.Length; i++)
+ {
+ ImageCodecInfo ici = info[i];
+ if (ici.MimeType.Equals(mimeType, StringComparison.OrdinalIgnoreCase))
+ {
+ return ici;
+ }
+ }
+ return info[1];
+ }
+ }
+}
diff --git a/MediaBrowser.Api/HttpHandlers/AudioHandler.cs b/MediaBrowser.Api/HttpHandlers/AudioHandler.cs
new file mode 100644
index 000000000..9c16acd2e
--- /dev/null
+++ b/MediaBrowser.Api/HttpHandlers/AudioHandler.cs
@@ -0,0 +1,119 @@
+using MediaBrowser.Common.Net.Handlers;
+using MediaBrowser.Controller.Entities;
+using MediaBrowser.Model.DTO;
+using System.Collections.Generic;
+using System.ComponentModel.Composition;
+using System.IO;
+using System.Net;
+
+namespace MediaBrowser.Api.HttpHandlers
+{
+ /// <summary>
+ /// Supported output formats are: mp3,flac,ogg,wav,asf,wma,aac
+ /// </summary>
+ [Export(typeof(BaseHandler))]
+ public class AudioHandler : BaseMediaHandler<Audio, AudioOutputFormats>
+ {
+ public override bool HandlesRequest(HttpListenerRequest request)
+ {
+ return ApiService.IsApiUrlMatch("audio", request);
+ }
+
+ /// <summary>
+ /// We can output these formats directly, but we cannot encode to them.
+ /// </summary>
+ protected override IEnumerable<AudioOutputFormats> UnsupportedOutputEncodingFormats
+ {
+ get
+ {
+ return new AudioOutputFormats[] { AudioOutputFormats.Aac, AudioOutputFormats.Flac, AudioOutputFormats.Wma };
+ }
+ }
+
+ private int? GetMaxAcceptedBitRate(AudioOutputFormats audioFormat)
+ {
+ return GetMaxAcceptedBitRate(audioFormat.ToString());
+ }
+
+ private int? GetMaxAcceptedBitRate(string audioFormat)
+ {
+ if (audioFormat.Equals("mp3", System.StringComparison.OrdinalIgnoreCase))
+ {
+ return 320000;
+ }
+
+ return null;
+ }
+
+ /// <summary>
+ /// Determines whether or not the original file requires transcoding
+ /// </summary>
+ protected override bool RequiresConversion()
+ {
+ if (base.RequiresConversion())
+ {
+ return true;
+ }
+
+ string currentFormat = Path.GetExtension(LibraryItem.Path).Replace(".", string.Empty);
+
+ int? bitrate = GetMaxAcceptedBitRate(currentFormat);
+
+ // If the bitrate is greater than our desired bitrate, we need to transcode
+ if (bitrate.HasValue && bitrate.Value < LibraryItem.BitRate)
+ {
+ return true;
+ }
+
+ // If the number of channels is greater than our desired channels, we need to transcode
+ if (AudioChannels.HasValue && AudioChannels.Value < LibraryItem.Channels)
+ {
+ return true;
+ }
+
+ // If the sample rate is greater than our desired sample rate, we need to transcode
+ if (AudioSampleRate.HasValue && AudioSampleRate.Value < LibraryItem.SampleRate)
+ {
+ return true;
+ }
+
+ // Yay
+ return false;
+ }
+
+ /// <summary>
+ /// Creates arguments to pass to ffmpeg
+ /// </summary>
+ protected override string GetCommandLineArguments()
+ {
+ var audioTranscodeParams = new List<string>();
+
+ AudioOutputFormats outputFormat = GetConversionOutputFormat();
+
+ int? bitrate = GetMaxAcceptedBitRate(outputFormat);
+
+ if (bitrate.HasValue)
+ {
+ audioTranscodeParams.Add("-ab " + bitrate.Value);
+ }
+
+ int? channels = GetNumAudioChannelsParam(LibraryItem.Channels);
+
+ if (channels.HasValue)
+ {
+ audioTranscodeParams.Add("-ac " + channels.Value);
+ }
+
+ int? sampleRate = GetSampleRateParam(LibraryItem.SampleRate);
+
+ if (sampleRate.HasValue)
+ {
+ audioTranscodeParams.Add("-ar " + sampleRate.Value);
+ }
+
+ audioTranscodeParams.Add("-f " + outputFormat);
+
+ return "-i \"" + LibraryItem.Path + "\" -vn " + string.Join(" ", audioTranscodeParams.ToArray()) + " -";
+ }
+ }
+}
diff --git a/MediaBrowser.Api/HttpHandlers/BaseMediaHandler.cs b/MediaBrowser.Api/HttpHandlers/BaseMediaHandler.cs
new file mode 100644
index 000000000..96ef60681
--- /dev/null
+++ b/MediaBrowser.Api/HttpHandlers/BaseMediaHandler.cs
@@ -0,0 +1,255 @@
+using MediaBrowser.Common.Logging;
+using MediaBrowser.Common.Net;
+using MediaBrowser.Common.Net.Handlers;
+using MediaBrowser.Controller;
+using MediaBrowser.Controller.Entities;
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.IO;
+using System.Linq;
+using System.Net;
+using System.Threading.Tasks;
+
+namespace MediaBrowser.Api.HttpHandlers
+{
+ public abstract class BaseMediaHandler<TBaseItemType, TOutputType> : BaseHandler
+ where TBaseItemType : BaseItem, new()
+ {
+ /// <summary>
+ /// Supported values: mp3,flac,ogg,wav,asf,wma,aac
+ /// </summary>
+ protected virtual IEnumerable<TOutputType> OutputFormats
+ {
+ get
+ {
+ return QueryString["outputformats"].Split(',').Select(o => (TOutputType)Enum.Parse(typeof(TOutputType), o, true));
+ }
+ }
+
+ /// <summary>
+ /// These formats can be outputted directly but cannot be encoded to
+ /// </summary>
+ protected virtual IEnumerable<TOutputType> UnsupportedOutputEncodingFormats
+ {
+ get
+ {
+ return new TOutputType[] { };
+ }
+ }
+
+ private TBaseItemType _libraryItem;
+ /// <summary>
+ /// Gets the library item that will be played, if any
+ /// </summary>
+ protected TBaseItemType LibraryItem
+ {
+ get
+ {
+ if (_libraryItem == null)
+ {
+ string id = QueryString["id"];
+
+ if (!string.IsNullOrEmpty(id))
+ {
+ _libraryItem = Kernel.Instance.GetItemById(Guid.Parse(id)) as TBaseItemType;
+ }
+ }
+
+ return _libraryItem;
+ }
+ }
+
+ public int? AudioChannels
+ {
+ get
+ {
+ string val = QueryString["audiochannels"];
+
+ if (string.IsNullOrEmpty(val))
+ {
+ return null;
+ }
+
+ return int.Parse(val);
+ }
+ }
+
+ public int? AudioSampleRate
+ {
+ get
+ {
+ string val = QueryString["audiosamplerate"];
+
+ if (string.IsNullOrEmpty(val))
+ {
+ return 44100;
+ }
+
+ return int.Parse(val);
+ }
+ }
+
+ protected override Task<ResponseInfo> GetResponseInfo()
+ {
+ ResponseInfo info = new ResponseInfo
+ {
+ ContentType = MimeTypes.GetMimeType("." + GetConversionOutputFormat()),
+ CompressResponse = false
+ };
+
+ return Task.FromResult<ResponseInfo>(info);
+ }
+
+ public override Task ProcessRequest(HttpListenerContext ctx)
+ {
+ HttpListenerContext = ctx;
+
+ if (!RequiresConversion())
+ {
+ return new StaticFileHandler { Path = LibraryItem.Path }.ProcessRequest(ctx);
+ }
+
+ return base.ProcessRequest(ctx);
+ }
+
+ protected abstract string GetCommandLineArguments();
+
+ /// <summary>
+ /// Gets the format we'll be converting to
+ /// </summary>
+ protected virtual TOutputType GetConversionOutputFormat()
+ {
+ return OutputFormats.First(f => !UnsupportedOutputEncodingFormats.Any(s => s.ToString().Equals(f.ToString(), StringComparison.OrdinalIgnoreCase)));
+ }
+
+ protected virtual bool RequiresConversion()
+ {
+ string currentFormat = Path.GetExtension(LibraryItem.Path).Replace(".", string.Empty);
+
+ if (OutputFormats.Any(f => currentFormat.EndsWith(f.ToString(), StringComparison.OrdinalIgnoreCase)))
+ {
+ // We can output these files directly, but we can't encode them
+ if (UnsupportedOutputEncodingFormats.Any(f => currentFormat.EndsWith(f.ToString(), StringComparison.OrdinalIgnoreCase)))
+ {
+ return false;
+ }
+ }
+ else
+ {
+ // If it's not in a format the consumer accepts, return true
+ return true;
+ }
+
+ return false;
+ }
+
+ private FileStream LogFileStream { get; set; }
+
+ protected async override Task WriteResponseToOutputStream(Stream stream)
+ {
+ var startInfo = new ProcessStartInfo{};
+
+ startInfo.CreateNoWindow = true;
+
+ startInfo.UseShellExecute = false;
+
+ // Must consume both or ffmpeg may hang due to deadlocks. See comments below.
+ startInfo.RedirectStandardOutput = true;
+ startInfo.RedirectStandardError = true;
+
+ startInfo.FileName = Kernel.Instance.ApplicationPaths.FFMpegPath;
+ startInfo.WorkingDirectory = Kernel.Instance.ApplicationPaths.FFMpegDirectory;
+ startInfo.Arguments = GetCommandLineArguments();
+
+ Logger.LogInfo(startInfo.FileName + " " + startInfo.Arguments);
+
+ var process = new Process{};
+ process.StartInfo = startInfo;
+
+ // FFMpeg writes debug/error info to stderr. This is useful when debugging so let's put it in the log directory.
+ LogFileStream = new FileStream(Path.Combine(Kernel.Instance.ApplicationPaths.LogDirectoryPath, "ffmpeg-" + Guid.NewGuid().ToString() + ".txt"), FileMode.Create);
+
+ process.EnableRaisingEvents = true;
+
+ process.Exited += ProcessExited;
+
+ try
+ {
+ process.Start();
+
+ // MUST read both stdout and stderr asynchronously or a deadlock may occurr
+
+ // Kick off two tasks
+ Task mediaTask = process.StandardOutput.BaseStream.CopyToAsync(stream);
+ Task debugLogTask = process.StandardError.BaseStream.CopyToAsync(LogFileStream);
+
+ await mediaTask.ConfigureAwait(false);
+ //await debugLogTask.ConfigureAwait(false);
+ }
+ catch (Exception ex)
+ {
+ Logger.LogException(ex);
+
+ // Hate having to do this
+ try
+ {
+ process.Kill();
+ }
+ catch
+ {
+ }
+ }
+ }
+
+ void ProcessExited(object sender, EventArgs e)
+ {
+ if (LogFileStream != null)
+ {
+ LogFileStream.Dispose();
+ }
+
+ var process = sender as Process;
+
+ Logger.LogInfo("FFMpeg exited with code " + process.ExitCode);
+
+ process.Dispose();
+ }
+
+ /// <summary>
+ /// Gets the number of audio channels to specify on the command line
+ /// </summary>
+ protected int? GetNumAudioChannelsParam(int libraryItemChannels)
+ {
+ // If the user requested a max number of channels
+ if (AudioChannels.HasValue)
+ {
+ // Only specify the param if we're going to downmix
+ if (AudioChannels.Value < libraryItemChannels)
+ {
+ return AudioChannels.Value;
+ }
+ }
+
+ return null;
+ }
+
+ /// <summary>
+ /// Gets the number of audio channels to specify on the command line
+ /// </summary>
+ protected int? GetSampleRateParam(int libraryItemSampleRate)
+ {
+ // If the user requested a max value
+ if (AudioSampleRate.HasValue)
+ {
+ // Only specify the param if we're going to downmix
+ if (AudioSampleRate.Value < libraryItemSampleRate)
+ {
+ return AudioSampleRate.Value;
+ }
+ }
+
+ return null;
+ }
+ }
+}
diff --git a/MediaBrowser.Api/HttpHandlers/FavoriteStatusHandler.cs b/MediaBrowser.Api/HttpHandlers/FavoriteStatusHandler.cs
new file mode 100644
index 000000000..19c175d8b
--- /dev/null
+++ b/MediaBrowser.Api/HttpHandlers/FavoriteStatusHandler.cs
@@ -0,0 +1,38 @@
+using MediaBrowser.Common.Net.Handlers;
+using MediaBrowser.Controller.Entities;
+using MediaBrowser.Model.DTO;
+using System.ComponentModel.Composition;
+using System.Net;
+using System.Threading.Tasks;
+
+namespace MediaBrowser.Api.HttpHandlers
+{
+ /// <summary>
+ /// Provides a handler to set user favorite status for an item
+ /// </summary>
+ [Export(typeof(BaseHandler))]
+ public class FavoriteStatusHandler : BaseSerializationHandler<DtoUserItemData>
+ {
+ public override bool HandlesRequest(HttpListenerRequest request)
+ {
+ return ApiService.IsApiUrlMatch("FavoriteStatus", request);
+ }
+
+ protected override Task<DtoUserItemData> GetObjectToSerialize()
+ {
+ // Get the item
+ BaseItem item = ApiService.GetItemById(QueryString["id"]);
+
+ // Get the user
+ User user = ApiService.GetUserById(QueryString["userid"], true);
+
+ // Get the user data for this item
+ UserItemData data = item.GetUserData(user, true);
+
+ // Set favorite status
+ data.IsFavorite = QueryString["isfavorite"] == "1";
+
+ return Task.FromResult(ApiService.GetDtoUserItemData(data));
+ }
+ }
+} \ No newline at end of file
diff --git a/MediaBrowser.Api/HttpHandlers/GenreHandler.cs b/MediaBrowser.Api/HttpHandlers/GenreHandler.cs
new file mode 100644
index 000000000..7cca2aea7
--- /dev/null
+++ b/MediaBrowser.Api/HttpHandlers/GenreHandler.cs
@@ -0,0 +1,57 @@
+using MediaBrowser.Common.Net.Handlers;
+using MediaBrowser.Controller;
+using MediaBrowser.Controller.Entities;
+using MediaBrowser.Model.DTO;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.Composition;
+using System.Linq;
+using System.Net;
+using System.Threading.Tasks;
+
+namespace MediaBrowser.Api.HttpHandlers
+{
+ /// <summary>
+ /// Gets a single genre
+ /// </summary>
+ [Export(typeof(BaseHandler))]
+ public class GenreHandler : BaseSerializationHandler<IbnItem>
+ {
+ public override bool HandlesRequest(HttpListenerRequest request)
+ {
+ return ApiService.IsApiUrlMatch("genre", request);
+ }
+
+ protected override Task<IbnItem> GetObjectToSerialize()
+ {
+ var parent = ApiService.GetItemById(QueryString["id"]) as Folder;
+ var user = ApiService.GetUserById(QueryString["userid"], true);
+
+ string name = QueryString["name"];
+
+ return GetGenre(parent, user, name);
+ }
+
+ /// <summary>
+ /// Gets a Genre
+ /// </summary>
+ private async Task<IbnItem> GetGenre(Folder parent, User user, string name)
+ {
+ int count = 0;
+
+ // Get all the allowed recursive children
+ IEnumerable<BaseItem> allItems = parent.GetRecursiveChildren(user);
+
+ foreach (var item in allItems)
+ {
+ if (item.Genres != null && item.Genres.Any(s => s.Equals(name, StringComparison.OrdinalIgnoreCase)))
+ {
+ count++;
+ }
+ }
+
+ // Get the original entity so that we can also supply the PrimaryImagePath
+ return ApiService.GetIbnItem(await Kernel.Instance.ItemController.GetGenre(name).ConfigureAwait(false), count);
+ }
+ }
+}
diff --git a/MediaBrowser.Api/HttpHandlers/GenresHandler.cs b/MediaBrowser.Api/HttpHandlers/GenresHandler.cs
new file mode 100644
index 000000000..4c5a9f4b7
--- /dev/null
+++ b/MediaBrowser.Api/HttpHandlers/GenresHandler.cs
@@ -0,0 +1,78 @@
+using MediaBrowser.Common.Net.Handlers;
+using MediaBrowser.Controller;
+using MediaBrowser.Controller.Entities;
+using MediaBrowser.Model.DTO;
+using System.Collections.Generic;
+using System.ComponentModel.Composition;
+using System.Linq;
+using System.Net;
+using System.Threading.Tasks;
+
+namespace MediaBrowser.Api.HttpHandlers
+{
+ [Export(typeof(BaseHandler))]
+ public class GenresHandler : BaseSerializationHandler<IbnItem[]>
+ {
+ public override bool HandlesRequest(HttpListenerRequest request)
+ {
+ return ApiService.IsApiUrlMatch("genres", request);
+ }
+
+ protected override Task<IbnItem[]> GetObjectToSerialize()
+ {
+ var parent = ApiService.GetItemById(QueryString["id"]) as Folder;
+ User user = ApiService.GetUserById(QueryString["userid"], true);
+
+ return GetAllGenres(parent, user);
+ }
+
+ /// <summary>
+ /// Gets all genres from all recursive children of a folder
+ /// The CategoryInfo class is used to keep track of the number of times each genres appears
+ /// </summary>
+ private async Task<IbnItem[]> GetAllGenres(Folder parent, User user)
+ {
+ var data = new Dictionary<string, int>();
+
+ // Get all the allowed recursive children
+ IEnumerable<BaseItem> allItems = parent.GetRecursiveChildren(user);
+
+ foreach (var item in allItems)
+ {
+ // Add each genre from the item to the data dictionary
+ // If the genre already exists, increment the count
+ if (item.Genres == null)
+ {
+ continue;
+ }
+
+ foreach (string val in item.Genres)
+ {
+ if (!data.ContainsKey(val))
+ {
+ data.Add(val, 1);
+ }
+ else
+ {
+ data[val]++;
+ }
+ }
+ }
+
+ // Get the Genre objects
+ Genre[] entities = await Task.WhenAll(data.Keys.Select(key => Kernel.Instance.ItemController.GetGenre(key))).ConfigureAwait(false);
+
+ // Convert to an array of IBNItem
+ var items = new IbnItem[entities.Length];
+
+ for (int i = 0; i < entities.Length; i++)
+ {
+ Genre e = entities[i];
+
+ items[i] = ApiService.GetIbnItem(e, data[e.Name]);
+ }
+
+ return items;
+ }
+ }
+}
diff --git a/MediaBrowser.Api/HttpHandlers/ImageHandler.cs b/MediaBrowser.Api/HttpHandlers/ImageHandler.cs
new file mode 100644
index 000000000..4aa367fb7
--- /dev/null
+++ b/MediaBrowser.Api/HttpHandlers/ImageHandler.cs
@@ -0,0 +1,224 @@
+using MediaBrowser.Common.Net;
+using MediaBrowser.Common.Net.Handlers;
+using MediaBrowser.Controller;
+using MediaBrowser.Controller.Drawing;
+using MediaBrowser.Controller.Entities;
+using MediaBrowser.Model.Entities;
+using System;
+using System.ComponentModel.Composition;
+using System.IO;
+using System.Net;
+using System.Threading.Tasks;
+
+namespace MediaBrowser.Api.HttpHandlers
+{
+ [Export(typeof(BaseHandler))]
+ public class ImageHandler : BaseHandler
+ {
+ public override bool HandlesRequest(HttpListenerRequest request)
+ {
+ return ApiService.IsApiUrlMatch("image", request);
+ }
+
+ private string _imagePath;
+
+ private async Task<string> GetImagePath()
+ {
+ _imagePath = _imagePath ?? await DiscoverImagePath();
+
+ return _imagePath;
+ }
+
+ private BaseEntity _sourceEntity;
+
+ private async Task<BaseEntity> GetSourceEntity()
+ {
+ if (_sourceEntity == null)
+ {
+ if (!string.IsNullOrEmpty(QueryString["personname"]))
+ {
+ _sourceEntity =
+ await Kernel.Instance.ItemController.GetPerson(QueryString["personname"]).ConfigureAwait(false);
+ }
+
+ else if (!string.IsNullOrEmpty(QueryString["genre"]))
+ {
+ _sourceEntity =
+ await Kernel.Instance.ItemController.GetGenre(QueryString["genre"]).ConfigureAwait(false);
+ }
+
+ else if (!string.IsNullOrEmpty(QueryString["year"]))
+ {
+ _sourceEntity =
+ await
+ Kernel.Instance.ItemController.GetYear(int.Parse(QueryString["year"])).ConfigureAwait(false);
+ }
+
+ else if (!string.IsNullOrEmpty(QueryString["studio"]))
+ {
+ _sourceEntity =
+ await Kernel.Instance.ItemController.GetStudio(QueryString["studio"]).ConfigureAwait(false);
+ }
+
+ else if (!string.IsNullOrEmpty(QueryString["userid"]))
+ {
+ _sourceEntity = ApiService.GetUserById(QueryString["userid"], false);
+ }
+
+ else
+ {
+ _sourceEntity = ApiService.GetItemById(QueryString["id"]);
+ }
+ }
+
+ return _sourceEntity;
+ }
+
+ private async Task<string> DiscoverImagePath()
+ {
+ var entity = await GetSourceEntity().ConfigureAwait(false);
+
+ return ImageProcessor.GetImagePath(entity, ImageType, ImageIndex);
+ }
+
+ protected async override Task<ResponseInfo> GetResponseInfo()
+ {
+ string path = await GetImagePath().ConfigureAwait(false);
+
+ ResponseInfo info = new ResponseInfo
+ {
+ CacheDuration = TimeSpan.FromDays(365),
+ ContentType = MimeTypes.GetMimeType(path)
+ };
+
+ DateTime? date = File.GetLastWriteTimeUtc(path);
+
+ // If the file does not exist it will return jan 1, 1601
+ // http://msdn.microsoft.com/en-us/library/system.io.file.getlastwritetimeutc.aspx
+ if (date.Value.Year == 1601)
+ {
+ if (!File.Exists(path))
+ {
+ info.StatusCode = 404;
+ date = null;
+ }
+ }
+
+ info.DateLastModified = date;
+
+ return info;
+ }
+
+ private int ImageIndex
+ {
+ get
+ {
+ string val = QueryString["index"];
+
+ if (string.IsNullOrEmpty(val))
+ {
+ return 0;
+ }
+
+ return int.Parse(val);
+ }
+ }
+
+ private int? Height
+ {
+ get
+ {
+ string val = QueryString["height"];
+
+ if (string.IsNullOrEmpty(val))
+ {
+ return null;
+ }
+
+ return int.Parse(val);
+ }
+ }
+
+ private int? Width
+ {
+ get
+ {
+ string val = QueryString["width"];
+
+ if (string.IsNullOrEmpty(val))
+ {
+ return null;
+ }
+
+ return int.Parse(val);
+ }
+ }
+
+ private int? MaxHeight
+ {
+ get
+ {
+ string val = QueryString["maxheight"];
+
+ if (string.IsNullOrEmpty(val))
+ {
+ return null;
+ }
+
+ return int.Parse(val);
+ }
+ }
+
+ private int? MaxWidth
+ {
+ get
+ {
+ string val = QueryString["maxwidth"];
+
+ if (string.IsNullOrEmpty(val))
+ {
+ return null;
+ }
+
+ return int.Parse(val);
+ }
+ }
+
+ private int? Quality
+ {
+ get
+ {
+ string val = QueryString["quality"];
+
+ if (string.IsNullOrEmpty(val))
+ {
+ return null;
+ }
+
+ return int.Parse(val);
+ }
+ }
+
+ private ImageType ImageType
+ {
+ get
+ {
+ string imageType = QueryString["type"];
+
+ if (string.IsNullOrEmpty(imageType))
+ {
+ return ImageType.Primary;
+ }
+
+ return (ImageType)Enum.Parse(typeof(ImageType), imageType, true);
+ }
+ }
+
+ protected override async Task WriteResponseToOutputStream(Stream stream)
+ {
+ var entity = await GetSourceEntity().ConfigureAwait(false);
+
+ ImageProcessor.ProcessImage(entity, ImageType, ImageIndex, stream, Width, Height, MaxWidth, MaxHeight, Quality);
+ }
+ }
+}
diff --git a/MediaBrowser.Api/HttpHandlers/ItemHandler.cs b/MediaBrowser.Api/HttpHandlers/ItemHandler.cs
new file mode 100644
index 000000000..60b328d1a
--- /dev/null
+++ b/MediaBrowser.Api/HttpHandlers/ItemHandler.cs
@@ -0,0 +1,35 @@
+using MediaBrowser.Common.Net.Handlers;
+using MediaBrowser.Controller.Entities;
+using MediaBrowser.Model.DTO;
+using System.ComponentModel.Composition;
+using System.Net;
+using System.Threading.Tasks;
+
+namespace MediaBrowser.Api.HttpHandlers
+{
+ /// <summary>
+ /// Provides a handler to retrieve a single item
+ /// </summary>
+ [Export(typeof(BaseHandler))]
+ public class ItemHandler : BaseSerializationHandler<DtoBaseItem>
+ {
+ public override bool HandlesRequest(HttpListenerRequest request)
+ {
+ return ApiService.IsApiUrlMatch("item", request);
+ }
+
+ protected override Task<DtoBaseItem> GetObjectToSerialize()
+ {
+ User user = ApiService.GetUserById(QueryString["userid"], true);
+
+ BaseItem item = ApiService.GetItemById(QueryString["id"]);
+
+ if (item == null)
+ {
+ return null;
+ }
+
+ return ApiService.GetDtoBaseItem(item, user);
+ }
+ }
+}
diff --git a/MediaBrowser.Api/HttpHandlers/ItemListHandler.cs b/MediaBrowser.Api/HttpHandlers/ItemListHandler.cs
new file mode 100644
index 000000000..d236e546b
--- /dev/null
+++ b/MediaBrowser.Api/HttpHandlers/ItemListHandler.cs
@@ -0,0 +1,84 @@
+using MediaBrowser.Common.Net.Handlers;
+using MediaBrowser.Controller.Entities;
+using MediaBrowser.Model.DTO;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.Composition;
+using System.Linq;
+using System.Net;
+using System.Threading.Tasks;
+
+namespace MediaBrowser.Api.HttpHandlers
+{
+ [Export(typeof(BaseHandler))]
+ public class ItemListHandler : BaseSerializationHandler<DtoBaseItem[]>
+ {
+ public override bool HandlesRequest(HttpListenerRequest request)
+ {
+ return ApiService.IsApiUrlMatch("itemlist", request);
+ }
+
+ protected override Task<DtoBaseItem[]> GetObjectToSerialize()
+ {
+ User user = ApiService.GetUserById(QueryString["userid"], true);
+
+ return Task.WhenAll(GetItemsToSerialize(user).Select(i => ApiService.GetDtoBaseItem(i, user, includeChildren: false, includePeople: false)));
+ }
+
+ private IEnumerable<BaseItem> GetItemsToSerialize(User user)
+ {
+ var parent = ApiService.GetItemById(ItemId) as Folder;
+
+ if (ListType.Equals("inprogressitems", StringComparison.OrdinalIgnoreCase))
+ {
+ return parent.GetInProgressItems(user);
+ }
+ if (ListType.Equals("recentlyaddeditems", StringComparison.OrdinalIgnoreCase))
+ {
+ return parent.GetRecentlyAddedItems(user);
+ }
+ if (ListType.Equals("recentlyaddedunplayeditems", StringComparison.OrdinalIgnoreCase))
+ {
+ return parent.GetRecentlyAddedUnplayedItems(user);
+ }
+ if (ListType.Equals("itemswithgenre", StringComparison.OrdinalIgnoreCase))
+ {
+ return parent.GetItemsWithGenre(QueryString["name"], user);
+ }
+ if (ListType.Equals("itemswithyear", StringComparison.OrdinalIgnoreCase))
+ {
+ return parent.GetItemsWithYear(int.Parse(QueryString["year"]), user);
+ }
+ if (ListType.Equals("itemswithstudio", StringComparison.OrdinalIgnoreCase))
+ {
+ return parent.GetItemsWithStudio(QueryString["name"], user);
+ }
+ if (ListType.Equals("itemswithperson", StringComparison.OrdinalIgnoreCase))
+ {
+ return parent.GetItemsWithPerson(QueryString["name"], null, user);
+ }
+ if (ListType.Equals("favorites", StringComparison.OrdinalIgnoreCase))
+ {
+ return parent.GetFavoriteItems(user);
+ }
+
+ throw new InvalidOperationException();
+ }
+
+ protected string ItemId
+ {
+ get
+ {
+ return QueryString["id"];
+ }
+ }
+
+ private string ListType
+ {
+ get
+ {
+ return QueryString["listtype"] ?? string.Empty;
+ }
+ }
+ }
+}
diff --git a/MediaBrowser.Api/HttpHandlers/MovieSpecialFeaturesHandler.cs b/MediaBrowser.Api/HttpHandlers/MovieSpecialFeaturesHandler.cs
new file mode 100644
index 000000000..3ab78ee8d
--- /dev/null
+++ b/MediaBrowser.Api/HttpHandlers/MovieSpecialFeaturesHandler.cs
@@ -0,0 +1,46 @@
+using MediaBrowser.Common.Net.Handlers;
+using MediaBrowser.Controller.Entities;
+using MediaBrowser.Controller.Entities.Movies;
+using MediaBrowser.Model.DTO;
+using System.ComponentModel.Composition;
+using System.Linq;
+using System.Net;
+using System.Threading.Tasks;
+
+namespace MediaBrowser.Api.HttpHandlers
+{
+ /// <summary>
+ /// This handler retrieves special features for movies
+ /// </summary>
+ [Export(typeof(BaseHandler))]
+ public class MovieSpecialFeaturesHandler : BaseSerializationHandler<DtoBaseItem[]>
+ {
+ public override bool HandlesRequest(HttpListenerRequest request)
+ {
+ return ApiService.IsApiUrlMatch("MovieSpecialFeatures", request);
+ }
+
+ protected override Task<DtoBaseItem[]> GetObjectToSerialize()
+ {
+ User user = ApiService.GetUserById(QueryString["userid"], true);
+
+ var movie = ApiService.GetItemById(ItemId) as Movie;
+
+ // If none
+ if (movie.SpecialFeatures == null)
+ {
+ return Task.FromResult(new DtoBaseItem[] { });
+ }
+
+ return Task.WhenAll(movie.SpecialFeatures.Select(i => ApiService.GetDtoBaseItem(i, user, includeChildren: false)));
+ }
+
+ protected string ItemId
+ {
+ get
+ {
+ return QueryString["id"];
+ }
+ }
+ }
+}
diff --git a/MediaBrowser.Api/HttpHandlers/PersonHandler.cs b/MediaBrowser.Api/HttpHandlers/PersonHandler.cs
new file mode 100644
index 000000000..fbbd88a11
--- /dev/null
+++ b/MediaBrowser.Api/HttpHandlers/PersonHandler.cs
@@ -0,0 +1,55 @@
+using MediaBrowser.Common.Net.Handlers;
+using MediaBrowser.Controller;
+using MediaBrowser.Controller.Entities;
+using MediaBrowser.Model.DTO;
+using System.Collections.Generic;
+using System.ComponentModel.Composition;
+using System.Net;
+using System.Threading.Tasks;
+
+namespace MediaBrowser.Api.HttpHandlers
+{
+ /// <summary>
+ /// Gets a single Person
+ /// </summary>
+ [Export(typeof(BaseHandler))]
+ public class PersonHandler : BaseSerializationHandler<IbnItem>
+ {
+ public override bool HandlesRequest(HttpListenerRequest request)
+ {
+ return ApiService.IsApiUrlMatch("person", request);
+ }
+
+ protected override Task<IbnItem> GetObjectToSerialize()
+ {
+ var parent = ApiService.GetItemById(QueryString["id"]) as Folder;
+ var user = ApiService.GetUserById(QueryString["userid"], true);
+
+ string name = QueryString["name"];
+
+ return GetPerson(parent, user, name);
+ }
+
+ /// <summary>
+ /// Gets a Person
+ /// </summary>
+ private async Task<IbnItem> GetPerson(Folder parent, User user, string name)
+ {
+ int count = 0;
+
+ // Get all the allowed recursive children
+ IEnumerable<BaseItem> allItems = parent.GetRecursiveChildren(user);
+
+ foreach (var item in allItems)
+ {
+ if (item.People != null && item.People.ContainsKey(name))
+ {
+ count++;
+ }
+ }
+
+ // Get the original entity so that we can also supply the PrimaryImagePath
+ return ApiService.GetIbnItem(await Kernel.Instance.ItemController.GetPerson(name).ConfigureAwait(false), count);
+ }
+ }
+}
diff --git a/MediaBrowser.Api/HttpHandlers/PlayedStatusHandler.cs b/MediaBrowser.Api/HttpHandlers/PlayedStatusHandler.cs
new file mode 100644
index 000000000..c010bcb02
--- /dev/null
+++ b/MediaBrowser.Api/HttpHandlers/PlayedStatusHandler.cs
@@ -0,0 +1,38 @@
+using MediaBrowser.Common.Net.Handlers;
+using MediaBrowser.Controller.Entities;
+using MediaBrowser.Model.DTO;
+using System.ComponentModel.Composition;
+using System.Net;
+using System.Threading.Tasks;
+
+namespace MediaBrowser.Api.HttpHandlers
+{
+ /// <summary>
+ /// Provides a handler to set played status for an item
+ /// </summary>
+ [Export(typeof(BaseHandler))]
+ public class PlayedStatusHandler : BaseSerializationHandler<DtoUserItemData>
+ {
+ public override bool HandlesRequest(HttpListenerRequest request)
+ {
+ return ApiService.IsApiUrlMatch("PlayedStatus", request);
+ }
+
+ protected override Task<DtoUserItemData> GetObjectToSerialize()
+ {
+ // Get the item
+ BaseItem item = ApiService.GetItemById(QueryString["id"]);
+
+ // Get the user
+ User user = ApiService.GetUserById(QueryString["userid"], true);
+
+ bool wasPlayed = QueryString["played"] == "1";
+
+ item.SetPlayedStatus(user, wasPlayed);
+
+ UserItemData data = item.GetUserData(user, true);
+
+ return Task.FromResult(ApiService.GetDtoUserItemData(data));
+ }
+ }
+} \ No newline at end of file
diff --git a/MediaBrowser.Api/HttpHandlers/PluginAssemblyHandler.cs b/MediaBrowser.Api/HttpHandlers/PluginAssemblyHandler.cs
new file mode 100644
index 000000000..47f08c8c3
--- /dev/null
+++ b/MediaBrowser.Api/HttpHandlers/PluginAssemblyHandler.cs
@@ -0,0 +1,38 @@
+using MediaBrowser.Common.Net.Handlers;
+using MediaBrowser.Controller;
+using System;
+using System.ComponentModel.Composition;
+using System.IO;
+using System.Net;
+using System.Threading.Tasks;
+
+namespace MediaBrowser.Api.HttpHandlers
+{
+ [Export(typeof(BaseHandler))]
+ class PluginAssemblyHandler : BaseHandler
+ {
+ public override bool HandlesRequest(HttpListenerRequest request)
+ {
+ return ApiService.IsApiUrlMatch("pluginassembly", request);
+ }
+
+ protected override Task<ResponseInfo> GetResponseInfo()
+ {
+ throw new NotImplementedException();
+ }
+
+ protected override Task WriteResponseToOutputStream(Stream stream)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override Task ProcessRequest(HttpListenerContext ctx)
+ {
+ string filename = ctx.Request.QueryString["assemblyfilename"];
+
+ string path = Path.Combine(Kernel.Instance.ApplicationPaths.PluginsPath, filename);
+
+ return new StaticFileHandler { Path = path }.ProcessRequest(ctx);
+ }
+ }
+}
diff --git a/MediaBrowser.Api/HttpHandlers/PluginConfigurationHandler.cs b/MediaBrowser.Api/HttpHandlers/PluginConfigurationHandler.cs
new file mode 100644
index 000000000..dc363956f
--- /dev/null
+++ b/MediaBrowser.Api/HttpHandlers/PluginConfigurationHandler.cs
@@ -0,0 +1,53 @@
+using MediaBrowser.Common.Net.Handlers;
+using MediaBrowser.Common.Plugins;
+using MediaBrowser.Controller;
+using MediaBrowser.Model.Plugins;
+using System;
+using System.ComponentModel.Composition;
+using System.Linq;
+using System.Net;
+using System.Threading.Tasks;
+
+namespace MediaBrowser.Api.HttpHandlers
+{
+ [Export(typeof(BaseHandler))]
+ public class PluginConfigurationHandler : BaseSerializationHandler<BasePluginConfiguration>
+ {
+ public override bool HandlesRequest(HttpListenerRequest request)
+ {
+ return ApiService.IsApiUrlMatch("pluginconfiguration", request);
+ }
+
+ private BasePlugin _plugin;
+ private BasePlugin Plugin
+ {
+ get
+ {
+ if (_plugin == null)
+ {
+ string name = QueryString["assemblyfilename"];
+
+ _plugin = Kernel.Instance.Plugins.First(p => p.AssemblyFileName.Equals(name, StringComparison.OrdinalIgnoreCase));
+ }
+
+ return _plugin;
+ }
+ }
+
+ protected override Task<BasePluginConfiguration> GetObjectToSerialize()
+ {
+ return Task.FromResult(Plugin.Configuration);
+ }
+
+ protected override async Task<ResponseInfo> GetResponseInfo()
+ {
+ var info = await base.GetResponseInfo().ConfigureAwait(false);
+
+ info.DateLastModified = Plugin.ConfigurationDateLastModified;
+
+ info.CacheDuration = TimeSpan.FromDays(7);
+
+ return info;
+ }
+ }
+}
diff --git a/MediaBrowser.Api/HttpHandlers/PluginsHandler.cs b/MediaBrowser.Api/HttpHandlers/PluginsHandler.cs
new file mode 100644
index 000000000..a1b37ecab
--- /dev/null
+++ b/MediaBrowser.Api/HttpHandlers/PluginsHandler.cs
@@ -0,0 +1,38 @@
+using MediaBrowser.Common.Net.Handlers;
+using MediaBrowser.Controller;
+using MediaBrowser.Model.DTO;
+using System.Collections.Generic;
+using System.ComponentModel.Composition;
+using System.Linq;
+using System.Net;
+using System.Threading.Tasks;
+
+namespace MediaBrowser.Api.HttpHandlers
+{
+ /// <summary>
+ /// Provides information about installed plugins
+ /// </summary>
+ [Export(typeof(BaseHandler))]
+ public class PluginsHandler : BaseSerializationHandler<IEnumerable<PluginInfo>>
+ {
+ public override bool HandlesRequest(HttpListenerRequest request)
+ {
+ return ApiService.IsApiUrlMatch("plugins", request);
+ }
+
+ protected override Task<IEnumerable<PluginInfo>> GetObjectToSerialize()
+ {
+ var plugins = Kernel.Instance.Plugins.Select(p => new PluginInfo
+ {
+ Name = p.Name,
+ Enabled = p.Enabled,
+ DownloadToUI = p.DownloadToUi,
+ Version = p.Version.ToString(),
+ AssemblyFileName = p.AssemblyFileName,
+ ConfigurationDateLastModified = p.ConfigurationDateLastModified
+ });
+
+ return Task.FromResult(plugins);
+ }
+ }
+}
diff --git a/MediaBrowser.Api/HttpHandlers/ServerConfigurationHandler.cs b/MediaBrowser.Api/HttpHandlers/ServerConfigurationHandler.cs
new file mode 100644
index 000000000..48c6761b1
--- /dev/null
+++ b/MediaBrowser.Api/HttpHandlers/ServerConfigurationHandler.cs
@@ -0,0 +1,37 @@
+using MediaBrowser.Common.Net.Handlers;
+using MediaBrowser.Controller;
+using MediaBrowser.Model.Configuration;
+using System;
+using System.ComponentModel.Composition;
+using System.IO;
+using System.Net;
+using System.Threading.Tasks;
+
+namespace MediaBrowser.Api.HttpHandlers
+{
+ [Export(typeof(BaseHandler))]
+ class ServerConfigurationHandler : BaseSerializationHandler<ServerConfiguration>
+ {
+ public override bool HandlesRequest(HttpListenerRequest request)
+ {
+ return ApiService.IsApiUrlMatch("serverconfiguration", request);
+ }
+
+ protected override Task<ServerConfiguration> GetObjectToSerialize()
+ {
+ return Task.FromResult(Kernel.Instance.Configuration);
+ }
+
+ protected override async Task<ResponseInfo> GetResponseInfo()
+ {
+ var info = await base.GetResponseInfo().ConfigureAwait(false);
+
+ info.DateLastModified =
+ File.GetLastWriteTimeUtc(Kernel.Instance.ApplicationPaths.SystemConfigurationFilePath);
+
+ info.CacheDuration = TimeSpan.FromDays(7);
+
+ return info;
+ }
+ }
+}
diff --git a/MediaBrowser.Api/HttpHandlers/StudioHandler.cs b/MediaBrowser.Api/HttpHandlers/StudioHandler.cs
new file mode 100644
index 000000000..6576e2cfe
--- /dev/null
+++ b/MediaBrowser.Api/HttpHandlers/StudioHandler.cs
@@ -0,0 +1,57 @@
+using MediaBrowser.Common.Net.Handlers;
+using MediaBrowser.Controller;
+using MediaBrowser.Controller.Entities;
+using MediaBrowser.Model.DTO;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.Composition;
+using System.Linq;
+using System.Net;
+using System.Threading.Tasks;
+
+namespace MediaBrowser.Api.HttpHandlers
+{
+ /// <summary>
+ /// Gets a single studio
+ /// </summary>
+ [Export(typeof(BaseHandler))]
+ public class StudioHandler : BaseSerializationHandler<IbnItem>
+ {
+ public override bool HandlesRequest(HttpListenerRequest request)
+ {
+ return ApiService.IsApiUrlMatch("studio", request);
+ }
+
+ protected override Task<IbnItem> GetObjectToSerialize()
+ {
+ var parent = ApiService.GetItemById(QueryString["id"]) as Folder;
+ var user = ApiService.GetUserById(QueryString["userid"], true);
+
+ string name = QueryString["name"];
+
+ return GetStudio(parent, user, name);
+ }
+
+ /// <summary>
+ /// Gets a Studio
+ /// </summary>
+ private async Task<IbnItem> GetStudio(Folder parent, User user, string name)
+ {
+ int count = 0;
+
+ // Get all the allowed recursive children
+ IEnumerable<BaseItem> allItems = parent.GetRecursiveChildren(user);
+
+ foreach (var item in allItems)
+ {
+ if (item.Studios != null && item.Studios.Any(s => s.Equals(name, StringComparison.OrdinalIgnoreCase)))
+ {
+ count++;
+ }
+ }
+
+ // Get the original entity so that we can also supply the PrimaryImagePath
+ return ApiService.GetIbnItem(await Kernel.Instance.ItemController.GetStudio(name).ConfigureAwait(false), count);
+ }
+ }
+}
diff --git a/MediaBrowser.Api/HttpHandlers/StudiosHandler.cs b/MediaBrowser.Api/HttpHandlers/StudiosHandler.cs
new file mode 100644
index 000000000..4377a0f43
--- /dev/null
+++ b/MediaBrowser.Api/HttpHandlers/StudiosHandler.cs
@@ -0,0 +1,78 @@
+using MediaBrowser.Common.Net.Handlers;
+using MediaBrowser.Controller;
+using MediaBrowser.Controller.Entities;
+using MediaBrowser.Model.DTO;
+using System.Collections.Generic;
+using System.ComponentModel.Composition;
+using System.Linq;
+using System.Net;
+using System.Threading.Tasks;
+
+namespace MediaBrowser.Api.HttpHandlers
+{
+ [Export(typeof(BaseHandler))]
+ public class StudiosHandler : BaseSerializationHandler<IbnItem[]>
+ {
+ public override bool HandlesRequest(HttpListenerRequest request)
+ {
+ return ApiService.IsApiUrlMatch("studios", request);
+ }
+
+ protected override Task<IbnItem[]> GetObjectToSerialize()
+ {
+ var parent = ApiService.GetItemById(QueryString["id"]) as Folder;
+ var user = ApiService.GetUserById(QueryString["userid"], true);
+
+ return GetAllStudios(parent, user);
+ }
+
+ /// <summary>
+ /// Gets all studios from all recursive children of a folder
+ /// The CategoryInfo class is used to keep track of the number of times each studio appears
+ /// </summary>
+ private async Task<IbnItem[]> GetAllStudios(Folder parent, User user)
+ {
+ var data = new Dictionary<string, int>();
+
+ // Get all the allowed recursive children
+ IEnumerable<BaseItem> allItems = parent.GetRecursiveChildren(user);
+
+ foreach (var item in allItems)
+ {
+ // Add each studio from the item to the data dictionary
+ // If the studio already exists, increment the count
+ if (item.Studios == null)
+ {
+ continue;
+ }
+
+ foreach (string val in item.Studios)
+ {
+ if (!data.ContainsKey(val))
+ {
+ data.Add(val, 1);
+ }
+ else
+ {
+ data[val]++;
+ }
+ }
+ }
+
+ // Get the Studio objects
+ Studio[] entities = await Task.WhenAll(data.Keys.Select(key => Kernel.Instance.ItemController.GetStudio(key))).ConfigureAwait(false);
+
+ // Convert to an array of IBNItem
+ var items = new IbnItem[entities.Length];
+
+ for (int i = 0; i < entities.Length; i++)
+ {
+ Studio e = entities[i];
+
+ items[i] = ApiService.GetIbnItem(e, data[e.Name]);
+ }
+
+ return items;
+ }
+ }
+}
diff --git a/MediaBrowser.Api/HttpHandlers/UserAuthenticationHandler.cs b/MediaBrowser.Api/HttpHandlers/UserAuthenticationHandler.cs
new file mode 100644
index 000000000..fa9d97598
--- /dev/null
+++ b/MediaBrowser.Api/HttpHandlers/UserAuthenticationHandler.cs
@@ -0,0 +1,29 @@
+using MediaBrowser.Common.Net.Handlers;
+using MediaBrowser.Controller;
+using MediaBrowser.Controller.Entities;
+using MediaBrowser.Model.Authentication;
+using System.ComponentModel.Composition;
+using System.Net;
+using System.Threading.Tasks;
+
+namespace MediaBrowser.Api.HttpHandlers
+{
+ [Export(typeof(BaseHandler))]
+ class UserAuthenticationHandler : BaseSerializationHandler<AuthenticationResult>
+ {
+ public override bool HandlesRequest(HttpListenerRequest request)
+ {
+ return ApiService.IsApiUrlMatch("UserAuthentication", request);
+ }
+
+ protected override async Task<AuthenticationResult> GetObjectToSerialize()
+ {
+ string userId = await GetFormValue("userid").ConfigureAwait(false);
+ User user = ApiService.GetUserById(userId, false);
+
+ string password = await GetFormValue("password").ConfigureAwait(false);
+
+ return Kernel.Instance.AuthenticateUser(user, password);
+ }
+ }
+}
diff --git a/MediaBrowser.Api/HttpHandlers/UserHandler.cs b/MediaBrowser.Api/HttpHandlers/UserHandler.cs
new file mode 100644
index 000000000..bc9286204
--- /dev/null
+++ b/MediaBrowser.Api/HttpHandlers/UserHandler.cs
@@ -0,0 +1,29 @@
+using MediaBrowser.Common.Net.Handlers;
+using MediaBrowser.Controller.Entities;
+using MediaBrowser.Model.DTO;
+using System.ComponentModel.Composition;
+using System.Net;
+using System.Threading.Tasks;
+
+namespace MediaBrowser.Api.HttpHandlers
+{
+ [Export(typeof(BaseHandler))]
+ class UserHandler : BaseSerializationHandler<DtoUser>
+ {
+ public override bool HandlesRequest(HttpListenerRequest request)
+ {
+ return ApiService.IsApiUrlMatch("user", request);
+ }
+
+ protected override Task<DtoUser> GetObjectToSerialize()
+ {
+ string id = QueryString["id"];
+
+ User user = string.IsNullOrEmpty(id) ? ApiService.GetDefaultUser(false) : ApiService.GetUserById(id, false);
+
+ DtoUser dto = ApiService.GetDtoUser(user);
+
+ return Task.FromResult(dto);
+ }
+ }
+}
diff --git a/MediaBrowser.Api/HttpHandlers/UserItemRatingHandler.cs b/MediaBrowser.Api/HttpHandlers/UserItemRatingHandler.cs
new file mode 100644
index 000000000..aed0804b6
--- /dev/null
+++ b/MediaBrowser.Api/HttpHandlers/UserItemRatingHandler.cs
@@ -0,0 +1,46 @@
+using MediaBrowser.Common.Net.Handlers;
+using MediaBrowser.Controller.Entities;
+using MediaBrowser.Model.DTO;
+using System.ComponentModel.Composition;
+using System.Net;
+using System.Threading.Tasks;
+
+namespace MediaBrowser.Api.HttpHandlers
+{
+ /// <summary>
+ /// Provides a handler to set a user's rating for an item
+ /// </summary>
+ [Export(typeof(BaseHandler))]
+ public class UserItemRatingHandler : BaseSerializationHandler<DtoUserItemData>
+ {
+ public override bool HandlesRequest(HttpListenerRequest request)
+ {
+ return ApiService.IsApiUrlMatch("UserItemRating", request);
+ }
+
+ protected override Task<DtoUserItemData> GetObjectToSerialize()
+ {
+ // Get the item
+ BaseItem item = ApiService.GetItemById(QueryString["id"]);
+
+ // Get the user
+ User user = ApiService.GetUserById(QueryString["userid"], true);
+
+ // Get the user data for this item
+ UserItemData data = item.GetUserData(user, true);
+
+ // If clearing the rating, set it to null
+ if (QueryString["clear"] == "1")
+ {
+ data.Rating = null;
+ }
+
+ else
+ {
+ data.Likes = QueryString["likes"] == "1";
+ }
+
+ return Task.FromResult(ApiService.GetDtoUserItemData(data));
+ }
+ }
+} \ No newline at end of file
diff --git a/MediaBrowser.Api/HttpHandlers/UsersHandler.cs b/MediaBrowser.Api/HttpHandlers/UsersHandler.cs
new file mode 100644
index 000000000..3fc3a7d58
--- /dev/null
+++ b/MediaBrowser.Api/HttpHandlers/UsersHandler.cs
@@ -0,0 +1,25 @@
+using MediaBrowser.Common.Net.Handlers;
+using MediaBrowser.Controller;
+using MediaBrowser.Model.DTO;
+using System.Collections.Generic;
+using System.ComponentModel.Composition;
+using System.Linq;
+using System.Net;
+using System.Threading.Tasks;
+
+namespace MediaBrowser.Api.HttpHandlers
+{
+ [Export(typeof(BaseHandler))]
+ class UsersHandler : BaseSerializationHandler<IEnumerable<DtoUser>>
+ {
+ public override bool HandlesRequest(HttpListenerRequest request)
+ {
+ return ApiService.IsApiUrlMatch("users", request);
+ }
+
+ protected override Task<IEnumerable<DtoUser>> GetObjectToSerialize()
+ {
+ return Task.FromResult(Kernel.Instance.Users.Select(u => ApiService.GetDtoUser(u)));
+ }
+ }
+}
diff --git a/MediaBrowser.Api/HttpHandlers/VideoHandler.cs b/MediaBrowser.Api/HttpHandlers/VideoHandler.cs
new file mode 100644
index 000000000..e34a1b41f
--- /dev/null
+++ b/MediaBrowser.Api/HttpHandlers/VideoHandler.cs
@@ -0,0 +1,424 @@
+using MediaBrowser.Common.Net.Handlers;
+using MediaBrowser.Controller.Drawing;
+using MediaBrowser.Controller.Entities;
+using MediaBrowser.Model.DTO;
+using MediaBrowser.Model.Entities;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.Composition;
+using System.Drawing;
+using System.Linq;
+using System.Net;
+
+namespace MediaBrowser.Api.HttpHandlers
+{
+ /// <summary>
+ /// Supported output formats: mkv,m4v,mp4,asf,wmv,mov,webm,ogv,3gp,avi,ts,flv
+ /// </summary>
+ [Export(typeof(BaseHandler))]
+ class VideoHandler : BaseMediaHandler<Video, VideoOutputFormats>
+ {
+ public override bool HandlesRequest(HttpListenerRequest request)
+ {
+ return ApiService.IsApiUrlMatch("video", request);
+ }
+
+ /// <summary>
+ /// We can output these files directly, but we can't encode them
+ /// </summary>
+ protected override IEnumerable<VideoOutputFormats> UnsupportedOutputEncodingFormats
+ {
+ get
+ {
+ // mp4, 3gp, mov - muxer does not support non-seekable output
+ // avi, mov, mkv, m4v - can't stream these when encoding. the player will try to download them completely before starting playback.
+ // wmv - can't seem to figure out the output format name
+ return new VideoOutputFormats[] { VideoOutputFormats.Mp4, VideoOutputFormats.ThreeGp, VideoOutputFormats.M4V, VideoOutputFormats.Mkv, VideoOutputFormats.Avi, VideoOutputFormats.Mov, VideoOutputFormats.Wmv };
+ }
+ }
+
+ /// <summary>
+ /// Determines whether or not we can just output the original file directly
+ /// </summary>
+ protected override bool RequiresConversion()
+ {
+ if (base.RequiresConversion())
+ {
+ return true;
+ }
+
+ // See if the video requires conversion
+ if (RequiresVideoConversion())
+ {
+ return true;
+ }
+
+ // See if the audio requires conversion
+ AudioStream audioStream = (LibraryItem.AudioStreams ?? new List<AudioStream>()).FirstOrDefault();
+
+ if (audioStream != null)
+ {
+ if (RequiresAudioConversion(audioStream))
+ {
+ return true;
+ }
+ }
+
+ // Yay
+ return false;
+ }
+
+ /// <summary>
+ /// Translates the output file extension to the format param that follows "-f" on the ffmpeg command line
+ /// </summary>
+ private string GetFfMpegOutputFormat(VideoOutputFormats outputFormat)
+ {
+ if (outputFormat == VideoOutputFormats.Mkv)
+ {
+ return "matroska";
+ }
+ if (outputFormat == VideoOutputFormats.Ts)
+ {
+ return "mpegts";
+ }
+ if (outputFormat == VideoOutputFormats.Ogv)
+ {
+ return "ogg";
+ }
+
+ return outputFormat.ToString().ToLower();
+ }
+
+ /// <summary>
+ /// Creates arguments to pass to ffmpeg
+ /// </summary>
+ protected override string GetCommandLineArguments()
+ {
+ VideoOutputFormats outputFormat = GetConversionOutputFormat();
+
+ return string.Format("-i \"{0}\" -threads 0 {1} {2} -f {3} -",
+ LibraryItem.Path,
+ GetVideoArguments(outputFormat),
+ GetAudioArguments(outputFormat),
+ GetFfMpegOutputFormat(outputFormat)
+ );
+ }
+
+ /// <summary>
+ /// Gets video arguments to pass to ffmpeg
+ /// </summary>
+ private string GetVideoArguments(VideoOutputFormats outputFormat)
+ {
+ // Get the output codec name
+ string codec = GetVideoCodec(outputFormat);
+
+ string args = "-vcodec " + codec;
+
+ // If we're encoding video, add additional params
+ if (!codec.Equals("copy", StringComparison.OrdinalIgnoreCase))
+ {
+ // Add resolution params, if specified
+ if (Width.HasValue || Height.HasValue || MaxHeight.HasValue || MaxWidth.HasValue)
+ {
+ Size size = DrawingUtils.Resize(LibraryItem.Width, LibraryItem.Height, Width, Height, MaxWidth, MaxHeight);
+
+ args += string.Format(" -s {0}x{1}", size.Width, size.Height);
+ }
+ }
+
+ return args;
+ }
+
+ /// <summary>
+ /// Gets audio arguments to pass to ffmpeg
+ /// </summary>
+ private string GetAudioArguments(VideoOutputFormats outputFormat)
+ {
+ AudioStream audioStream = (LibraryItem.AudioStreams ?? new List<AudioStream>()).FirstOrDefault();
+
+ // If the video doesn't have an audio stream, return empty
+ if (audioStream == null)
+ {
+ return string.Empty;
+ }
+
+ // Get the output codec name
+ string codec = GetAudioCodec(audioStream, outputFormat);
+
+ string args = "-acodec " + codec;
+
+ // If we're encoding audio, add additional params
+ if (!codec.Equals("copy", StringComparison.OrdinalIgnoreCase))
+ {
+ // Add the number of audio channels
+ int? channels = GetNumAudioChannelsParam(codec, audioStream.Channels);
+
+ if (channels.HasValue)
+ {
+ args += " -ac " + channels.Value;
+ }
+
+ // Add the audio sample rate
+ int? sampleRate = GetSampleRateParam(audioStream.SampleRate);
+
+ if (sampleRate.HasValue)
+ {
+ args += " -ar " + sampleRate.Value;
+ }
+
+ }
+
+ return args;
+ }
+
+ /// <summary>
+ /// Gets the name of the output video codec
+ /// </summary>
+ private string GetVideoCodec(VideoOutputFormats outputFormat)
+ {
+ // Some output containers require specific codecs
+
+ if (outputFormat == VideoOutputFormats.Webm)
+ {
+ // Per webm specification, it must be vpx
+ return "libvpx";
+ }
+ if (outputFormat == VideoOutputFormats.Asf)
+ {
+ return "wmv2";
+ }
+ if (outputFormat == VideoOutputFormats.Wmv)
+ {
+ return "wmv2";
+ }
+ if (outputFormat == VideoOutputFormats.Ogv)
+ {
+ return "libtheora";
+ }
+
+ // Skip encoding when possible
+ if (!RequiresVideoConversion())
+ {
+ return "copy";
+ }
+
+ return "libx264";
+ }
+
+ /// <summary>
+ /// Gets the name of the output audio codec
+ /// </summary>
+ private string GetAudioCodec(AudioStream audioStream, VideoOutputFormats outputFormat)
+ {
+ // Some output containers require specific codecs
+
+ if (outputFormat == VideoOutputFormats.Webm)
+ {
+ // Per webm specification, it must be vorbis
+ return "libvorbis";
+ }
+ if (outputFormat == VideoOutputFormats.Asf)
+ {
+ return "wmav2";
+ }
+ if (outputFormat == VideoOutputFormats.Wmv)
+ {
+ return "wmav2";
+ }
+ if (outputFormat == VideoOutputFormats.Ogv)
+ {
+ return "libvorbis";
+ }
+
+ // Skip encoding when possible
+ if (!RequiresAudioConversion(audioStream))
+ {
+ return "copy";
+ }
+
+ return "libvo_aacenc";
+ }
+
+ /// <summary>
+ /// Gets the number of audio channels to specify on the command line
+ /// </summary>
+ private int? GetNumAudioChannelsParam(string audioCodec, int libraryItemChannels)
+ {
+ if (libraryItemChannels > 2)
+ {
+ if (audioCodec.Equals("libvo_aacenc"))
+ {
+ // libvo_aacenc currently only supports two channel output
+ return 2;
+ }
+ if (audioCodec.Equals("wmav2"))
+ {
+ // wmav2 currently only supports two channel output
+ return 2;
+ }
+ }
+
+ return GetNumAudioChannelsParam(libraryItemChannels);
+ }
+
+ /// <summary>
+ /// Determines if the video stream requires encoding
+ /// </summary>
+ private bool RequiresVideoConversion()
+ {
+ // Check dimensions
+
+ // If a specific width is required, validate that
+ if (Width.HasValue)
+ {
+ if (Width.Value != LibraryItem.Width)
+ {
+ return true;
+ }
+ }
+
+ // If a specific height is required, validate that
+ if (Height.HasValue)
+ {
+ if (Height.Value != LibraryItem.Height)
+ {
+ return true;
+ }
+ }
+
+ // If a max width is required, validate that
+ if (MaxWidth.HasValue)
+ {
+ if (MaxWidth.Value < LibraryItem.Width)
+ {
+ return true;
+ }
+ }
+
+ // If a max height is required, validate that
+ if (MaxHeight.HasValue)
+ {
+ if (MaxHeight.Value < LibraryItem.Height)
+ {
+ return true;
+ }
+ }
+
+ // If the codec is already h264, don't encode
+ if (LibraryItem.Codec.IndexOf("264", StringComparison.OrdinalIgnoreCase) != -1 || LibraryItem.Codec.IndexOf("avc", StringComparison.OrdinalIgnoreCase) != -1)
+ {
+ return false;
+ }
+
+ return false;
+ }
+
+ /// <summary>
+ /// Determines if the audio stream requires encoding
+ /// </summary>
+ private bool RequiresAudioConversion(AudioStream audio)
+ {
+
+ // If the input stream has more audio channels than the client can handle, we need to encode
+ if (AudioChannels.HasValue)
+ {
+ if (audio.Channels > AudioChannels.Value)
+ {
+ return true;
+ }
+ }
+
+ // Aac, ac-3 and mp3 are all pretty much universally supported. No need to encode them
+
+ if (audio.Codec.IndexOf("aac", StringComparison.OrdinalIgnoreCase) != -1)
+ {
+ return false;
+ }
+
+ if (audio.Codec.IndexOf("ac-3", StringComparison.OrdinalIgnoreCase) != -1 || audio.Codec.IndexOf("ac3", StringComparison.OrdinalIgnoreCase) != -1)
+ {
+ return false;
+ }
+
+ if (audio.Codec.IndexOf("mpeg", StringComparison.OrdinalIgnoreCase) != -1 || audio.Codec.IndexOf("mp3", StringComparison.OrdinalIgnoreCase) != -1)
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ /// <summary>
+ /// Gets the fixed output video height, in pixels
+ /// </summary>
+ private int? Height
+ {
+ get
+ {
+ string val = QueryString["height"];
+
+ if (string.IsNullOrEmpty(val))
+ {
+ return null;
+ }
+
+ return int.Parse(val);
+ }
+ }
+
+ /// <summary>
+ /// Gets the fixed output video width, in pixels
+ /// </summary>
+ private int? Width
+ {
+ get
+ {
+ string val = QueryString["width"];
+
+ if (string.IsNullOrEmpty(val))
+ {
+ return null;
+ }
+
+ return int.Parse(val);
+ }
+ }
+
+ /// <summary>
+ /// Gets the maximum output video height, in pixels
+ /// </summary>
+ private int? MaxHeight
+ {
+ get
+ {
+ string val = QueryString["maxheight"];
+
+ if (string.IsNullOrEmpty(val))
+ {
+ return null;
+ }
+
+ return int.Parse(val);
+ }
+ }
+
+ /// <summary>
+ /// Gets the maximum output video width, in pixels
+ /// </summary>
+ private int? MaxWidth
+ {
+ get
+ {
+ string val = QueryString["maxwidth"];
+
+ if (string.IsNullOrEmpty(val))
+ {
+ return null;
+ }
+
+ return int.Parse(val);
+ }
+ }
+
+ }
+}
diff --git a/MediaBrowser.Api/HttpHandlers/WeatherHandler.cs b/MediaBrowser.Api/HttpHandlers/WeatherHandler.cs
new file mode 100644
index 000000000..378e89067
--- /dev/null
+++ b/MediaBrowser.Api/HttpHandlers/WeatherHandler.cs
@@ -0,0 +1,43 @@
+using MediaBrowser.Common.Net.Handlers;
+using MediaBrowser.Controller;
+using MediaBrowser.Model.Weather;
+using System;
+using System.ComponentModel.Composition;
+using System.Linq;
+using System.Net;
+using System.Threading.Tasks;
+
+namespace MediaBrowser.Api.HttpHandlers
+{
+ [Export(typeof(BaseHandler))]
+ class WeatherHandler : BaseSerializationHandler<WeatherInfo>
+ {
+ public override bool HandlesRequest(HttpListenerRequest request)
+ {
+ return ApiService.IsApiUrlMatch("weather", request);
+ }
+
+ protected override Task<WeatherInfo> GetObjectToSerialize()
+ {
+ // If a specific zip code was requested on the query string, use that. Otherwise use the value from configuration
+
+ string zipCode = QueryString["zipcode"];
+
+ if (string.IsNullOrWhiteSpace(zipCode))
+ {
+ zipCode = Kernel.Instance.Configuration.WeatherZipCode;
+ }
+
+ return Kernel.Instance.WeatherProviders.First().GetWeatherInfoAsync(zipCode);
+ }
+
+ protected override async Task<ResponseInfo> GetResponseInfo()
+ {
+ var info = await base.GetResponseInfo().ConfigureAwait(false);
+
+ info.CacheDuration = TimeSpan.FromMinutes(15);
+
+ return info;
+ }
+ }
+}
diff --git a/MediaBrowser.Api/HttpHandlers/YearHandler.cs b/MediaBrowser.Api/HttpHandlers/YearHandler.cs
new file mode 100644
index 000000000..dbd1d25be
--- /dev/null
+++ b/MediaBrowser.Api/HttpHandlers/YearHandler.cs
@@ -0,0 +1,55 @@
+using MediaBrowser.Common.Net.Handlers;
+using MediaBrowser.Controller;
+using MediaBrowser.Controller.Entities;
+using MediaBrowser.Model.DTO;
+using System.Collections.Generic;
+using System.ComponentModel.Composition;
+using System.Net;
+using System.Threading.Tasks;
+
+namespace MediaBrowser.Api.HttpHandlers
+{
+ /// <summary>
+ /// Gets a single year
+ /// </summary>
+ [Export(typeof(BaseHandler))]
+ public class YearHandler : BaseSerializationHandler<IbnItem>
+ {
+ public override bool HandlesRequest(HttpListenerRequest request)
+ {
+ return ApiService.IsApiUrlMatch("year", request);
+ }
+
+ protected override Task<IbnItem> GetObjectToSerialize()
+ {
+ var parent = ApiService.GetItemById(QueryString["id"]) as Folder;
+ var user = ApiService.GetUserById(QueryString["userid"], true);
+
+ string year = QueryString["year"];
+
+ return GetYear(parent, user, int.Parse(year));
+ }
+
+ /// <summary>
+ /// Gets a Year
+ /// </summary>
+ private async Task<IbnItem> GetYear(Folder parent, User user, int year)
+ {
+ int count = 0;
+
+ // Get all the allowed recursive children
+ IEnumerable<BaseItem> allItems = parent.GetRecursiveChildren(user);
+
+ foreach (var item in allItems)
+ {
+ if (item.ProductionYear.HasValue && item.ProductionYear.Value == year)
+ {
+ count++;
+ }
+ }
+
+ // Get the original entity so that we can also supply the PrimaryImagePath
+ return ApiService.GetIbnItem(await Kernel.Instance.ItemController.GetYear(year).ConfigureAwait(false), count);
+ }
+ }
+}
diff --git a/MediaBrowser.Api/HttpHandlers/YearsHandler.cs b/MediaBrowser.Api/HttpHandlers/YearsHandler.cs
new file mode 100644
index 000000000..7c90768e8
--- /dev/null
+++ b/MediaBrowser.Api/HttpHandlers/YearsHandler.cs
@@ -0,0 +1,75 @@
+using MediaBrowser.Common.Net.Handlers;
+using MediaBrowser.Controller;
+using MediaBrowser.Controller.Entities;
+using MediaBrowser.Model.DTO;
+using System.Collections.Generic;
+using System.ComponentModel.Composition;
+using System.Linq;
+using System.Net;
+using System.Threading.Tasks;
+
+namespace MediaBrowser.Api.HttpHandlers
+{
+ [Export(typeof(BaseHandler))]
+ public class YearsHandler : BaseSerializationHandler<IbnItem[]>
+ {
+ public override bool HandlesRequest(HttpListenerRequest request)
+ {
+ return ApiService.IsApiUrlMatch("years", request);
+ }
+
+ protected override Task<IbnItem[]> GetObjectToSerialize()
+ {
+ var parent = ApiService.GetItemById(QueryString["id"]) as Folder;
+ User user = ApiService.GetUserById(QueryString["userid"], true);
+
+ return GetAllYears(parent, user);
+ }
+
+ /// <summary>
+ /// Gets all years from all recursive children of a folder
+ /// The CategoryInfo class is used to keep track of the number of times each year appears
+ /// </summary>
+ private async Task<IbnItem[]> GetAllYears(Folder parent, User user)
+ {
+ var data = new Dictionary<int, int>();
+
+ // Get all the allowed recursive children
+ IEnumerable<BaseItem> allItems = parent.GetRecursiveChildren(user);
+
+ foreach (var item in allItems)
+ {
+ // Add the year from the item to the data dictionary
+ // If the year already exists, increment the count
+ if (item.ProductionYear == null)
+ {
+ continue;
+ }
+
+ if (!data.ContainsKey(item.ProductionYear.Value))
+ {
+ data.Add(item.ProductionYear.Value, 1);
+ }
+ else
+ {
+ data[item.ProductionYear.Value]++;
+ }
+ }
+
+ // Get the Year objects
+ Year[] entities = await Task.WhenAll(data.Keys.Select(key => Kernel.Instance.ItemController.GetYear(key))).ConfigureAwait(false);
+
+ // Convert to an array of IBNItem
+ var items = new IbnItem[entities.Length];
+
+ for (int i = 0; i < entities.Length; i++)
+ {
+ Year e = entities[i];
+
+ items[i] = ApiService.GetIbnItem(e, data[int.Parse(e.Name)]);
+ }
+
+ return items;
+ }
+ }
+}
diff --git a/MediaBrowser.Api/MediaBrowser.Api.csproj b/MediaBrowser.Api/MediaBrowser.Api.csproj
new file mode 100644
index 000000000..1af7e71bd
--- /dev/null
+++ b/MediaBrowser.Api/MediaBrowser.Api.csproj
@@ -0,0 +1,117 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProjectGuid>{4FD51AC5-2C16-4308-A993-C3A84F3B4582}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>MediaBrowser.Api</RootNamespace>
+ <AssemblyName>MediaBrowser.Api</AssemblyName>
+ <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup>
+ <RunPostBuildEvent>Always</RunPostBuildEvent>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="System" />
+ <Reference Include="System.ComponentModel.Composition" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Drawing" />
+ <Reference Include="System.Reactive.Core, Version=2.0.20823.0, Culture=neutral, PublicKeyToken=f300afd708cefcd3, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\packages\Rx-Core.2.0.20823\lib\Net45\System.Reactive.Core.dll</HintPath>
+ </Reference>
+ <Reference Include="System.Reactive.Interfaces, Version=2.0.20823.0, Culture=neutral, PublicKeyToken=f300afd708cefcd3, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\packages\Rx-Interfaces.2.0.20823\lib\Net45\System.Reactive.Interfaces.dll</HintPath>
+ </Reference>
+ <Reference Include="System.Reactive.Linq, Version=2.0.20823.0, Culture=neutral, PublicKeyToken=f300afd708cefcd3, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\packages\Rx-Linq.2.0.20823\lib\Net45\System.Reactive.Linq.dll</HintPath>
+ </Reference>
+ <Reference Include="System.Runtime.Serialization" />
+ <Reference Include="System.Xml.Linq" />
+ <Reference Include="System.Data.DataSetExtensions" />
+ <Reference Include="Microsoft.CSharp" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="ApiService.cs" />
+ <Compile Include="HttpHandlers\AudioHandler.cs" />
+ <Compile Include="HttpHandlers\BaseMediaHandler.cs" />
+ <Compile Include="HttpHandlers\FavoriteStatusHandler.cs" />
+ <Compile Include="HttpHandlers\MovieSpecialFeaturesHandler.cs" />
+ <Compile Include="HttpHandlers\PlayedStatusHandler.cs" />
+ <Compile Include="HttpHandlers\UserHandler.cs" />
+ <Compile Include="HttpHandlers\GenreHandler.cs" />
+ <Compile Include="HttpHandlers\GenresHandler.cs" />
+ <Compile Include="HttpHandlers\ImageHandler.cs" />
+ <Compile Include="HttpHandlers\ItemHandler.cs" />
+ <Compile Include="HttpHandlers\ItemListHandler.cs" />
+ <Compile Include="HttpHandlers\PersonHandler.cs" />
+ <Compile Include="HttpHandlers\PluginAssemblyHandler.cs" />
+ <Compile Include="HttpHandlers\PluginConfigurationHandler.cs" />
+ <Compile Include="HttpHandlers\PluginsHandler.cs" />
+ <Compile Include="HttpHandlers\ServerConfigurationHandler.cs" />
+ <Compile Include="HttpHandlers\StudioHandler.cs" />
+ <Compile Include="HttpHandlers\StudiosHandler.cs" />
+ <Compile Include="HttpHandlers\UserAuthenticationHandler.cs" />
+ <Compile Include="HttpHandlers\UserItemRatingHandler.cs" />
+ <Compile Include="HttpHandlers\UsersHandler.cs" />
+ <Compile Include="HttpHandlers\VideoHandler.cs" />
+ <Compile Include="HttpHandlers\WeatherHandler.cs" />
+ <Compile Include="HttpHandlers\YearHandler.cs" />
+ <Compile Include="HttpHandlers\YearsHandler.cs" />
+ <Compile Include="Plugin.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\MediaBrowser.Common\MediaBrowser.Common.csproj">
+ <Project>{9142eefa-7570-41e1-bfcc-468bb571af2f}</Project>
+ <Name>MediaBrowser.Common</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\MediaBrowser.Controller\MediaBrowser.Controller.csproj">
+ <Project>{17e1f4e6-8abd-4fe5-9ecf-43d4b6087ba2}</Project>
+ <Name>MediaBrowser.Controller</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\MediaBrowser.Model\MediaBrowser.Model.csproj">
+ <Project>{7eeeb4bb-f3e8-48fc-b4c5-70f0fff8329b}</Project>
+ <Name>MediaBrowser.Model</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="packages.config" />
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <PropertyGroup>
+ <PostBuildEvent>xcopy "$(TargetPath)" "$(SolutionDir)\ProgramData-Server\Plugins\" /y</PostBuildEvent>
+ </PropertyGroup>
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project> \ No newline at end of file
diff --git a/MediaBrowser.Api/Plugin.cs b/MediaBrowser.Api/Plugin.cs
new file mode 100644
index 000000000..8def96da8
--- /dev/null
+++ b/MediaBrowser.Api/Plugin.cs
@@ -0,0 +1,14 @@
+using MediaBrowser.Common.Plugins;
+using System.ComponentModel.Composition;
+
+namespace MediaBrowser.Api
+{
+ [Export(typeof(BasePlugin))]
+ public class Plugin : BasePlugin
+ {
+ public override string Name
+ {
+ get { return "Media Browser API"; }
+ }
+ }
+}
diff --git a/MediaBrowser.Api/Properties/AssemblyInfo.cs b/MediaBrowser.Api/Properties/AssemblyInfo.cs
new file mode 100644
index 000000000..c92346bac
--- /dev/null
+++ b/MediaBrowser.Api/Properties/AssemblyInfo.cs
@@ -0,0 +1,35 @@
+using System.Reflection;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("MediaBrowser.Api")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("MediaBrowser.Api")]
+[assembly: AssemblyCopyright("Copyright © 2012")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("13464b02-f033-48b8-9e1c-d071f8860935")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/MediaBrowser.Api/packages.config b/MediaBrowser.Api/packages.config
new file mode 100644
index 000000000..42f16a267
--- /dev/null
+++ b/MediaBrowser.Api/packages.config
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+ <package id="Rx-Core" version="2.0.20823" targetFramework="net45" />
+ <package id="Rx-Interfaces" version="2.0.20823" targetFramework="net45" />
+ <package id="Rx-Linq" version="2.0.20823" targetFramework="net45" />
+</packages> \ No newline at end of file