Skip to content

Commit

Permalink
This is quick workaround for the issue "Torrent size as hard filterin…
Browse files Browse the repository at this point in the history
…g criteria autodl-community#201"

autodl-community#201 (comment)

The fix is designed to bring minimum changes to the flow and as well as to achieve the end result
Two major changes
1. Filter manager performs a soft check on torrent size. When "torrentSizeInBytes" is not defined, treats the condition as satisfied, if defined checks the condition.
2. MatchedRelease when size condition is not met instead of aborting the process triggers the filter check and download process again with additional information of "torrentSizeInBytes"

Short comings of the fix
1. Under certain conditions torrent file is downloaded twice. 2nd download of torrent file certainly leads to an action.
2. Time and computation wasted in rechecking the filter

Possible improvements
1. Avoid downloading torrent file again, if it is available in temp
2. Parse torrentSizeInBytes from IRC announcement wherever possible
  • Loading branch information
satcos committed Jul 19, 2020
1 parent b534cbe commit 234fed6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
5 changes: 5 additions & 0 deletions AutodlIrssi/FilterManager.pm
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ sub checkFilter {
return 0 if defined $numDownloads && $numDownloads >= $filter->{maxDownloads};
}

# Check filter size
# This is a soft check when torrentSizeInBytes is not defined,
# condition will be treated as satisfied
return checkFilterSize($ti->{torrentSizeInBytes}, $filter);

return 1;
}

Expand Down
3 changes: 2 additions & 1 deletion AutodlIrssi/IrcHandler.pm
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ sub onNewIrcLine {
my $ti = $self->handleNewAnnouncerLine($line, $networkName, $serverName, $channelName, $userName);
return 0 unless defined $ti;

my $matchedRelease = new AutodlIrssi::MatchedRelease($self->{downloadHistory});
# Matched Release takes filterManager as argument, so that it can check filters during 2nd attempt
my $matchedRelease = new AutodlIrssi::MatchedRelease($self->{downloadHistory}, $self->{filterManager});
$matchedRelease->start($ti);
return 1;
}
Expand Down
16 changes: 15 additions & 1 deletion AutodlIrssi/MatchedRelease.pm
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ else {
}

sub new {
my ($class, $downloadHistory) = @_;
my ($class, $downloadHistory, $filterManager) = @_;
bless {
downloadHistory => $downloadHistory,
filterManager => $filterManager,
}, $class;
}

Expand Down Expand Up @@ -295,6 +296,19 @@ sub _onTorrentDownloaded {

if (!AutodlIrssi::FilterManager::checkFilterSize($self->{ti}{torrentSizeInBytes}, $self->{ti}{filter})) {
$self->{ti}{filter}{state}->restoreDownloadCount($self->{filterDlState});

# Since all condition met except for torrent size
# Process the announcement again, since this time we have the torrentSizeInBytes, If a matching filter is identified,
# this block of code will not be executed again as torrent size is also part of the filter
message 4, "Because of torrent size condition processing the announcement again";
my $ti = $self->{ti};

$ti->{filter} = $self->{filterManager}->findFilter($ti);
return unless defined $ti->{filter};

my $matchedRelease = new AutodlIrssi::MatchedRelease($self->{downloadHistory}, $self->{filterManager});
$matchedRelease->start($ti);

return;
}
else {
Expand Down

0 comments on commit 234fed6

Please sign in to comment.