mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-05-25 18:16:56 +01:00
All calls to get items now require passing in a userId. Made the model project portable. Also filled in more api calls.
This commit is contained in:
parent
baedafbeb9
commit
6fbd5cf464
113
MediaBrowser.Common/ApiInteraction/ApiController.cs
Normal file
113
MediaBrowser.Common/ApiInteraction/ApiController.cs
Normal file
@@ -0,0 +1,113 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Common.Json;
|
||||
using MediaBrowser.Model.Users;
|
||||
using MediaBrowser.Model.Entities;
|
||||
|
||||
namespace MediaBrowser.Common.ApiInteraction
|
||||
{
|
||||
public class ApiController
|
||||
{
|
||||
public string ApiUrl { get; set; }
|
||||
|
||||
private WebClient WebClient { get; set; }
|
||||
|
||||
public ApiController()
|
||||
{
|
||||
WebClient = new WebClient();
|
||||
}
|
||||
|
||||
public async Task<DictionaryBaseItem> GetRootItem(Guid userId)
|
||||
{
|
||||
string url = ApiUrl + "/item?userId=" + userId.ToString();
|
||||
|
||||
Stream stream = await WebClient.OpenReadTaskAsync(url);
|
||||
|
||||
using (GZipStream gzipStream = new GZipStream(stream, CompressionMode.Decompress, false))
|
||||
{
|
||||
return DictionaryBaseItem.FromApiOutput(gzipStream);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<DictionaryBaseItem> GetItem(Guid id, Guid userId)
|
||||
{
|
||||
string url = ApiUrl + "/item?userId=" + userId.ToString();
|
||||
|
||||
if (id != Guid.Empty)
|
||||
{
|
||||
url += "&id=" + id.ToString();
|
||||
}
|
||||
|
||||
Stream stream = await WebClient.OpenReadTaskAsync(url);
|
||||
|
||||
using (GZipStream gzipStream = new GZipStream(stream, CompressionMode.Decompress, false))
|
||||
{
|
||||
return DictionaryBaseItem.FromApiOutput(gzipStream);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<User>> GetAllUsers()
|
||||
{
|
||||
string url = ApiUrl + "/users";
|
||||
|
||||
Stream stream = await WebClient.OpenReadTaskAsync(url);
|
||||
|
||||
using (GZipStream gzipStream = new GZipStream(stream, CompressionMode.Decompress, false))
|
||||
{
|
||||
return JsonSerializer.DeserializeFromStream<IEnumerable<User>>(gzipStream);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<CategoryInfo>> GetAllGenres(Guid userId)
|
||||
{
|
||||
string url = ApiUrl + "/genres?userId=" + userId.ToString();
|
||||
|
||||
Stream stream = await WebClient.OpenReadTaskAsync(url);
|
||||
|
||||
using (GZipStream gzipStream = new GZipStream(stream, CompressionMode.Decompress, false))
|
||||
{
|
||||
return JsonSerializer.DeserializeFromStream<IEnumerable<CategoryInfo>>(gzipStream);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<CategoryInfo> GetGenre(string name, Guid userId)
|
||||
{
|
||||
string url = ApiUrl + "/genre?userId=" + userId.ToString() + "&name=" + name;
|
||||
|
||||
Stream stream = await WebClient.OpenReadTaskAsync(url);
|
||||
|
||||
using (GZipStream gzipStream = new GZipStream(stream, CompressionMode.Decompress, false))
|
||||
{
|
||||
return JsonSerializer.DeserializeFromStream<CategoryInfo>(gzipStream);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<CategoryInfo>> GetAllStudios(Guid userId)
|
||||
{
|
||||
string url = ApiUrl + "/studios?userId=" + userId.ToString();
|
||||
|
||||
Stream stream = await WebClient.OpenReadTaskAsync(url);
|
||||
|
||||
using (GZipStream gzipStream = new GZipStream(stream, CompressionMode.Decompress, false))
|
||||
{
|
||||
return JsonSerializer.DeserializeFromStream<IEnumerable<CategoryInfo>>(gzipStream);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<CategoryInfo> GetStudio(string name, Guid userId)
|
||||
{
|
||||
string url = ApiUrl + "/studio?userId=" + userId.ToString() + "&name=" + name;
|
||||
|
||||
Stream stream = await WebClient.OpenReadTaskAsync(url);
|
||||
|
||||
using (GZipStream gzipStream = new GZipStream(stream, CompressionMode.Decompress, false))
|
||||
{
|
||||
return JsonSerializer.DeserializeFromStream<CategoryInfo>(gzipStream);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
412
MediaBrowser.Common/ApiInteraction/DictionaryBaseItem.cs
Normal file
412
MediaBrowser.Common/ApiInteraction/DictionaryBaseItem.cs
Normal file
@@ -0,0 +1,412 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using MediaBrowser.Common.Json;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Users;
|
||||
using System.Linq;
|
||||
|
||||
namespace MediaBrowser.Common.ApiInteraction
|
||||
{
|
||||
public class DictionaryBaseItem : BaseItem
|
||||
{
|
||||
private Dictionary<string, object> Dictionary { get; set; }
|
||||
|
||||
public UserItemData UserItemData { get; set; }
|
||||
public IEnumerable<DictionaryBaseItem> Children { get; set; }
|
||||
|
||||
public DictionaryBaseItem(Dictionary<string, object> dictionary)
|
||||
{
|
||||
Dictionary = dictionary;
|
||||
}
|
||||
|
||||
public override string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetString("Name");
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue("Name", value);
|
||||
}
|
||||
}
|
||||
|
||||
public override string ArtImagePath
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetString("ArtImagePath");
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue("ArtImagePath", value);
|
||||
}
|
||||
}
|
||||
|
||||
public override string AspectRatio
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetString("AspectRatio");
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue("AspectRatio", value);
|
||||
}
|
||||
}
|
||||
|
||||
public override string BannerImagePath
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetString("BannerImagePath");
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue("BannerImagePath", value);
|
||||
}
|
||||
}
|
||||
|
||||
public override string CustomPin
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetString("CustomPin");
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue("CustomPin", value);
|
||||
}
|
||||
}
|
||||
|
||||
public override string CustomRating
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetString("CustomRating");
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue("CustomRating", value);
|
||||
}
|
||||
}
|
||||
|
||||
public override string DisplayMediaType
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetString("DisplayMediaType");
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue("DisplayMediaType", value);
|
||||
}
|
||||
}
|
||||
|
||||
public override string LogoImagePath
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetString("LogoImagePath");
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue("LogoImagePath", value);
|
||||
}
|
||||
}
|
||||
|
||||
public override string OfficialRating
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetString("OfficialRating");
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue("OfficialRating", value);
|
||||
}
|
||||
}
|
||||
|
||||
public override string Overview
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetString("Overview");
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue("Overview", value);
|
||||
}
|
||||
}
|
||||
|
||||
public override string Path
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetString("Path");
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue("Path", value);
|
||||
}
|
||||
}
|
||||
|
||||
public override string PrimaryImagePath
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetString("PrimaryImagePath");
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue("PrimaryImagePath", value);
|
||||
}
|
||||
}
|
||||
|
||||
public override string SortName
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetString("SortName");
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue("SortName", value);
|
||||
}
|
||||
}
|
||||
|
||||
public override string Tagline
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetString("Tagline");
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue("Tagline", value);
|
||||
}
|
||||
}
|
||||
|
||||
public override string TrailerUrl
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetString("TrailerUrl");
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue("TrailerUrl", value);
|
||||
}
|
||||
}
|
||||
|
||||
public override DateTime DateCreated
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetDateTime("DateCreated");
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue("DateCreated", value);
|
||||
}
|
||||
}
|
||||
|
||||
public override DateTime DateModified
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetDateTime("DateModified");
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue("DateModified", value);
|
||||
}
|
||||
}
|
||||
|
||||
public override float? UserRating
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetNullableFloat("UserRating");
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue("UserRating", value);
|
||||
}
|
||||
}
|
||||
|
||||
public override string ThumbnailImagePath
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetString("ThumbnailImagePath");
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue("ThumbnailImagePath", value);
|
||||
}
|
||||
}
|
||||
|
||||
public override int? ProductionYear
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetNullableInt("ProductionYear");
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue("ProductionYear", value);
|
||||
}
|
||||
}
|
||||
|
||||
public override TimeSpan? RunTime
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetNullableTimeSpan("RunTime");
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue("RunTime", value);
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsFolder
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetBool("IsFolder");
|
||||
}
|
||||
}
|
||||
|
||||
public override Guid Id
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetGuid("Id");
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue("Id", value);
|
||||
}
|
||||
}
|
||||
|
||||
public TimeSpan? GetNullableTimeSpan(string name)
|
||||
{
|
||||
string val = Dictionary[name] as string;
|
||||
|
||||
if (string.IsNullOrEmpty(val))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return TimeSpan.Parse(val);
|
||||
}
|
||||
|
||||
public int? GetNullableInt(string name)
|
||||
{
|
||||
string val = Dictionary[name] as string;
|
||||
|
||||
if (string.IsNullOrEmpty(val))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return int.Parse(val);
|
||||
}
|
||||
|
||||
public float? GetNullableFloat(string name)
|
||||
{
|
||||
string val = Dictionary[name] as string;
|
||||
|
||||
if (string.IsNullOrEmpty(val))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return float.Parse(val);
|
||||
}
|
||||
|
||||
public DateTime? GetNullableDateTime(string name)
|
||||
{
|
||||
string val = Dictionary[name] as string;
|
||||
|
||||
if (string.IsNullOrEmpty(val))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return DateTime.Parse(val);
|
||||
}
|
||||
|
||||
public DateTime GetDateTime(string name)
|
||||
{
|
||||
DateTime? val = GetNullableDateTime(name);
|
||||
|
||||
return val ?? DateTime.MinValue;
|
||||
}
|
||||
|
||||
public bool? GetNullableBool(string name)
|
||||
{
|
||||
string val = Dictionary[name] as string;
|
||||
|
||||
if (string.IsNullOrEmpty(val))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return val != "false";
|
||||
}
|
||||
|
||||
public Guid GetGuid(string name)
|
||||
{
|
||||
string val = GetString(name);
|
||||
|
||||
if (string.IsNullOrEmpty(val))
|
||||
{
|
||||
return Guid.Empty;
|
||||
}
|
||||
|
||||
return Guid.Parse(val);
|
||||
}
|
||||
|
||||
public bool GetBool(string name)
|
||||
{
|
||||
bool? val = GetNullableBool(name);
|
||||
|
||||
return val ?? false;
|
||||
}
|
||||
|
||||
public string GetString(string name)
|
||||
{
|
||||
return Dictionary[name] as string;
|
||||
}
|
||||
|
||||
private void SetValue<T>(string name, T value)
|
||||
{
|
||||
Dictionary[name] = value;
|
||||
}
|
||||
|
||||
public static DictionaryBaseItem FromApiOutput(Stream stream)
|
||||
{
|
||||
Dictionary<string, object> data = JsonSerializer.DeserializeFromStream<Dictionary<string, object>>(stream);
|
||||
|
||||
string baseItem = data["Item"] as string;
|
||||
|
||||
DictionaryBaseItem item = new DictionaryBaseItem(JsonSerializer.DeserializeFromString<Dictionary<string, object>>(baseItem));
|
||||
|
||||
if (data.ContainsKey("UserItemData"))
|
||||
{
|
||||
item.UserItemData = JsonSerializer.DeserializeFromString<UserItemData>(data["UserItemData"].ToString());
|
||||
}
|
||||
|
||||
if (data.ContainsKey("Children"))
|
||||
{
|
||||
item.Children = JsonSerializer.DeserializeFromString<IEnumerable<Dictionary<string, object>>>(data["Children"].ToString()).Select(c => new DictionaryBaseItem(c));
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -45,9 +45,10 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ApiInteraction\ApiController.cs" />
|
||||
<Compile Include="Events\GenericItemEventArgs.cs" />
|
||||
<Compile Include="Json\JsonSerializer.cs" />
|
||||
<Compile Include="Model\DictionaryBaseItem.cs" />
|
||||
<Compile Include="ApiInteraction\DictionaryBaseItem.cs" />
|
||||
<Compile Include="Net\CollectionExtensions.cs" />
|
||||
<Compile Include="Net\Handlers\BaseEmbeddedResourceHandler.cs" />
|
||||
<Compile Include="Net\Handlers\JsonHandler.cs" />
|
||||
@@ -70,7 +71,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\MediaBrowser.Model\MediaBrowser.Model.csproj">
|
||||
<Project>{9b1ddd79-5134-4df3-ace3-d1957a7350d8}</Project>
|
||||
<Project>{7eeeb4bb-f3e8-48fc-b4c5-70f0fff8329b}</Project>
|
||||
<Name>MediaBrowser.Model</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
|
||||
@@ -1,227 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using System.IO;
|
||||
using MediaBrowser.Common.Json;
|
||||
|
||||
namespace MediaBrowser.Common.Model
|
||||
{
|
||||
public class DictionaryBaseItem : BaseItem
|
||||
{
|
||||
private Dictionary<string, object> Dictionary { get; set; }
|
||||
|
||||
public DictionaryBaseItem(Dictionary<string, object> dictionary)
|
||||
{
|
||||
Dictionary = dictionary;
|
||||
}
|
||||
|
||||
public override string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetString("Name");
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue("Name", value);
|
||||
}
|
||||
}
|
||||
|
||||
public override string ArtImagePath
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetString("ArtImagePath");
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue("ArtImagePath", value);
|
||||
}
|
||||
}
|
||||
|
||||
public override string AspectRatio
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetString("AspectRatio");
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue("AspectRatio", value);
|
||||
}
|
||||
}
|
||||
|
||||
public override string BannerImagePath
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetString("BannerImagePath");
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue("BannerImagePath", value);
|
||||
}
|
||||
}
|
||||
|
||||
public override string CustomPin
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetString("CustomPin");
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue("CustomPin", value);
|
||||
}
|
||||
}
|
||||
|
||||
public override string CustomRating
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetString("CustomRating");
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue("CustomRating", value);
|
||||
}
|
||||
}
|
||||
|
||||
public override string DisplayMediaType
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetString("DisplayMediaType");
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue("DisplayMediaType", value);
|
||||
}
|
||||
}
|
||||
|
||||
public override string LogoImagePath
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetString("LogoImagePath");
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue("LogoImagePath", value);
|
||||
}
|
||||
}
|
||||
|
||||
public override string OfficialRating
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetString("OfficialRating");
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue("OfficialRating", value);
|
||||
}
|
||||
}
|
||||
|
||||
public override string Overview
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetString("Overview");
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue("Overview", value);
|
||||
}
|
||||
}
|
||||
|
||||
public override string Path
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetString("Path");
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue("Path", value);
|
||||
}
|
||||
}
|
||||
|
||||
public override string PrimaryImagePath
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetString("PrimaryImagePath");
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue("PrimaryImagePath", value);
|
||||
}
|
||||
}
|
||||
|
||||
public override string SortName
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetString("SortName");
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue("SortName", value);
|
||||
}
|
||||
}
|
||||
|
||||
public override string Tagline
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetString("Tagline");
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue("Tagline", value);
|
||||
}
|
||||
}
|
||||
|
||||
public override string TrailerUrl
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetString("TrailerUrl");
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue("TrailerUrl", value);
|
||||
}
|
||||
}
|
||||
|
||||
private string GetString(string name)
|
||||
{
|
||||
return Dictionary[name] as string;
|
||||
}
|
||||
|
||||
private void SetValue<T>(string name, T value)
|
||||
{
|
||||
Dictionary[name] = value;
|
||||
}
|
||||
|
||||
public static DictionaryBaseItem FromApiOutput(Stream stream)
|
||||
{
|
||||
Dictionary<string,object> data = JsonSerializer.DeserializeFromStream<Dictionary<string, object>>(stream);
|
||||
|
||||
if (data.ContainsKey("BaseItem"))
|
||||
{
|
||||
string baseItem = data["BaseItem"] as string;
|
||||
|
||||
data = JsonSerializer.DeserializeFromString<Dictionary<string, object>>(baseItem);
|
||||
|
||||
return new DictionaryBaseItem(data);
|
||||
}
|
||||
|
||||
return new DictionaryBaseItem(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user