Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
tidusjar committed Jan 12, 2021
2 parents 878adc5 + df74e38 commit eedd67b
Show file tree
Hide file tree
Showing 269 changed files with 10,159 additions and 1,019 deletions.
4 changes: 0 additions & 4 deletions src/Ombi.Api.Emby/EmbyApiFactory.cs
Expand Up @@ -25,10 +25,6 @@ public async Task<IEmbyApi> CreateClient()

public IEmbyApi CreateClient(EmbySettings settings)
{
if (settings.IsJellyfin)
{
return new JellyfinApi(_api);
}
return new EmbyApi(_api);
}
}
Expand Down
9 changes: 1 addition & 8 deletions src/Ombi.Api.Emby/Models/PublicInfo.cs
Expand Up @@ -5,15 +5,8 @@ public class PublicInfo
public string LocalAddress { get; set; }
public string ServerName { get; set; }
public string Version { get; set; }
/// <summary>
/// Only populated for Jellyfin
/// </summary>
public string ProductName { get; set; }

public bool IsJellyfin => !string.IsNullOrEmpty(ProductName) && ProductName.Contains("Jellyfin");

public string OperatingSystem { get; set; }
public string Id { get; set; }
}

}
}
33 changes: 33 additions & 0 deletions src/Ombi.Api.Jellyfin/IBaseJellyfinApi.cs
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Ombi.Api.Jellyfin.Models;
using Ombi.Api.Jellyfin.Models.Media.Tv;
using Ombi.Api.Jellyfin.Models.Movie;

namespace Ombi.Api.Jellyfin
{
public interface IBaseJellyfinApi
{
Task<JellyfinSystemInfo> GetSystemInformation(string apiKey, string baseUrl);
Task<List<JellyfinUser>> GetUsers(string baseUri, string apiKey);
Task<JellyfinUser> LogIn(string username, string password, string apiKey, string baseUri);

Task<JellyfinItemContainer<JellyfinMovie>> GetAllMovies(string apiKey, int startIndex, int count, string userId,
string baseUri);

Task<JellyfinItemContainer<JellyfinEpisodes>> GetAllEpisodes(string apiKey, int startIndex, int count, string userId,
string baseUri);

Task<JellyfinItemContainer<JellyfinSeries>> GetAllShows(string apiKey, int startIndex, int count, string userId,
string baseUri);

Task<JellyfinItemContainer<JellyfinMovie>> GetCollection(string mediaId,
string apiKey, string userId, string baseUrl);

Task<SeriesInformation> GetSeriesInformation(string mediaId, string apiKey, string userId, string baseUrl);
Task<MovieInformation> GetMovieInformation(string mediaId, string apiKey, string userId, string baseUrl);
Task<EpisodeInformation> GetEpisodeInformation(string mediaId, string apiKey, string userId, string baseUrl);
Task<PublicInfo> GetPublicInformation(string baseUrl);
}
}
10 changes: 10 additions & 0 deletions src/Ombi.Api.Jellyfin/IJellyfinApi.cs
@@ -0,0 +1,10 @@
using System.Threading.Tasks;
using Ombi.Api.Jellyfin.Models;

namespace Ombi.Api.Jellyfin
{
public interface IJellyfinApi : IBaseJellyfinApi
{
Task<JellyfinConnectUser> LoginConnectUser(string username, string password);
}
}
Expand Up @@ -3,14 +3,14 @@
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore.Internal;
using Newtonsoft.Json;
using Ombi.Api.Emby.Models;
using Ombi.Api.Emby.Models.Media.Tv;
using Ombi.Api.Emby.Models.Movie;
using Ombi.Api.Jellyfin.Models;
using Ombi.Api.Jellyfin.Models.Media.Tv;
using Ombi.Api.Jellyfin.Models.Movie;
using Ombi.Helpers;

namespace Ombi.Api.Emby
namespace Ombi.Api.Jellyfin
{
public class JellyfinApi : IEmbyApi
public class JellyfinApi : IJellyfinApi
{
public JellyfinApi(IApi api)
{
Expand All @@ -20,27 +20,27 @@ public JellyfinApi(IApi api)
private IApi Api { get; }

/// <summary>
/// Returns all users from the Emby Instance
/// Returns all users from the Jellyfin Instance
/// </summary>
/// <param name="baseUri"></param>
/// <param name="apiKey"></param>
public async Task<List<EmbyUser>> GetUsers(string baseUri, string apiKey)
public async Task<List<JellyfinUser>> GetUsers(string baseUri, string apiKey)
{
var request = new Request("users", baseUri, HttpMethod.Get);

AddHeaders(request, apiKey);
var obj = await Api.Request<List<EmbyUser>>(request);
var obj = await Api.Request<List<JellyfinUser>>(request);

return obj;
}

public async Task<EmbySystemInfo> GetSystemInformation(string apiKey, string baseUrl)
public async Task<JellyfinSystemInfo> GetSystemInformation(string apiKey, string baseUrl)
{
var request = new Request("System/Info", baseUrl, HttpMethod.Get);

AddHeaders(request, apiKey);

var obj = await Api.Request<EmbySystemInfo>(request);
var obj = await Api.Request<JellyfinSystemInfo>(request);

return obj;
}
Expand All @@ -56,7 +56,7 @@ public async Task<PublicInfo> GetPublicInformation(string baseUrl)
return obj;
}

public async Task<EmbyUser> LogIn(string username, string password, string apiKey, string baseUri)
public async Task<JellyfinUser> LogIn(string username, string password, string apiKey, string baseUri)
{
var request = new Request("users/authenticatebyname", baseUri, HttpMethod.Post);
var body = new
Expand All @@ -71,11 +71,11 @@ public async Task<EmbyUser> LogIn(string username, string password, string apiKe
$"MediaBrowser Client=\"Ombi\", Device=\"Ombi\", DeviceId=\"v3\", Version=\"v3\"");
AddHeaders(request, apiKey);

var obj = await Api.Request<EmbyUser>(request);
var obj = await Api.Request<JellyfinUser>(request);
return obj;
}

public async Task<EmbyItemContainer<EmbyMovie>> GetCollection(string mediaId, string apiKey, string userId, string baseUrl)
public async Task<JellyfinItemContainer<JellyfinMovie>> GetCollection(string mediaId, string apiKey, string userId, string baseUrl)
{
var request = new Request($"users/{userId}/items?parentId={mediaId}", baseUrl, HttpMethod.Get);
AddHeaders(request, apiKey);
Expand All @@ -84,22 +84,22 @@ public async Task<EmbyItemContainer<EmbyMovie>> GetCollection(string mediaId, st

request.AddQueryString("IsVirtualItem", "False");

return await Api.Request<EmbyItemContainer<EmbyMovie>>(request);
return await Api.Request<JellyfinItemContainer<JellyfinMovie>>(request);
}

public async Task<EmbyItemContainer<EmbyMovie>> GetAllMovies(string apiKey, int startIndex, int count, string userId, string baseUri)
public async Task<JellyfinItemContainer<JellyfinMovie>> GetAllMovies(string apiKey, int startIndex, int count, string userId, string baseUri)
{
return await GetAll<EmbyMovie>("Movie", apiKey, userId, baseUri, true, startIndex, count);
return await GetAll<JellyfinMovie>("Movie", apiKey, userId, baseUri, true, startIndex, count);
}

public async Task<EmbyItemContainer<EmbyEpisodes>> GetAllEpisodes(string apiKey, int startIndex, int count, string userId, string baseUri)
public async Task<JellyfinItemContainer<JellyfinEpisodes>> GetAllEpisodes(string apiKey, int startIndex, int count, string userId, string baseUri)
{
return await GetAll<EmbyEpisodes>("Episode", apiKey, userId, baseUri, false, startIndex, count);
return await GetAll<JellyfinEpisodes>("Episode", apiKey, userId, baseUri, false, startIndex, count);
}

public async Task<EmbyItemContainer<EmbySeries>> GetAllShows(string apiKey, int startIndex, int count, string userId, string baseUri)
public async Task<JellyfinItemContainer<JellyfinSeries>> GetAllShows(string apiKey, int startIndex, int count, string userId, string baseUri)
{
return await GetAll<EmbySeries>("Series", apiKey, userId, baseUri, false, startIndex, count);
return await GetAll<JellyfinSeries>("Series", apiKey, userId, baseUri, false, startIndex, count);
}

public async Task<SeriesInformation> GetSeriesInformation(string mediaId, string apiKey, string userId, string baseUrl)
Expand All @@ -126,7 +126,7 @@ private async Task<T> GetInformation<T>(string mediaId, string apiKey, string us
return JsonConvert.DeserializeObject<T>(response);
}

private async Task<EmbyItemContainer<T>> GetAll<T>(string type, string apiKey, string userId, string baseUri, bool includeOverview = false)
private async Task<JellyfinItemContainer<T>> GetAll<T>(string type, string apiKey, string userId, string baseUri, bool includeOverview = false)
{
var request = new Request($"users/{userId}/items", baseUri, HttpMethod.Get);

Expand All @@ -139,10 +139,10 @@ private async Task<EmbyItemContainer<T>> GetAll<T>(string type, string apiKey, s
AddHeaders(request, apiKey);


var obj = await Api.Request<EmbyItemContainer<T>>(request);
var obj = await Api.Request<JellyfinItemContainer<T>>(request);
return obj;
}
private async Task<EmbyItemContainer<T>> GetAll<T>(string type, string apiKey, string userId, string baseUri, bool includeOverview, int startIndex, int count)
private async Task<JellyfinItemContainer<T>> GetAll<T>(string type, string apiKey, string userId, string baseUri, bool includeOverview, int startIndex, int count)
{
var request = new Request($"users/{userId}/items", baseUri, HttpMethod.Get);

Expand All @@ -157,7 +157,7 @@ private async Task<EmbyItemContainer<T>> GetAll<T>(string type, string apiKey, s
AddHeaders(request, apiKey);


var obj = await Api.Request<EmbyItemContainer<T>>(request);
var obj = await Api.Request<JellyfinItemContainer<T>>(request);
return obj;
}

Expand All @@ -172,7 +172,7 @@ private static void AddHeaders(Request req, string apiKey)
req.AddHeader("Device", "Ombi");
}

public Task<EmbyConnectUser> LoginConnectUser(string username, string password)
public Task<JellyfinConnectUser> LoginConnectUser(string username, string password)
{
throw new System.NotImplementedException();
}
Expand Down
37 changes: 37 additions & 0 deletions src/Ombi.Api.Jellyfin/JellyfinApiFactory.cs
@@ -0,0 +1,37 @@
using Ombi.Api;
using Ombi.Core.Settings;
using Ombi.Core.Settings.Models.External;
using System.Threading.Tasks;

namespace Ombi.Api.Jellyfin
{
public class JellyfinApiFactory : IJellyfinApiFactory
{
private readonly ISettingsService<JellyfinSettings> _jellyfinSettings;
private readonly IApi _api;

// TODO, if we need to derive futher, need to rework
public JellyfinApiFactory(ISettingsService<JellyfinSettings> jellyfinSettings, IApi api)
{
_jellyfinSettings = jellyfinSettings;
_api = api;
}

public async Task<IJellyfinApi> CreateClient()
{
var settings = await _jellyfinSettings.GetSettingsAsync();
return CreateClient(settings);
}

public IJellyfinApi CreateClient(JellyfinSettings settings)
{
return new JellyfinApi(_api);
}
}

public interface IJellyfinApiFactory
{
Task<IJellyfinApi> CreateClient();
IJellyfinApi CreateClient(JellyfinSettings settings);
}
}
45 changes: 45 additions & 0 deletions src/Ombi.Api.Jellyfin/Models/JellyfinConfiguration.cs
@@ -0,0 +1,45 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2017 Jamie Rees
// File: JellyfinConfiguration.cs
// Created By: Jamie Rees
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
namespace Ombi.Api.Jellyfin.Models
{
public class JellyfinConfiguration
{
public bool PlayDefaultAudioTrack { get; set; }
public bool DisplayMissingEpisodes { get; set; }
public bool DisplayUnairedEpisodes { get; set; }
public object[] GroupedFolders { get; set; }
public string SubtitleMode { get; set; }
public bool DisplayCollectionsView { get; set; }
public bool EnableLocalPassword { get; set; }
public object[] OrderedViews { get; set; }
public object[] LatestItemsExcludes { get; set; }
public bool HidePlayedInLatest { get; set; }
public bool RememberAudioSelections { get; set; }
public bool RememberSubtitleSelections { get; set; }
public bool EnableNextEpisodeAutoPlay { get; set; }
}
}
47 changes: 47 additions & 0 deletions src/Ombi.Api.Jellyfin/Models/JellyfinConnectUser.cs
@@ -0,0 +1,47 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2017 Jamie Rees
// File: JellyfinConnectUser.cs
// Created By: Jamie Rees
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
namespace Ombi.Api.Jellyfin.Models
{
public class JellyfinConnectUser
{
public string AccessToken { get; set; }
public User User { get; set; }
}

public class User
{
public string Id { get; set; }
public string Name { get; set; }
public string DisplayName { get; set; }
public string Email { get; set; }
public string IsActive { get; set; }
public string ImageUrl { get; set; }
public object IsSupporter { get; set; }
public object ExpDate { get; set; }
}

}
10 changes: 10 additions & 0 deletions src/Ombi.Api.Jellyfin/Models/JellyfinItemContainer.cs
@@ -0,0 +1,10 @@
using System.Collections.Generic;

namespace Ombi.Api.Jellyfin.Models
{
public class JellyfinItemContainer<T>
{
public List<T> Items { get; set; }
public int TotalRecordCount { get; set; }
}
}
10 changes: 10 additions & 0 deletions src/Ombi.Api.Jellyfin/Models/JellyfinMediaType.cs
@@ -0,0 +1,10 @@
namespace Ombi.Api.Jellyfin.Models
{
public enum JellyfinMediaType
{
Movie = 0,
Series = 1,
Music = 2,
Episode = 3
}
}

0 comments on commit eedd67b

Please sign in to comment.