diff --git a/Kyoo.Common/Kyoo.Common.csproj b/Kyoo.Common/Kyoo.Common.csproj index 9f34812e..ab4dc7c5 100644 --- a/Kyoo.Common/Kyoo.Common.csproj +++ b/Kyoo.Common/Kyoo.Common.csproj @@ -11,6 +11,7 @@ SDG GPL-3.0-or-later true + 1.0.2 diff --git a/Kyoo.Common/Models/Collection.cs b/Kyoo.Common/Models/Collection.cs index 81ade2a7..fb1c6d59 100644 --- a/Kyoo.Common/Models/Collection.cs +++ b/Kyoo.Common/Models/Collection.cs @@ -2,7 +2,6 @@ using Newtonsoft.Json; using System.Collections.Generic; using System.Linq; -using Kyoo.Utility; namespace Kyoo.Models { diff --git a/Kyoo.Common/Models/Episode.cs b/Kyoo.Common/Models/Episode.cs index c7d53dbc..ba75b521 100644 --- a/Kyoo.Common/Models/Episode.cs +++ b/Kyoo.Common/Models/Episode.cs @@ -1,6 +1,5 @@ using Newtonsoft.Json; using System; -using Kyoo.Utility; namespace Kyoo.Models { diff --git a/Kyoo.Common/Models/People.cs b/Kyoo.Common/Models/People.cs index abb44c53..0626e75e 100644 --- a/Kyoo.Common/Models/People.cs +++ b/Kyoo.Common/Models/People.cs @@ -1,5 +1,4 @@ -using Kyoo.Utility; -using Newtonsoft.Json; +using Newtonsoft.Json; namespace Kyoo.Models { diff --git a/Kyoo.Common/Models/Season.cs b/Kyoo.Common/Models/Season.cs index 6c9133f1..bc149ee3 100644 --- a/Kyoo.Common/Models/Season.cs +++ b/Kyoo.Common/Models/Season.cs @@ -1,6 +1,4 @@ -using System.Linq; -using Kyoo.Utility; -using Newtonsoft.Json; +using Newtonsoft.Json; namespace Kyoo.Models { diff --git a/Kyoo.Common/Models/Show.cs b/Kyoo.Common/Models/Show.cs index bd179283..34d3016d 100644 --- a/Kyoo.Common/Models/Show.cs +++ b/Kyoo.Common/Models/Show.cs @@ -1,8 +1,8 @@ -using Kyoo.Controllers; +using System; +using Kyoo.Controllers; using Newtonsoft.Json; using System.Collections.Generic; using System.Linq; -using Kyoo.Utility; namespace Kyoo.Models { @@ -127,6 +127,14 @@ namespace Kyoo.Models reader["externalIDs"] as string); } + public string GetID(string provider) + { + if (ExternalIDs?.Contains(provider) != true) + return null; + int startIndex = ExternalIDs.IndexOf(provider, StringComparison.Ordinal) + provider.Length + 1; //The + 1 is for the '=' + return ExternalIDs.Substring(startIndex, ExternalIDs.IndexOf('|', startIndex) - startIndex); + } + public Show Set(string slug, string path) { Slug = slug; diff --git a/Kyoo.Common/Utility.cs b/Kyoo.Common/Utility.cs new file mode 100644 index 00000000..e161e132 --- /dev/null +++ b/Kyoo.Common/Utility.cs @@ -0,0 +1,62 @@ +using System.Text.RegularExpressions; +using Kyoo.Models; + +namespace Kyoo +{ + public interface IMergable + { + public T Merge(T other); + } + + public static class Utility + { + public static string ToSlug(string name) + { + if (name == null) + return null; + + //First to lower case + name = name.ToLowerInvariant(); + + //Remove all accents + //var bytes = Encoding.GetEncoding("Cyrillic").GetBytes(showTitle); + //showTitle = Encoding.ASCII.GetString(bytes); + + //Replace spaces + name = Regex.Replace(name, @"\s", "-", RegexOptions.Compiled); + + //Remove invalid chars + name = Regex.Replace(name, @"[^\w\s\p{Pd}]", "", RegexOptions.Compiled); + + //Trim dashes from end + name = name.Trim('-', '_'); + + //Replace double occurences of - or \_ + name = Regex.Replace(name, @"([-_]){2,}", "$1", RegexOptions.Compiled); + + return name; + } + + + public static void SetImage(Show show, string imgUrl, ImageType type) + { + switch(type) + { + case ImageType.Poster: + show.ImgPrimary = imgUrl; + break; + case ImageType.Thumbnail: + show.ImgThumb = imgUrl; + break; + case ImageType.Logo: + show.ImgLogo = imgUrl; + break; + case ImageType.Background: + show.ImgBackdrop = imgUrl; + break; + default: + break; + } + } + } +} \ No newline at end of file diff --git a/Kyoo.Common/Utility/IMergable.cs b/Kyoo.Common/Utility/IMergable.cs deleted file mode 100644 index 3c56420b..00000000 --- a/Kyoo.Common/Utility/IMergable.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System.Collections.Generic; - -namespace Kyoo.Utility -{ - public interface IMergable - { - public T Merge(T other); - } -} \ No newline at end of file diff --git a/Kyoo.Common/Utility/ImageHelper.cs b/Kyoo.Common/Utility/ImageHelper.cs deleted file mode 100644 index d75bd30d..00000000 --- a/Kyoo.Common/Utility/ImageHelper.cs +++ /dev/null @@ -1,28 +0,0 @@ -using Kyoo.Models; - -namespace Kyoo.Controllers.Utility -{ - public static class ImageHelper - { - public static void SetImage(Show show, string imgUrl, ImageType type) - { - switch(type) - { - case ImageType.Poster: - show.ImgPrimary = imgUrl; - break; - case ImageType.Thumbnail: - show.ImgThumb = imgUrl; - break; - case ImageType.Logo: - show.ImgLogo = imgUrl; - break; - case ImageType.Background: - show.ImgBackdrop = imgUrl; - break; - default: - break; - } - } - } -} \ No newline at end of file diff --git a/Kyoo.Common/Utility/Slugifier.cs b/Kyoo.Common/Utility/Slugifier.cs deleted file mode 100644 index 22cbc4f3..00000000 --- a/Kyoo.Common/Utility/Slugifier.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System.Text.RegularExpressions; - -namespace Kyoo.Controllers.Utility -{ - public class Slugifier - { - public static string ToSlug(string showTitle) - { - if (showTitle == null) - return null; - - //First to lower case - showTitle = showTitle.ToLowerInvariant(); - - //Remove all accents - //var bytes = Encoding.GetEncoding("Cyrillic").GetBytes(showTitle); - //showTitle = Encoding.ASCII.GetString(bytes); - - //Replace spaces - showTitle = Regex.Replace(showTitle, @"\s", "-", RegexOptions.Compiled); - - //Remove invalid chars - showTitle = Regex.Replace(showTitle, @"[^\w\s\p{Pd}]", "", RegexOptions.Compiled); - - //Trim dashes from end - showTitle = showTitle.Trim('-', '_'); - - //Replace double occurences of - or \_ - showTitle = Regex.Replace(showTitle, @"([-_]){2,}", "$1", RegexOptions.Compiled); - - return showTitle; - } - } -} diff --git a/Kyoo/Controllers/Crawler.cs b/Kyoo/Controllers/Crawler.cs index 80e25dac..d67ba985 100644 --- a/Kyoo/Controllers/Crawler.cs +++ b/Kyoo/Controllers/Crawler.cs @@ -7,7 +7,6 @@ using System.Linq; using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; -using Kyoo.Controllers.Utility; using Kyoo.Models.Watch; namespace Kyoo.Controllers @@ -141,7 +140,7 @@ namespace Kyoo.Controllers libraryManager.RegisterInLibrary(showID, library); if (!string.IsNullOrEmpty(collectionName)) { - if (!libraryManager.IsCollectionRegistered(Slugifier.ToSlug(collectionName), out long collectionID)) + if (!libraryManager.IsCollectionRegistered(Utility.ToSlug(collectionName), out long collectionID)) { Collection collection = await metadataProvider.GetCollectionFromName(collectionName, library); collectionID = libraryManager.RegisterCollection(collection); diff --git a/Kyoo/Controllers/ProviderManager.cs b/Kyoo/Controllers/ProviderManager.cs index f1b2b542..8aeba1cf 100644 --- a/Kyoo/Controllers/ProviderManager.cs +++ b/Kyoo/Controllers/ProviderManager.cs @@ -4,7 +4,6 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Kyoo.Controllers.ThumbnailsManager; -using Kyoo.Utility; namespace Kyoo.Controllers {