Merge pull request #3477 from pawndev/fix/emby-wrong-url

Fixed #3455
This commit is contained in:
Jamie 2020-04-07 00:08:19 +01:00 committed by GitHub
commit 0e6c38f231
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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)
{
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}";
}
}
}