mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-09 03:04:20 -04:00
Refactorying a bit
This commit is contained in:
parent
c0ab6f898a
commit
899adb2b9d
@ -11,6 +11,7 @@
|
||||
<Company>SDG</Company>
|
||||
<PackageLicenseExpression>GPL-3.0-or-later</PackageLicenseExpression>
|
||||
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
|
||||
<PackageVersion>1.0.2</PackageVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -2,7 +2,6 @@
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Kyoo.Utility;
|
||||
|
||||
namespace Kyoo.Models
|
||||
{
|
||||
|
@ -1,6 +1,5 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using Kyoo.Utility;
|
||||
|
||||
namespace Kyoo.Models
|
||||
{
|
||||
|
@ -1,5 +1,4 @@
|
||||
using Kyoo.Utility;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Kyoo.Models
|
||||
{
|
||||
|
@ -1,6 +1,4 @@
|
||||
using System.Linq;
|
||||
using Kyoo.Utility;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Kyoo.Models
|
||||
{
|
||||
|
@ -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;
|
||||
|
62
Kyoo.Common/Utility.cs
Normal file
62
Kyoo.Common/Utility.cs
Normal file
@ -0,0 +1,62 @@
|
||||
using System.Text.RegularExpressions;
|
||||
using Kyoo.Models;
|
||||
|
||||
namespace Kyoo
|
||||
{
|
||||
public interface IMergable<T>
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Kyoo.Utility
|
||||
{
|
||||
public interface IMergable<T>
|
||||
{
|
||||
public T Merge(T other);
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
@ -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
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user