Merge pull request #144 from Gabisonfire/reduce_cpu_cycles
reduce cpu cycles in parsing in producer
This commit is contained in:
@@ -101,13 +101,15 @@ public partial class DebridMediaManagerCrawler(
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var parsedTorrent = parsingService.Parse(filenameElement.GetString());
|
var torrentTitle = filenameElement.GetString();
|
||||||
|
|
||||||
if (parsedTorrent.IsInvalid)
|
if (torrentTitle.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var torrentType = parsingService.GetTypeByName(torrentTitle);
|
||||||
|
|
||||||
var torrent = new Torrent
|
var torrent = new Torrent
|
||||||
{
|
{
|
||||||
Source = Source,
|
Source = Source,
|
||||||
@@ -117,48 +119,52 @@ public partial class DebridMediaManagerCrawler(
|
|||||||
Leechers = 0,
|
Leechers = 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
return parsedTorrent.Type switch
|
return torrentType switch
|
||||||
{
|
{
|
||||||
TorrentType.Movie => HandleMovieType(torrent, parsedTorrent),
|
TorrentType.Movie => HandleMovieType(torrent, torrentTitle),
|
||||||
TorrentType.Tv => HandleTvType(torrent, parsedTorrent),
|
TorrentType.Tv => HandleTvType(torrent, torrentTitle),
|
||||||
_ => null,
|
_ => 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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!parsingService.HasNoBannedTerms(parsedTorrent.Movie.ReleaseTitle))
|
if (!parsingService.HasNoBannedTerms(title))
|
||||||
{
|
{
|
||||||
|
LogBannedTermsFound(torrent);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
torrent.Category = "movies";
|
torrent.Category = "movies";
|
||||||
torrent.Name = parsedTorrent.Movie.ReleaseTitle;
|
torrent.Name = title;
|
||||||
return torrent;
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!parsingService.HasNoBannedTerms(parsedTorrent.Show.ReleaseTitle))
|
if (!parsingService.HasNoBannedTerms(title))
|
||||||
{
|
{
|
||||||
|
LogBannedTermsFound(torrent);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
torrent.Category = "tv";
|
torrent.Category = "tv";
|
||||||
torrent.Name = parsedTorrent.Show.ReleaseTitle;
|
torrent.Name = title;
|
||||||
return torrent;
|
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)
|
private async Task InsertTorrentsForPage(JsonDocument json)
|
||||||
{
|
{
|
||||||
var torrents = json.RootElement.EnumerateArray()
|
var torrents = json.RootElement.EnumerateArray()
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ namespace Producer.Features.ParseTorrentTitle;
|
|||||||
|
|
||||||
public interface IParsingService
|
public interface IParsingService
|
||||||
{
|
{
|
||||||
|
TorrentType GetTypeByName(string name);
|
||||||
ParsedFilename Parse(string name);
|
ParsedFilename Parse(string name);
|
||||||
string Naked(string title);
|
string Naked(string title);
|
||||||
List<string> GrabYears(string str);
|
List<string> GrabYears(string str);
|
||||||
|
|||||||
@@ -3,4 +3,5 @@ namespace Producer.Features.ParseTorrentTitle;
|
|||||||
public interface ITorrentTitleParser
|
public interface ITorrentTitleParser
|
||||||
{
|
{
|
||||||
ParsedFilename Parse(string name);
|
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 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[]
|
var tvRegexes = new[]
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user