This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Request: Idle Time

Tags: None
(comma "," separated)
bolovan
Registered Member
Posts
2
Karma
0

Request: Idle Time

Sat Sep 12, 2009 3:49 pm
I seed a lot for a tracker, but the tracker is limited to 30 torrents. I need to know how log was idle one of the torrents (for example, if there was no any activity in last 20 days, to know to remove the torrent).
Ideea is to have one time counter that is reseted at any seed. So, to show how log as past from last seed.
Rioting_Pacifist
Registered Member
Posts
27
Karma
0

Re: Request: Idle Time

Sun Sep 13, 2009 2:03 am
Do you mean leach?, if two people were seeding to nobody then neither would ever go 20days without seeing another seed.

I could whip together a kross script for this, unfortunately it would only log/remove (e.g it cant make a group with torrents for you to remove them yourself, because of a kross bug). If you want to see if there are any new leaches (or seeds) i'd rely on checking torrents every 30min or so, so it would not be 100% accurate (may fail to pick up some leaches if the d/l takes less than 30min and you miss it). Alternatively it could check if you have uploaded anything in the last 20days, but that would fail if the torrent was busy but better seeded by others.

I am a bit busy atm but this seams like a simple script and aslong as you don't want a gui config i can probably find time to do it this week.
bolovan
Registered Member
Posts
2
Karma
0

Re: Request: Idle Time

Sun Sep 13, 2009 7:26 am
RiotingPacifist, I found that Queue Manager have one field: "Time Stalled". I's do what I need, the only issue is that is reseted at any restart of ktorrent. There is a way to keep a total "Time Stalled"?
Is not important for me that the torrent is busy or others have more seed than me. The important is for me to have seed. As I told you, I use a tracker that is limited to 30 torrents, and I must have a good ratio to download.
This is the best way for me to establish what torrents to keep in seed.
If you manage to make a script for this, I will own you a big big big beer.
I didn't have time to look in ktorrent code, but I will try to find a way.

Thanks.
Rioting_Pacifist
Registered Member
Posts
27
Karma
0

Re: Request: Idle Time

Mon Sep 14, 2009 1:07 am
RiotingPacifist, I found that Queue Manager have one field: "Time Stalled". I's do what I need, the only issue is that is reseted at any restart of ktorrent. There is a way to keep a total "Time Stalled"?

I think time stalled is used by the queue manager to decide which torrents to seed, so the information needs to be reset on reboots as it is no longer immediately relevant.

As I told you, I use a tracker that is limited to 30 torrents, and I must have a good ratio to download.

It seams that you can acheive what you want using the Queue Manager
set Maximum Downloads + Maximum seeds to 30
set Decrease priority of torrents which are stalled and stall timer (to a low value to rotate them, the timer is reset on ktorrent restarts so setting to 28800min will not work well)
set keep seeding after download is finished and put a max share ratio

If you manage to make a script for this, I will own you a big big big beer.

It's pretty simple given all the work the KTorrent developer(s) have put into kross, and give me a chance to learn so don't worry about it

I didn't have time to look in ktorrent code, but I will try to find a way.

No need to, these sort of things can (and IMO should) be handled by kross scripts (plugin scripts in ruby, python, javascript, etc) instead of adding a million features to ktorrent.

I would go with the above set-up as it will achieve what you want (reaching your target share ratio without wasting time seeding idle torrents), however as i enjoy scripting, here is an almost untested script (not such a fan of testing), it won't eat your dog or trash your os, but it may not work properly:
Code: Select all
#!/usr/biclan/env kross
# -*- coding: utf-8 -*-
import KTorrent
import Kross
import KTScriptingPlugin
from time import time

class removeStalledTorrents:
   def __init__(self):
      #settings for you
      self.timerFreq=3600000 #time in ms
      self.removeOlderThan= 20*86400 #time in s
      self.logOld=True
      self.removeOld=False
      
      #mine
      self.run = True
      self.timer = KTScriptingPlugin.createTimer(True)
      self.timer.connect('timeout()',self.timerFired)
   
   def timerFired(self):
      if self.run:
         for ih in KTorrent.torrents():
            now = int(time())
            uploadedOld = KTScriptingPlugin.readConfigEntryInt("removeStalledTorrentsv0.1",ih+"/uploaded",0)
            uploadedNew = KTorrent.torrent(ih).bytesUploaded()
            if uploadedNew > 4294967296: continue #for now ignore torrents with more than 4G upload
            if uploadedOld == uploadedNew:
               lastChange = KTScriptingPlugin.readConfigEntryInt("removeStalledTorrentsv0.1",ih+"/lastChange",now)
               if now > (lastChange + self.removeOlderThan) :
                  if self.logOld:
                     daysSinceChange = int((now - lastChange)/86400)
                     KTorrent.log(KTorrent.torrent(ih).name()+" has been idle for "+str(daysSinceChange)+" days")
                  if self.removeOld: KTorrent.remove(ih,False)
            else:
               KTScriptingPlugin.writeConfigEntryInt("removeStalledTorrentsv0.1",ih+"/uploaded",uploadedNew)
               KTScriptingPlugin.writeConfigEntryInt("removeStalledTorrentsv0.1",ih+"/lastChange",now)
         
         KTScriptingPlugin.syncConfig("removeStalledTorrentsv0.1")
         self.timer.start(self.timerFreq)

def unload():
   VarRemoveStalledTorrents.run = False

VarRemoveStalledTorrents=removeStalledTorrents()
VarRemoveStalledTorrents.start.timer(VarRemoveStalledTorrents.timerFreq)

save as a.py and add to kross scripts (needs kross plugin enabled in ktorrent and kross and kross-python installed on your distro)

I have assumed what you want is to see if you have seeded/uploaded anything in the last 20days and log torrents that have not.
I also don't check if the torrent (or even ktorrent) has tried running in the last 20days, if you want that just ask but as you may not even need to use this script i didn't bother implementing it in this version
3 bugs atm:
It doesn't deal with files that have uploaded more than 4GB because i couldn't rework it to use floats instead of ints, if you work with a lot of large torrents i can fix this
It does not remove settings for removed torrents, but i can't find a way to do that so its either a kross limitation or im abusing the settings system, however it is literally a few bytes per torrent so unless you deal with millions of torrents it will never cause any real problems
The shutdown code isn't great, so if you stop it then restart it (without restarting ktorrent) within an hour it may run twice an hour instead of once (very light & safe script though so you probably wont notice)


Bookmarks



Who is online

Registered users: Bing [Bot], Evergrowing, Google [Bot]