Reworking the crawler to use only one regex and adding movies support

This commit is contained in:
Zoe Roux 2020-02-13 22:48:37 +01:00
parent eb0aa23293
commit e5bb71084b
3 changed files with 21 additions and 29 deletions

View File

@ -27,6 +27,8 @@ namespace Kyoo.Models
public string ExternalIDs { get; set; }
public bool IsMovie { get; set; }
public bool IsCollection;
[JsonIgnore] public virtual IEnumerable<Genre> Genres

View File

@ -68,6 +68,7 @@ namespace Kyoo.Controllers
private async Task RegisterFile(string path, string relativePath, Library library)
{
Console.WriteLine("Registering episode at: " + path);
string patern = _config.GetValue<string>("regex");
Regex regex = new Regex(patern, RegexOptions.IgnoreCase);
Match match = regex.Match(relativePath);
@ -75,35 +76,23 @@ namespace Kyoo.Controllers
string showPath = Path.GetDirectoryName(path);
string collectionName = match.Groups["Collection"]?.Value;
string showName = match.Groups["ShowTitle"].Value;
bool seasonSuccess = long.TryParse(match.Groups["Season"].Value, out long seasonNumber);
bool episodeSucess = long.TryParse(match.Groups["Episode"].Value, out long episodeNumber);
long absoluteNumber = -1;
Console.WriteLine("Registering episode at: " + path);
if (!seasonSuccess || !episodeSucess)
{
//Considering that the episode is using absolute path.
seasonNumber = -1;
episodeNumber = -1;
regex = new Regex(_config.GetValue<string>("absoluteRegex"));
match = regex.Match(relativePath);
showName = match.Groups["ShowTitle"].Value;
bool absoluteSucess = long.TryParse(match.Groups["AbsoluteNumber"].Value, out absoluteNumber);
if (!absoluteSucess)
{
Console.Error.WriteLine("Couldn't find basic data for the episode (regexs didn't match) " + relativePath);
return;
}
}
long seasonNumber = long.TryParse(match.Groups["Season"].Value, out long tmp) ? tmp : -1;
long episodeNumber = long.TryParse(match.Groups["Episode"].Value, out tmp) ? tmp : -1;
long absoluteNumber = long.TryParse(match.Groups["Absolute"].Value, out tmp) ? tmp : -1;
Collection collection = await GetCollection(collectionName, library);
Show show = await GetShow(showName, showPath, library);
Season season = seasonNumber != -1 ? await GetSeason(show, seasonNumber, library) : null;
Episode episode = await GetEpisode(show, season, episodeNumber, absoluteNumber, path, library);
_libraryManager.RegisterEpisode(episode);
if (seasonNumber == -1 && episodeNumber == -1 && absoluteNumber == -1)
{
show.IsMovie = true;
_libraryManager.RegisterShow(show);
}
else
{
Season season = await GetSeason(show, seasonNumber, library);
Episode episode = await GetEpisode(show, season, episodeNumber, absoluteNumber, path, library);
_libraryManager.RegisterEpisode(episode);
}
_libraryManager.RegisterShowLinks(library, collection, show);
}
@ -131,6 +120,8 @@ namespace Kyoo.Controllers
private async Task<Season> GetSeason(Show show, long seasonNumber, Library library)
{
if (seasonNumber == -1)
return null;
Season season = _libraryManager.GetSeason(show.Slug, seasonNumber);
if (season != null)
return await Task.FromResult(season);

View File

@ -16,6 +16,5 @@
"transcodeTempPath": "/tmp/cached/kyoo/transcode",
"peoplePath": "/tmp/people",
"plugins": "plugins/",
"regex": "^(\\/(?<Collection>.+?))?\\/.*\\/(?<ShowTitle>.+?) S(?<Season>\\d+)E(?<Episode>\\d+)",
"absoluteRegex": ".*\\/(?<ShowTitle>.+?) (?<AbsoluteNumber>\\d+)"
"regex": "(\\/(?<Collection>.*)\\/)?.*\\/(?<ShowTitle>.+?)(( S(?<Season>\\d+)E(?<Episode>\\d+)| (?<Absolute>\\d+)))?\\.",
}