How do I set the label field a torrent has to a variable in a php plugin?

dsouvik215

Member
May 25, 2018
896
0
16
I want to set the label to a variable, so I can hack it into a script. I am unsure how to set the current label a torrent has to a variable. I know php, I am just unfamiliar how the plugin grabs data since it has no DB.
 

das329717

Member
May 25, 2018
928
0
16
how the plugin grabs data since it has no DB.
It use rtorrent as DB. You can associate pair key=>value with any torrent. Something like
d.set_custom=key,value for set and
$d.get_custom=key for get.

BTW, torrents label already exist in these variables:

$label = rawurlencode($label);
d.set_custom1=$label

for set (this pseudocode use deprecated method d.set_customN=value instead d.set_custom=key,value)

and,

$label = rawurldecode($d.get_custom1=)

for get.
rawurl* functions is used for prevent troubles with a non-UTF labels (in theory, user can set any values from rtorrent console, but we can't send non-UTF characters via XMLRPC API)
 

jith45

Member
May 25, 2018
960
0
16
It use rtorrent as DB. You can associate pair key=>value with any torrent. Something like
d.set_custom=key,value for set and
$d.get_custom=key for get.

BTW, torrents label already exist in these variables:

$label = rawurlencode($label);
d.set_custom1=$label

for set (this pseudocode use deprecated method d.set_customN=value instead d.set_custom=key,value)

and,

$label = rawurldecode($d.get_custom1=)

for get.
rawurl* functions is used for prevent troubles with a non-UTF labels (in theory, user can set any values from rtorrent console, but we can't send non-UTF characters via XMLRPC API)
Perhaps I am not as sharp as I thought. I am not quite clear on what you said. So I can grab any value from rtorrent using pair key=>value.

So for a label:

label=>$label?

I am not trying to set a value. I just want to grab the label from the torrent the script is operating on and set it to a variable called $label. If I can do that, I can finish what I am trying to do on the script. I typically only play with MySQL, so this is all very new to me.
 

das329717

Member
May 25, 2018
928
0
16
Here is a code snippet:

Code:
$label = rawurldecode($d.get_custom1=);
$directory = str_replace( "{LABEL}", $label, $directory );
if( ($path_to_finished != '') && !empty($session) )
{
$path_to_finished = rtAddTailSlash( $path_to_finished );
$fname = rtAddTailSlash($session).$hash.".torrent";
$directory = rTorrentSettings::get()->directory;
if(is_readable($fname) && !empty($directory))
{
$torrent = new Torrent( $fname );
if( !$torrent->errors() )
{
$directory = rtAddTailSlash( $directory );
$base_path = rtRemoveTailSlash( $base_path );
$base_path = rtRemoveLastToken( $base_path, '/' ); // filename or dirname
$base_path = rtAddTailSlash( $base_path );
$rel_path = rtGetRelativePath( $directory, $base_path );

I want the path for move to allow the string variable {LABEL} to be set to the torrent's label. So /data/tv/{LABEL} will change to /data/tv/torrentslabel