ruTorrent icon indicating copy to clipboard operation
ruTorrent copied to clipboard

Plugin ratio: It is impossible to assign or remove a ratio from a torrent.

Open Al4ndil opened this issue 6 months ago • 21 comments

Please complete the following tasks.

  • [x] Web browser cache cleared
  • [x] Link provided to install script if applicable
  • [x] Not using broken rtinst install script
  • [x] Web browser, ruTorrent, PHP and OS version provided

Tell us about your environment

Web browser : Opera One(version : 119.0.5497.70) ruTorrent : 5.2.8 (via crazy-max contener) PHP : PHP 8.3.19 OS : Openmediavault 7.7.9-1 (Sandworm)

Tell us how you installed ruTorrent

Crazy-max contener on docker standalone

Describe the bug

Hi, I only use autotools with automove. I decided to set up a ratio rule to try out. I can create my rule, rename it, and assign it. Once assigned, I cannot unassign it (no ratio) or replace it with another. I don't find any ratio rules in my .rtorrent.rc file. Even after disabling Autotools and restarting the container, nothing changes. No error in rutorrent.log or rtorrent.log

Steps to reproduce

No response

Expected behavior

No response

Additional context

No response

Al4ndil avatar Jun 16 '25 09:06 Al4ndil

Have you tried updating to the latest crazy max image? That one is 4 days old! There's a new one out already!

stickz avatar Jun 16 '25 11:06 stickz

Have you tried updating to the latest crazy max image? That one is 4 days old! There's a new one out already!

I just tried it. No difference.

Al4ndil avatar Jun 16 '25 12:06 Al4ndil

Thank you. This is an ruTorrent or rTorrent bug. I was able to reproduce it outside the docker container.

stickz avatar Jun 16 '25 12:06 stickz

Thx a lot for your test.

Al4ndil avatar Jun 16 '25 12:06 Al4ndil

Made mistake with activating this ratio rules thing and now every single torrent is broken. Can change ratiogroup max once. Deleted the rule, deleted the ratiorules.dat faile, disablked the extratio plugin and still nothing. There is no way to fix this. If you activate it once you are screwed. Looked into it a little and found that you cant change it because inside theWebUI.torrents the ratiogroup looks like this ratiogroup : "rat_0rat_0". The ratio plugin expects only once and it cant change it if its double. So looked in even deeper and would that in the hash.torrent.rtorrent file its decoded like this views=[[b'rat_0'], b'rat_0']. So how the hell did this one group get inside another group? I am so mad at myself that I did this to myself. Made a script that I can use to fix .rtorrent files directly, but that is not a fix. I dont even understand how activating extratio plugin for once can screw up entite rutorrent forever.

Edit: Tried even recompiling rtorrent, but that did nothing. So its clearly rutorrent problem and I cant find the problem. And because rutorrent add ratiogroup double the rtorrent dont accept this. Over writing my rutorrent with backup also did not fix the issue. So If someone dont find the solution the only thing I can think of is clean rutorrent and never use extratio plugin ever again. I have never seen anything break this bad in my life. What i did see is that xmlrpc commands are correct. It sends values only once and it should work, but rtorrent say the command failed. So I dont even know what to do now with my broken rutorrent. I have my script that can fix the .rtorrent files and then I can change the rtorrent group once for every torrent, but then its already broken. I hope my tests help someone to the right direction. I cant fix this.

ranirahn avatar Jun 17 '25 20:06 ranirahn

@ranirahn Thank you for communicating this problem is related to the extratio plugin on ruTorrent. This information is helpful to resolve the issue.

stickz avatar Jun 18 '25 09:06 stickz

I know that its related to "extratio" plugin. I tried to remove "extratio" plugin completely, but even that did not help to get regular "ratio" plugin to work. So extratio plugin overwrite something so completely that I cant get even "ratio" plugin to work at all. "extratio" plugin needs to be fixed, but it also cant breake "ratio" plugin that it did right now. Because I change ratiogroups often, I need this to work so I keep testing everything I can think of. Example restarting webserver did something...break "ratio.dat" file. Lost all data and ratiogroup names. Restored that from backup, but maybe that will give someone little more info about the problem. Restarting webserver did not help also with this issue. "ratio" plugin still dont work. For me the priorities are "ratio" plugin first. That needs to work what ever "extratio" plugin is doing. And then look at "extratio" plugin that it does not break the "ratio" plugin.

ranirahn avatar Jun 18 '25 10:06 ranirahn

@ranirahn I agree with you the extratio plugin needs to be fixed, so it doesn't break the ratio plugin. I am summarizing the information you provided. Your contribution to this issue report is very helpful.

stickz avatar Jun 18 '25 10:06 stickz

For my part, exratio is not installed on my rutorrent (exclusion via environment variable on Crazymax's compose).

Al4ndil avatar Jun 18 '25 13:06 Al4ndil

"extratio" is the plugin that allows you to open rules manager and add rules. If you dont have it installed how did you add any rules? If its disabled or removed you dont even have the option to open rules manager and add any rules to automatically change ratio groups.

ranirahn avatar Jun 18 '25 14:06 ranirahn

Oops! I didn't have that in mind. I was already focused on the attribution issue. I'll add the plugin in question.

Al4ndil avatar Jun 18 '25 15:06 Al4ndil

well, that is the plugin that break everything so I would not use that right now. We are talking about that plugin right? https://github.com/Novik/ruTorrent/wiki/PluginExtRatio

ranirahn avatar Jun 18 '25 15:06 ranirahn

I found the problem, but I dont know how to fix it. So ratiogroup data is saved in session file that looks like this when decoded

views = [rat_1]

But this info stay in rtorrent memory somewhere so if you delete this and it looks like this

views = []

and add another ratiogroup example rat_2 then the outcome will be like this

views = [[rat_1], rat_2]

But you cant delete ever that nested value rat_1 anymore. And if you change the ratiogroup then it will look like something like this

views = [[rat_1], [rat_2], rat_2]

On both of these options rutorrent sill can delete the last value but never anything that is in double []. So where do rtorrent keep the cache for this? I am not actually sure is its rtorrent or rutorrent problem actually. As mutch as I have seen the xmlrpc stream is correct. It sends right string to rtorrent, but dont know what happens with it after that and it get nested. I tried both rtorrent 0.9.8 and rtorrent 0.15.4 so that changed nothing on this issue.

I am trying to figure things out with separate php file in terminal, but what ever I do I still get nested value on ratiogroup change. I will keep testing and I hope it helps someone to get this fixed. Only way to get torrents working once is to fix session files directly, but then you can change ratiogroup once and then nothing again because its nested again.

ranirahn avatar Jun 19 '25 13:06 ranirahn

I give up. I cant fix this. rutorrent is sending through xmlrpc with both ratio and extratio plugin same way the ratiogroup values as strings, but rtorrent responds with nested array. And if its already nested none of the rtorrent commands work on them because rtorrent expect them to be strings, but something changes the type of the rat_ type as list not string like its sent and this extratio plugin change it for me permanently. I have not found a way to reset this change and get ratio plugin to work. Any rtorrent or rutorrent version does not work anymore with ratio plugins. I have tracked this down to libtorrent, but have now found where exactly this change from string to list takes place and the value gets added twice. once normal and once nested version and that breaks everything. Now i just need help to get my rutorrent or rtorrent reset so i can use it without this issue. But hopefully without deleting all torrents and adding them again one by one. it would be really hard to do with 1300 torrents.

ranirahn avatar Jun 25 '25 21:06 ranirahn

Hey @ranirahn, I encountered this issue as well and ended up creating a simple python script that removes rat_* views and related attributes from the sessions files. This might help you fix all your torrents in a batch. Just stop rTorrent, copy all your *.torrent.rtorrent session files into the in directory, run the script, and then replace your session files with the ones from the out directory. Be sure to back up everything first.

import bencodepy
import pprint
import os
from pathlib import Path

IN_DIR = Path("in")
OUT_DIR = Path("out")
OUT_DIR.mkdir(exist_ok=True)

def is_rat_entry(entry):
    # Match b'rat_0' through b'rat_20' and [b'rat_0'] through [b'rat_20']
    if isinstance(entry, bytes) and entry.startswith(b'rat_'):
        try:
            num = int(entry[4:])
            if 0 <= num <= 20:
                return True
        except ValueError:
            pass
    if isinstance(entry, list) and len(entry) == 1 and isinstance(entry[0], bytes) and entry[0].startswith(b'rat_'):
        try:
            num = int(entry[0][4:])
            if 0 <= num <= 20:
                return True
        except ValueError:
            pass
    return False

for file_path in IN_DIR.glob("*.rtorrent"):
    print(f"\nProcessing: {file_path}")
    with open(file_path, 'rb') as f:
        data = bencodepy.decode(f.read())

    print("Full object before filtering:")
    pprint.pprint(data)

    # Remove rat_* entries from views
    views = data.get(b'views', [])
    print("\nViews before filtering:")
    pprint.pprint(views)
    filtered_views = [v for v in views if not is_rat_entry(v)]
    print("\nViews after filtering:")
    pprint.pprint(filtered_views)
    data[b'views'] = filtered_views

    # Remove x-extratio1 from custom
    custom = data.get(b'custom')
    if custom and b'x-extratio1' in custom:
        del custom[b'x-extratio1']

    # Set throttle_name to empty if present
    if b'throttle_name' in data:
        data[b'throttle_name'] = b''

    print("\nFull object after filtering:")
    pprint.pprint(data)

    out_file = OUT_DIR / file_path.name
    with open(out_file, 'wb') as f:
        f.write(bencodepy.encode(data))

    print(f"Filtered file saved to {out_file}")

drrako avatar Jun 26 '25 12:06 drrako

I already had script for fixing session files, but first ratiogroup change break the file again and cant change second time. Are you saying you can change ratiogroups freely after using that script? I tested your script and nothing changed. Still can change group only once and session file is broken again.

ranirahn avatar Jun 26 '25 13:06 ranirahn

It's just intended to remove ratio groups from session files that cannot be removed manually through the UI, it does not resolve the underlying issue.

drrako avatar Jun 26 '25 14:06 drrako

Yeah. Its so weird problem. Before I used this extratio plugin I changed my ratiogroups often and there was never a issue with that. How did this plugin break something so completely that only way to get session files fixed is to change them directly and then it only works once. But yeah, script to fix session files I made same day when I break my rutorrent/rtorrent. I am still not sure witch side is the broken one. My script does not remove ratiogroups. Groups that are formatted correctly I keep so that I dont need to change them back after using my script. But if someone finds away to get things back to normal I really would like to know. And I suggest no one use extratio plugin if they have not break the system yet.

ranirahn avatar Jun 26 '25 18:06 ranirahn

Cross linking the rtorrent discussion: https://github.com/rakshasa/rtorrent/discussions/1542

anthonyryan1 avatar Jul 09 '25 21:07 anthonyryan1

Next rtorrent version should include fix for this. Tested it with Ratio Rules plugin also and all seem to be working.

ranirahn avatar Aug 02 '25 12:08 ranirahn

rtorrent 0.15.6 is out and everything seems to be working about ratio groups.

ranirahn avatar Aug 23 '25 08:08 ranirahn