From d80565f6a9b045f2e8de594eda0d2ce51ea497bd Mon Sep 17 00:00:00 2001 From: Stevie Robinson Date: Mon, 20 Dec 2021 21:26:51 +0100 Subject: [PATCH] Fixed: Convert Trakt list name to URL slug --- .../Extensions/StringExtensions.cs | 23 +++++++++++++++++++ .../Trakt/List/TraktListRequestGenerator.cs | 4 +--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/NzbDrone.Common/Extensions/StringExtensions.cs b/src/NzbDrone.Common/Extensions/StringExtensions.cs index b7d058657..827a34aa3 100644 --- a/src/NzbDrone.Common/Extensions/StringExtensions.cs +++ b/src/NzbDrone.Common/Extensions/StringExtensions.cs @@ -165,5 +165,28 @@ namespace NzbDrone.Common.Extensions { return source.Contains(value, StringComparer.InvariantCultureIgnoreCase); } + + public static string ToUrlSlug(this string value) + { + //First to lower case + value = value.ToLowerInvariant(); + + //Remove all accents + value = value.RemoveAccent(); + + //Replace spaces + value = Regex.Replace(value, @"\s", "-", RegexOptions.Compiled); + + //Remove invalid chars + value = Regex.Replace(value, @"[^a-z0-9\s-_]", "", RegexOptions.Compiled); + + //Trim dashes from end + value = value.Trim('-', '_'); + + //Replace double occurences of - or _ + value = Regex.Replace(value, @"([-_]){2,}", "$1", RegexOptions.Compiled); + + return value; + } } } diff --git a/src/NzbDrone.Core/ImportLists/Trakt/List/TraktListRequestGenerator.cs b/src/NzbDrone.Core/ImportLists/Trakt/List/TraktListRequestGenerator.cs index d268c25c0..da666cc3f 100644 --- a/src/NzbDrone.Core/ImportLists/Trakt/List/TraktListRequestGenerator.cs +++ b/src/NzbDrone.Core/ImportLists/Trakt/List/TraktListRequestGenerator.cs @@ -26,9 +26,7 @@ namespace NzbDrone.Core.ImportLists.Trakt.List { var link = Settings.BaseUrl.Trim(); - var listName = Settings.Listname.Trim(); - - link += $"/users/{Settings.Username.Trim()}/lists/{listName}/items/shows?limit={Settings.Limit}"; + link += $"/users/{Settings.Username.Trim()}/lists/{Settings.Listname.ToUrlSlug()}/items/shows?limit={Settings.Limit}"; var request = new ImportListRequest($"{link}", HttpAccept.Json);