mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
reduce cpu cycles in parsing in producer
This commit is contained in:
@@ -101,13 +101,15 @@ public partial class DebridMediaManagerCrawler(
|
||||
return null;
|
||||
}
|
||||
|
||||
var parsedTorrent = parsingService.Parse(filenameElement.GetString());
|
||||
var torrentTitle = filenameElement.GetString();
|
||||
|
||||
if (parsedTorrent.IsInvalid)
|
||||
if (torrentTitle.IsNullOrEmpty())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var torrentType = parsingService.GetTypeByName(torrentTitle);
|
||||
|
||||
var torrent = new Torrent
|
||||
{
|
||||
Source = Source,
|
||||
@@ -117,48 +119,52 @@ public partial class DebridMediaManagerCrawler(
|
||||
Leechers = 0,
|
||||
};
|
||||
|
||||
return parsedTorrent.Type switch
|
||||
return torrentType switch
|
||||
{
|
||||
TorrentType.Movie => HandleMovieType(torrent, parsedTorrent),
|
||||
TorrentType.Tv => HandleTvType(torrent, parsedTorrent),
|
||||
TorrentType.Movie => HandleMovieType(torrent, torrentTitle),
|
||||
TorrentType.Tv => HandleTvType(torrent, torrentTitle),
|
||||
_ => null,
|
||||
};
|
||||
}
|
||||
|
||||
private Torrent HandleMovieType(Torrent torrent, ParsedFilename parsedTorrent)
|
||||
private Torrent HandleMovieType(Torrent torrent, string title)
|
||||
{
|
||||
if (parsedTorrent.Movie.ReleaseTitle.IsNullOrEmpty())
|
||||
if (title.IsNullOrEmpty())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!parsingService.HasNoBannedTerms(parsedTorrent.Movie.ReleaseTitle))
|
||||
if (!parsingService.HasNoBannedTerms(title))
|
||||
{
|
||||
LogBannedTermsFound(torrent);
|
||||
return null;
|
||||
}
|
||||
|
||||
torrent.Category = "movies";
|
||||
torrent.Name = parsedTorrent.Movie.ReleaseTitle;
|
||||
torrent.Name = title;
|
||||
return torrent;
|
||||
}
|
||||
|
||||
private Torrent HandleTvType(Torrent torrent, ParsedFilename parsedTorrent)
|
||||
private Torrent HandleTvType(Torrent torrent, string title)
|
||||
{
|
||||
if (parsedTorrent.Show.ReleaseTitle.IsNullOrEmpty())
|
||||
if (title.IsNullOrEmpty())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!parsingService.HasNoBannedTerms(parsedTorrent.Show.ReleaseTitle))
|
||||
if (!parsingService.HasNoBannedTerms(title))
|
||||
{
|
||||
LogBannedTermsFound(torrent);
|
||||
return null;
|
||||
}
|
||||
|
||||
torrent.Category = "tv";
|
||||
torrent.Name = parsedTorrent.Show.ReleaseTitle;
|
||||
torrent.Name = title;
|
||||
return torrent;
|
||||
}
|
||||
|
||||
private void LogBannedTermsFound(Torrent torrent) => logger.LogWarning("Banned terms found in torrent title for ingested infoHash: {InfoHash}. Skipping", torrent.InfoHash);
|
||||
|
||||
private async Task InsertTorrentsForPage(JsonDocument json)
|
||||
{
|
||||
var torrents = json.RootElement.EnumerateArray()
|
||||
|
||||
@@ -2,6 +2,7 @@ namespace Producer.Features.ParseTorrentTitle;
|
||||
|
||||
public interface IParsingService
|
||||
{
|
||||
TorrentType GetTypeByName(string name);
|
||||
ParsedFilename Parse(string name);
|
||||
string Naked(string title);
|
||||
List<string> GrabYears(string str);
|
||||
|
||||
@@ -3,4 +3,5 @@ namespace Producer.Features.ParseTorrentTitle;
|
||||
public interface ITorrentTitleParser
|
||||
{
|
||||
ParsedFilename Parse(string name);
|
||||
TorrentType GetTypeByName(string name);
|
||||
}
|
||||
|
||||
@@ -347,4 +347,6 @@ public partial class ParsingService(IWordCollections wordCollections, ITorrentTi
|
||||
}
|
||||
|
||||
public ParsedFilename Parse(string name) => torrentTitleParser.Parse(name);
|
||||
|
||||
public TorrentType GetTypeByName(string name) => torrentTitleParser.GetTypeByName(name);
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ public partial class TorrentTitleParser : ITorrentTitleParser
|
||||
};
|
||||
}
|
||||
|
||||
private static TorrentType GetTypeByName(string name)
|
||||
public TorrentType GetTypeByName(string name)
|
||||
{
|
||||
var tvRegexes = new[]
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user