reduce cpu cycles in parsing in producer

This commit is contained in:
iPromKnight
2024-03-10 15:14:17 +00:00
parent f18cd5b1ac
commit 02150482df
5 changed files with 24 additions and 14 deletions

View File

@@ -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()

View File

@@ -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);

View File

@@ -3,4 +3,5 @@ namespace Producer.Features.ParseTorrentTitle;
public interface ITorrentTitleParser
{
ParsedFilename Parse(string name);
TorrentType GetTypeByName(string name);
}

View File

@@ -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);
}

View File

@@ -117,7 +117,7 @@ public partial class TorrentTitleParser : ITorrentTitleParser
};
}
private static TorrentType GetTypeByName(string name)
public TorrentType GetTypeByName(string name)
{
var tvRegexes = new[]
{