Fixing bugs with the crawler that keep appening, cleaning the regex

This commit is contained in:
Zoe Roux 2020-06-18 23:48:38 +02:00
parent 7be4133af9
commit 74fabb11ea
6 changed files with 31 additions and 19 deletions

View File

@ -1,10 +1,11 @@
using Newtonsoft.Json; using Newtonsoft.Json;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Kyoo.Models.Attributes;
namespace Kyoo.Models namespace Kyoo.Models
{ {
public class Episode public class Episode : IOnMerge
{ {
[JsonIgnore] public int ID { get; set; } [JsonIgnore] public int ID { get; set; }
[JsonIgnore] public int ShowID { get; set; } [JsonIgnore] public int ShowID { get; set; }
@ -12,9 +13,9 @@ namespace Kyoo.Models
[JsonIgnore] public int? SeasonID { get; set; } [JsonIgnore] public int? SeasonID { get; set; }
[JsonIgnore] public virtual Season Season { get; set; } [JsonIgnore] public virtual Season Season { get; set; }
public int SeasonNumber { get; set; } public int SeasonNumber { get; set; } = -1;
public int EpisodeNumber { get; set; } public int EpisodeNumber { get; set; } = -1;
public int AbsoluteNumber { get; set; } public int AbsoluteNumber { get; set; } = -1;
[JsonIgnore] public string Path { get; set; } [JsonIgnore] public string Path { get; set; }
public string Title { get; set; } public string Title { get; set; }
public string Overview { get; set; } public string Overview { get; set; }
@ -94,5 +95,16 @@ namespace Kyoo.Models
{ {
return showSlug + "-s" + seasonNumber + "e" + episodeNumber; return showSlug + "-s" + seasonNumber + "e" + episodeNumber;
} }
public void OnMerge(object merged)
{
Episode other = (Episode)merged;
if (SeasonNumber == -1 && other.SeasonNumber != -1)
SeasonNumber = other.SeasonNumber;
if (EpisodeNumber == -1 && other.EpisodeNumber != -1)
EpisodeNumber = other.EpisodeNumber;
if (AbsoluteNumber == -1 && other.AbsoluteNumber != -1)
AbsoluteNumber = other.AbsoluteNumber;
}
} }
} }

View File

@ -9,6 +9,7 @@ using System.Text.RegularExpressions;
using JetBrains.Annotations; using JetBrains.Annotations;
using Kyoo.Models; using Kyoo.Models;
using Kyoo.Models.Attributes; using Kyoo.Models.Attributes;
using Microsoft.VisualBasic;
namespace Kyoo namespace Kyoo
{ {
@ -93,7 +94,6 @@ namespace Kyoo
public static T Merge<T>(T first, T second) public static T Merge<T>(T first, T second)
{ {
// TODO During the merge, reference to the second values are not set to the first value (for child objects).
if (first == null) if (first == null)
return second; return second;
if (second == null) if (second == null)
@ -124,8 +124,8 @@ namespace Kyoo
} }
} }
if (first is IOnMerge) if (first is IOnMerge merge)
((IOnMerge)first).OnMerge(second); merge.OnMerge(second);
return first; return first;
} }

View File

@ -147,7 +147,7 @@ namespace Kyoo.Controllers
string showPath = Path.GetDirectoryName(path); string showPath = Path.GetDirectoryName(path);
string collectionName = match.Groups["Collection"]?.Value; string collectionName = match.Groups["Collection"]?.Value;
string showName = match.Groups["ShowTitle"].Value; string showName = match.Groups["Show"].Value;
int seasonNumber = int.TryParse(match.Groups["Season"].Value, out int tmp) ? tmp : -1; int seasonNumber = int.TryParse(match.Groups["Season"].Value, out int tmp) ? tmp : -1;
int episodeNumber = int.TryParse(match.Groups["Episode"].Value, out tmp) ? tmp : -1; int episodeNumber = int.TryParse(match.Groups["Episode"].Value, out tmp) ? tmp : -1;
int absoluteNumber = int.TryParse(match.Groups["Absolute"].Value, out tmp) ? tmp : -1; int absoluteNumber = int.TryParse(match.Groups["Absolute"].Value, out tmp) ? tmp : -1;
@ -272,12 +272,6 @@ namespace Kyoo.Controllers
season ??= await GetSeason(libraryManager, show, episode.SeasonNumber, library); season ??= await GetSeason(libraryManager, show, episode.SeasonNumber, library);
episode.Season = season; episode.Season = season;
episode.SeasonID = season?.ID; episode.SeasonID = season?.ID;
if (season == null)
{
await Console.Error.WriteLineAsync("Error: You don't have any provider that support absolute epiode numbering. Install one and try again.");
return default;
}
await _thumbnailsManager.Validate(episode); await _thumbnailsManager.Validate(episode);
await GetTracks(episode); await GetTracks(episode);
return episode; return episode;

View File

@ -9,7 +9,8 @@
"Microsoft": "Warning", "Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information", "Microsoft.Hosting.Lifetime": "Information",
"Microsoft.EntityFrameworkCore.DbUpdateException": "None", "Microsoft.EntityFrameworkCore.DbUpdateException": "None",
"Microsoft.EntityFrameworkCore.Update": "None" "Microsoft.EntityFrameworkCore.Update": "None",
"Microsoft.EntityFrameworkCore.Database.Command": "None"
} }
}, },
"AllowedHosts": "*", "AllowedHosts": "*",
@ -32,5 +33,5 @@
"plugins": "plugins/", "plugins": "plugins/",
"defaultPermissions": "read,play,write,admin", "defaultPermissions": "read,play,write,admin",
"newUserPermissions": "read,play,write,admin", "newUserPermissions": "read,play,write,admin",
"regex": "(\\/(?<Collection>.*)\\/)?.*\\/(?<ShowTitle>.+?)( \\(\\d*\\))?(( S(?<Season>\\d+)E(?<Episode>\\d+)| (?<Absolute>\\d+)))?\\." "regex": "(?:\\/(?<Collection>.*?))?\\/(?<Show>.*)(?: \\(\\d+\\))?\\/\\k<Show>(?: \\(\\d+\\))?(?:(?: S(?<Season>\\d+)E(?<Episode>\\d+))| (?<Absolute>\\d+))?.*$"
} }

View File

@ -1,4 +1,4 @@
#!/usr/bin/bash #!/usr/bin/bash
cd /opt/kyoo cd /opt/kyoo || exit 1
dotnet Kyoo.dll dotnet Kyoo.dll

5
Kyoo/regexTesterr.sh Executable file
View File

@ -0,0 +1,5 @@
#! /usr/bin/bash
REGEX="(?:\/(?<Collection>.*?))?\/(?<ShowTitle>.*)(?: \(\d+\))?\/\k<ShowTitle>(?: \(\d+\))?(?:(?: S(?<SeasonNumber>\d+)E(?<EpisodeNumber>\d+))| (?<AbsoluteNumber>\d+))?.*$"
find "$1" -type f \( -name '*.mp4' -o -name '*.mkv' \) | cut -c $((${#1} + 1))- | grep -viP "$REGEX"