Skip to content

New: Flood Download Client #4159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 21, 2021
Merged

New: Flood Download Client #4159

merged 1 commit into from
Jan 21, 2021

Conversation

jesec
Copy link
Contributor

@jesec jesec commented Dec 13, 2020

Database Migration

NO

Description

Add support for Flood, a modern Web UI for various torrent clients.

@jesec
Copy link
Contributor Author

jesec commented Dec 25, 2020

Ping @markus101.

Happy holidays!

I would be appreciated if you can give some preliminary reviews. I deployed the PR on my Sonarr/Radarr instances, and the PR is working perfectly fine so far.

Thanks.

BTW: I joined the Sonarr Discord. Feel free to contact me directly if necessary.

Copy link
Member

@markus101 markus101 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't tested, but left some preliminary comments.

_proxy = proxy;
}

private static IEnumerable<string> HandleTags(RemoteEpisode media, FloodSettings settings)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

media -> remoteEpisode

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

public bool StartOnAdd { get; set; }

[FieldDefinition(12, Label = "Sequential Download", Type = FieldType.Checkbox, Advanced = true)]
public bool SequentialDownload { get; set; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not have plans to support this for other clients, so we don't want to support it for flood either.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SequentialDownload removed.

RuleFor(c => c.Host).ValidHost();
RuleFor(c => c.Port).InclusiveBetween(1, 65535);

RuleFor(c => c.TargetRatio).GreaterThanOrEqualTo(0).Unless(c => c.TargetRatio == -1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ratio limits in clients are based on indexer settings, there shouldn't be a setting for flood.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TargetRatio removed.

{
var result = item.Clone();

var contentPaths = _proxy.GetTorrentContentPaths(item.DownloadId, Settings);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be fetched when the torrents are fetched? Avoiding the extra API call? The output path is already being set in GetItems what is that directory if it's not where it should be imported from?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, no. Get torrent API call provides directory path only. There are many cases: single-file vs. multi-file, base directory vs. sub directory.

When the torrent is single-file, Sonarr expects path to the file. Otherwise, it will try to import the whole directory, which can cause problems if there are unrelated files in the directory. For multi-file torrents, Sonarr expects path to the base directory of the torrent.

As such, an additional API call to fetch the list of contents of a torrent is required. It is more efficient (resource saving) to fetch when the import is requested.

item.Status = DownloadItemStatus.Paused;
}

if (Settings.TargetRatio != -1 && item.SeedRatio > Settings.TargetRatio)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned on the setting the target ratio comes from the indexer, there is a big discussion on how to do this in rtorrent here: #3632

The big thing is we don't want Sonarr to be a seedtime/ratio manager, it can pass the limits to the client, but the client should be able to indicate when the time/ratio has been met.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TargetRatio removed.

@jesec jesec requested a review from markus101 January 4, 2021 00:52
Copy link
Member

@markus101 markus101 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found a couple issues while testing, will be able to test more once the path issue is resolved.

{
// For multi-file torrent, OutputPath should be the path of base directroy of torrent.
// isBasePath is false by default. Presumably base directory would be first fragment of path of content.
result.OutputPath = item.OutputPath + new OsPath(contentPaths[0].Split(new char[] { '\\', '/' }, StringSplitOptions.RemoveEmptyEntries)[0]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not working for multi-file torrents. It currently returns the path to the first file, but instead I believe it should just be returning item.OutputPath.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

item.OutputPath is the directory of TorrentProperties, which, by definition, is always a directory. This directory may or may not be the base directory. This causes problems as Sonarr can grab contents of unrelated torrents which reside in the same destination directory.

This line of code tries to combine the directory with the first segment (directory) of a content when the torrent is multi-file:

TorrentProperties.directory + first path segment of first content of a multi-file torrent (path -> split -> pathSegments[0])

/mnt/data0/downloads + Big.Buck.Bunny.1080P/Soundtracks/Bunny.wav

I tested with a multi-file torrent. It seems that this approach works fine as torrent clients always create a sub-directory for multi-file torrents by default.

For single-file torrents, Sonarr expects path to a single file, which is handled by another case (above).

What's not working? Did this line of code fail to get the first segment, combine paths, or...?

Copy link
Member

@markus101 markus101 Jan 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It currently returns the path to the first file.

It gave me the path to a text file, not a folder. Even if it happened to give me a video file it'd be wrong for a multi-video file download.

image
result.OutputPath is set to C:\downloads\torrents\test\The.Rookie.S03E02.WEBRip.x264-ION10\RARBG.txt.
item.OutputPath is set to C:\timebomb\downloads\torrents\test\The.Rookie.S03E02.WEBRip.x264-ION10

For multi-file this should just return the path, but if there is single file torrent inside a job folder you're probably going to see issues.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In your case, directory is the base directory, which is indeed a possible case. This case is not unhandled here. I assume there are some differences in how clients handle root directory of a multi-file torrent. I will work out a more robust method for detection of base directory.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, they pretty much universally suck at it, we're sometimes left guessing which has lead to issues in the past and somewhat recently with qbit.

Copy link
Contributor Author

@jesec jesec Jan 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is done. Please try it.

BTW: Sonarr can probably utilize a method that returns an array of paths (of contents of torrents) instead. That allows things to be much more precise and eliminates any interferences and inconsistencies.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working much better now. In the future please don't squash fixes immediately, we can do that when merging the PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack. It is a shame that Github PR does not have the capability to compare different versions of change sets directly. I typically use more professional Code Review tools like Gerrit, which does have the capability (and as result, pushing additional commits can be "stupid").

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fortunately, though, there is a commit compare function: https://github.com/jesec/Sonarr/compare/17237a0e..0cae35f3.

@jesec jesec requested a review from markus101 January 14, 2021 04:07
Copy link
Member

@markus101 markus101 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working great, just the warning to add then we'll get it landed.

}

public override string Name => "Flood";

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Until we have remove support we need to add:

public override ProviderMessage Message => new ProviderMessage("Sonarr is unable to remove torrents that have finished seeding when using Flood", ProviderMessageType.Warning);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually the current behavior is that Sonarr defaults to instant removal of completed torrents, which is not a desired behavior in BitTorrent community.

If we want to add the warning, I think it would be a good idea to make item.CanMoveFiles and item.CanBeRemoved always false so Sonarr won't instant remove completed torrents. Otherwise the warning can be misleading and needs to be reworded.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah you’re absolutely correct, I missed that part. That + the warning then, please.

@jesec jesec requested a review from markus101 January 17, 2021 02:17
@jesec
Copy link
Contributor Author

jesec commented Jan 20, 2021

@markus101 Can you check what happened with CI? I don't have access to TeamCity.

@bakerboy448
Copy link
Contributor

@jesec there’s the little login as guest button on the page! (Not obvious, I missed it too!)

@jesec
Copy link
Contributor Author

jesec commented Jan 20, 2021

@jesec there’s the little login as guest button on the page! (Not obvious, I missed it too!)

Thanks.

I think it is a flaky test which does not appear to be related to this PR.

@markus101 markus101 changed the title Initial support for Flood New: Flood Download Client Jan 21, 2021
@markus101 markus101 merged commit 28e0ad3 into Sonarr:phantom-develop Jan 21, 2021
@markus101
Copy link
Member

Thanks for all the work on this @jesec!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants