rdt-client icon indicating copy to clipboard operation
rdt-client copied to clipboard

Feature Request: Ability to filter file selection by regex patterns

Open nrlcode opened this issue 1 year ago • 2 comments

I would like to be able to filter files in two scenarios:

  1. Selecting only playable files (mkv, mp4, etc...)
  2. Not selecting files that are samples, trailers, extras, etc...

I propose this is done by two user configurable regex fields that could be a part of the options for GUI Defaults, qBitorrent, Add Torrent pages, etc... The first regex field will only select files that provide a match. The second regex field will only select files that do not provide a match.

I am providing some sample code below, obviously variable names could be changed to what makes the most sense. I did try building and I got pretty far, but I'm having trouble with escape characters coming from the input on the webpage to actually consuming the variables in the selection process.

Sample regex fields could be something like:

  1. For playable files: \.(mkv|mp4|avi|wmv)$
  2. For samples, trailers, and extras: \b(samples?(\d{1,4})?|extras?(\d{1,4})|trailer)\b

Some sample code to add the configurable fields:

    <div class="field">
      <label class="label">Only select video files</label>
      <div class="control">
        <div class="field has-addons" style="margin-bottom: 0">
          <div class="control is-expanded">
            <input class="input" type="text" placeholder="\.(mkv|mp4|avi|wmv)$" [(ngModel)]="selectVideoFilesRegex">
      </div>
      <p class="help">The regex statement you enter here will only select files that present a match. Use regex101.com to help build your regex statements.</p>
    </div>

    <div class="field">
      <label class="label">Do no select samples, trailers, and extras?</label>
      <div class="control">
        <div class="field has-addons" style="margin-bottom: 0">
          <div class="control is-expanded">
            <input class="input" type="text" placeholder="\b(samples?(\d{1,4})?|extras?(\d{1,4})|trailer)\b" [(ngModel)]="unselectMiscFilesRegex">
      </div>
      <p class="help">The regex statement you enter here will not select files that present a match. Use regex101.com to help build your regex statements.</p>
    </div>

As well as sample code for the selection process:

        if (torrent.DownloadAction != TorrentDownloadAction.DownloadManual)
        {
            var minFileSize = torrent.DownloadMinSize * 1024 * 1024;

            Log($"Determining which files are over {minFileSize} bytes", torrent);

            files = files.Where(m => m.Bytes > minFileSize)
                         .ToList();

            Log($"Found {files.Count} files that match the minimum file size criterea", torrent);

            Log("Determining which files are playable", torrent);

            var isVideoFileRegex = torrent.SelectVideoFilesRegex;

            var isVideoFile = new Regex(isVideoFileRegex, RegexOptions.IgnoreCase);

            files = files.Where(m => isVideoFile.IsMatch(m.Path))
                         .ToList();

            Log("Determining which files are not misc", torrent);
            
            var isNotMiscFilesRegex = torrent.UnselectMiscFilesRegex;

            var isNotMiscFiles = new Regex(isNotMiscFilesRegex, RegexOptions.IgnoreCase);

            files = files.Where(m => !isNotMiscFiles.IsMatch(m.Path))
                         .ToList();
        }

nrlcode avatar Jan 20 '24 05:01 nrlcode

@rogerfar any thoughts on this?

nrlcode avatar Jan 23 '24 17:01 nrlcode

+1, I would definitely like to see this. For some reason RDT client keeps adding files that it shouldn't so it'd be nice to define a regex filter to prevent this

banhathome avatar Feb 09 '24 11:02 banhathome

This makes sense yes!

rogerfar avatar Feb 13 '24 02:02 rogerfar