From 2c788cc0c3e024baeaff949d8261545a18053507 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Tue, 31 Mar 2020 15:56:37 +0100 Subject: [PATCH] Fixed #3455 --- src/Ombi.Helpers.Tests/EmbyHelperTests.cs | 46 +++++++++++++++++++++++ src/Ombi.Helpers/EmbyHelper.cs | 12 ++++-- 2 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 src/Ombi.Helpers.Tests/EmbyHelperTests.cs diff --git a/src/Ombi.Helpers.Tests/EmbyHelperTests.cs b/src/Ombi.Helpers.Tests/EmbyHelperTests.cs new file mode 100644 index 000000000..746bd1d5f --- /dev/null +++ b/src/Ombi.Helpers.Tests/EmbyHelperTests.cs @@ -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 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 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"); + } + } + } +} diff --git a/src/Ombi.Helpers/EmbyHelper.cs b/src/Ombi.Helpers/EmbyHelper.cs index e22bb1d99..61716cd4b 100644 --- a/src/Ombi.Helpers/EmbyHelper.cs +++ b/src/Ombi.Helpers/EmbyHelper.cs @@ -4,18 +4,22 @@ { public static string GetEmbyMediaUrl(string mediaId, string customerServerUrl = null, bool isJellyfin = false) { - string path = "item/item"; + string path = "item"; if (isJellyfin) { - path = "itemdetails"; + path = "itemdetails.html"; } if (customerServerUrl.HasValue()) { - return $"{customerServerUrl}#!/{path}.html?id={mediaId}"; + if (!customerServerUrl.EndsWith("/")) + { + return $"{customerServerUrl}/#!/{path}?id={mediaId}"; + } + return $"{customerServerUrl}#!/{path}?id={mediaId}"; } else { - return $"https://app.emby.media/#!/{path}.html?id={mediaId}"; + return $"https://app.emby.media/#!/{path}?id={mediaId}"; } } }