This commit is contained in:
tidusjar 2020-03-31 15:56:37 +01:00 committed by Pawndev
commit 2c788cc0c3
2 changed files with 54 additions and 4 deletions

View file

@ -0,0 +1,46 @@
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Text;
namespace Ombi.Helpers.Tests
{
[TestFixture]
public class EmbyHelperTests
{
[TestCaseSource(nameof(UrlData))]
public string TestUrl(string mediaId, string url)
{
return EmbyHelper.GetEmbyMediaUrl(mediaId, url);
}
[TestCaseSource(nameof(JellyfinUrlData))]
public string TestJellyfinUrl(string mediaId, string url)
{
return EmbyHelper.GetEmbyMediaUrl(mediaId, url, true);
}
public static IEnumerable<TestCaseData> UrlData
{
get
{
var mediaId = 1;
yield return new TestCaseData(mediaId.ToString(), "http://google.com").Returns($"http://google.com/#!/item?id={mediaId}").SetName("EmbyHelper_GetMediaUrl_WithCustomDomain_WithoutTrailingSlash");
yield return new TestCaseData(mediaId.ToString(), "http://google.com/").Returns($"http://google.com/#!/item?id={mediaId}").SetName("EmbyHelper_GetMediaUrl_WithCustomDomain");
yield return new TestCaseData(mediaId.ToString(), "https://google.com/").Returns($"https://google.com/#!/item?id={mediaId}").SetName("EmbyHelper_GetMediaUrl_WithCustomDomain_Https");
yield return new TestCaseData(mediaId.ToString(), string.Empty).Returns($"https://app.emby.media/#!/item?id={mediaId}").SetName("EmbyHelper_GetMediaUrl_WithOutCustomDomain");
}
}
public static IEnumerable<TestCaseData> JellyfinUrlData
{
get
{
var mediaId = 1;
yield return new TestCaseData(mediaId.ToString(), "http://google.com").Returns($"http://google.com/#!/itemdetails.html?id={mediaId}").SetName("EmbyHelperJellyfin_GetMediaUrl_WithCustomDomain_WithoutTrailingSlash");
yield return new TestCaseData(mediaId.ToString(), "http://google.com/").Returns($"http://google.com/#!/itemdetails.html?id={mediaId}").SetName("EmbyHelperJellyfin_GetMediaUrl_WithCustomDomain");
yield return new TestCaseData(mediaId.ToString(), "https://google.com/").Returns($"https://google.com/#!/itemdetails.html?id={mediaId}").SetName("EmbyHelperJellyfin_GetMediaUrl_WithCustomDomain_Https");
}
}
}
}

View file

@ -4,18 +4,22 @@
{ {
public static string GetEmbyMediaUrl(string mediaId, string customerServerUrl = null, bool isJellyfin = false) public static string GetEmbyMediaUrl(string mediaId, string customerServerUrl = null, bool isJellyfin = false)
{ {
string path = "item/item"; string path = "item";
if (isJellyfin) if (isJellyfin)
{ {
path = "itemdetails"; path = "itemdetails.html";
} }
if (customerServerUrl.HasValue()) if (customerServerUrl.HasValue())
{ {
return $"{customerServerUrl}#!/{path}.html?id={mediaId}"; if (!customerServerUrl.EndsWith("/"))
{
return $"{customerServerUrl}/#!/{path}?id={mediaId}";
}
return $"{customerServerUrl}#!/{path}?id={mediaId}";
} }
else else
{ {
return $"https://app.emby.media/#!/{path}.html?id={mediaId}"; return $"https://app.emby.media/#!/{path}?id={mediaId}";
} }
} }
} }