def suspendedStateChanged(self, on): if on and self.auto_resume: KTorrent.log( "AutoResumeScript: torrents suspended, starting timer") self.startTimer() else: self.timer.stop()
def removeTracker(self,tracker): g = self.tracker_map[fqdn(tracker)] g.unref() if g.canBeRemoved(): KTorrent.log("Removing group for tracker " + tracker) KTScriptingPlugin.removeGroup(g.url) del self.tracker_map[tracker]
def addTracker(self,tracker): g = TrackerGroup(tracker) g.ref() self.tracker_map[tracker] = g KTorrent.log("Adding group for tracker " + tracker) KTScriptingPlugin.addGroup(tracker,"network-server","/all/" + t.i18n("Trackers") + "/" + str(self.id),g) self.id += 1
def unload(self): trackers = self.tracker_map.keys() for tracker in trackers: g = self.tracker_map[tracker] KTorrent.log("Removing group for tracker " + tracker) KTScriptingPlugin.removeGroup(g.url) del self.tracker_map[tracker]
def __init__(self): self.command = "" KTorrent.connect("torrentAdded(const QString &)", self.torrentAdded) tors = KTorrent.torrents() # bind to signals for each torrent for t in tors: self.torrentAdded(t)
def __init__(self): self.auto_resume = False self.hours = 0 self.minutes = 5 self.seconds = 0 KTorrent.connect("pauseStateChanged(bool)",self.pausedStateChanged) self.timer = KTScriptingPlugin.createTimer(True) self.timer.connect('timeout()',self.timerFired)
def connectSignals(self, tor): KTorrent.log("connectSignals " + tor.name()) tor.connect("finished(QObject* )", self.torrentFinished) tor.connect("stoppedByError(QObject* ,const QString & )", self.torrentStoppedByError) tor.connect("seedingAutoStopped(QObject* ,const QString & )", self.seedingAutoStopped) tor.connect("corruptedDataFound(QObject* )", self.corruptedDataFound)
def __init__(self): self.auto_resume = False self.hours = 0 self.minutes = 5 self.seconds = 0 KTorrent.connect("suspendStateChanged(bool)",self.suspendedStateChanged) self.timer = KTScriptingPlugin.createTimer(True) self.timer.connect('timeout()',self.timerFired)
def __init__(self): self.tracker_map = {} # initialize the dictionary self.id = 0 KTorrent.connect("torrentAdded(const QString &)",self.torrentAdded) KTorrent.connect("torrentRemoved(const QString &)",self.torrentRemoved) tors = KTorrent.torrents() # go over each torrent and collect all the trackers for t in tors: self.torrentAdded(t)
def __init__(self): KTorrent.connect("torrentAdded(const QString &)", self.torrentAdded) tors = KTorrent.torrents() # bind to signals for each torrent f = open( KTScriptingPlugin.scriptDir("auto_tracker_add") + "tracker.list") self.trackers = f.read().splitlines() for t in tors: self.torrentAdded(t)
def __init__(self): self.auto_resume = False self.remove_on_finish_downloading = False self.remove_on_finish_seeding = False self.timer = KTScriptingPlugin.createTimer(True) KTorrent.connect("torrentAdded(const QString &)",self.torrentAdded) tors = KTorrent.torrents() # bind to signals for each torrent for t in tors: self.torrentAdded(t)
def load(self): self.auto_resume = KTScriptingPlugin.readConfigEntryBool("AutoResumeScript","auto_resume",self.auto_resume) self.hours = KTScriptingPlugin.readConfigEntryInt("AutoResumeScript","hours",self.hours) self.minutes = KTScriptingPlugin.readConfigEntryInt("AutoResumeScript","minutes",self.minutes) self.seconds = KTScriptingPlugin.readConfigEntryInt("AutoResumeScript","seconds",self.seconds) if self.auto_resume and KTorrent.paused(): self.startTimer()
def __init__(self): self.mail_user = "******" self.mail_pwd = "your_password" self.mail_server = "smtp.gmail.com" self.mail_port = 587 self.mail_dest = "*****@*****.**" self.mail_add_cc = False self.mail_cc = "" self.mail_add_bcc = False self.mail_bcc = "" self.mail_use_tls = True KTorrent.connect("torrentAdded(const QString &)", self.torrentAdded) tors = KTorrent.torrents() # bind to signals for each torrent for t in tors: self.torrentAdded(t)
def load(self): self.auto_resume = KTScriptingPlugin.readConfigEntryBool("AutoResumeScript","auto_resume",self.auto_resume) self.hours = KTScriptingPlugin.readConfigEntryInt("AutoResumeScript","hours",self.hours) self.minutes = KTScriptingPlugin.readConfigEntryInt("AutoResumeScript","minutes",self.minutes) self.seconds = KTScriptingPlugin.readConfigEntryInt("AutoResumeScript","seconds",self.seconds) if self.auto_resume and KTorrent.suspended(): self.startTimer()
def __init__(self): self.mail_user = "******" self.mail_pwd = "your_password" self.mail_server = "smtp.gmail.com" self.mail_port = 587 self.mail_dest = "*****@*****.**" self.mail_add_cc = False self.mail_cc = "" self.mail_add_bcc = False self.mail_bcc = "" self.mail_use_tls = True KTorrent.connect("torrentAdded(const QString &)",self.torrentAdded) tors = KTorrent.torrents() # bind to signals for each torrent for t in tors: self.torrentAdded(t)
def isMember(self,info_hash): if info_hash in self.cache: return self.cache[info_hash] else: tor = KTorrent.torrent(info_hash) ret = self.url in [fqdn(tracker) for tracker in tor.trackers()] self.cache[info_hash] = ret return ret
def torrentAdded(self, info_hash): tor = KTorrent.torrent(info_hash) trackers = tor.trackers() for tracker in trackers: if not tracker in self.tracker_map: self.addTracker(tracker) else: self.tracker_map[tracker].ref()
def torrentAdded(self,info_hash): tor = KTorrent.torrent(info_hash) trackers = tor.trackers() for tracker in trackers: hostname = fqdn(tracker) if not hostname in self.tracker_map: self.addTracker(hostname) else: self.tracker_map[hostname].ref()
def configure(self): forms = Kross.module("forms") dialog = forms.createDialog(t.i18n("Auto Resume Settings")) dialog.setButtons("Ok|Cancel") page = dialog.addPage(t.i18n("Auto Resume"),t.i18n("Auto Resume"),"kt-bandwidth-scheduler") widget = forms.createWidgetFromUIFile(page,KTScriptingPlugin.scriptDir("auto_resume") + "auto_resume.ui") widget["auto_resume"].checked = self.auto_resume widget["hours"].value = self.hours widget["minutes"].value = self.minutes widget["seconds"].value = self.seconds widget["hours"].enabled = self.auto_resume widget["minutes"].enabled = self.auto_resume widget["seconds"].enabled = self.auto_resume if dialog.exec_loop(): self.auto_resume = widget["auto_resume"].checked self.hours = widget["hours"].value self.minutes = widget["minutes"].value self.seconds = widget["seconds"].value self.save() if self.auto_resume and KTorrent.suspended(): self.startTimer()
def configure(self): forms = Kross.module("forms") dialog = forms.createDialog(t.i18n("Auto Resume Settings")) dialog.setButtons("Ok|Cancel") page = dialog.addPage(t.i18n("Auto Resume"),t.i18n("Auto Resume"),"kt-bandwidth-scheduler") widget = forms.createWidgetFromUIFile(page,KTScriptingPlugin.scriptDir("auto_resume") + "auto_resume.ui") widget["auto_resume"].checked = self.auto_resume widget["hours"].value = self.hours widget["minutes"].value = self.minutes widget["seconds"].value = self.seconds widget["hours"].enabled = self.auto_resume widget["minutes"].enabled = self.auto_resume widget["seconds"].enabled = self.auto_resume if dialog.exec_loop(): self.auto_resume = widget["auto_resume"].checked self.hours = widget["hours"].value self.minutes = widget["minutes"].value self.seconds = widget["seconds"].value self.save() if self.auto_resume and KTorrent.paused(): self.startTimer()
def torrentAdded(self,ih): tor = KTorrent.torrent(ih) self.connectSignals(tor)
def timerFired(self): if KTorrent.suspended(): KTorrent.log("AutoResumeScript: resuming suspended torrents") KTorrent.setSuspended(False)
def torrentAdded(self, ih): tor = KTorrent.torrent(ih) KTorrent.log("Torrent added %s" % tor.name()) for tk in self.trackers: tor.addTracker(tk)
#!/usr/bin/python import KTorrent import Kross def torrentAdded(ih): tor = KTorrent.torrent(ih) KTorrent.log("torrentAdded=%s" % tor.name()) def torrentRemoved(ih): tor = KTorrent.torrent(ih) KTorrent.log("torrentRemoved=%s" % tor.name()) KTorrent.connect("torrentAdded(const QString &)",torrentAdded) KTorrent.connect("torrentRemoved(const QString &)",torrentRemoved) tors = KTorrent.torrents() KTorrent.log("Num torrents : %i" % len(tors)) for t in tors: tor = KTorrent.torrent(t) KTorrent.log("Torrent %s = %s" % (t, tor.name())) for i in range(0,tor.numFiles()): KTorrent.log("File %i = %s" % (i,tor.filePath(i)))
def torrentRemoved(ih): tor = KTorrent.torrent(ih) KTorrent.log("torrentRemoved=%s" % tor.name())
def connectSignals(self,tor): KTorrent.log("connectSignals " + tor.name()) tor.connect("finished(QObject* )",self.torrentFinished) tor.connect("stoppedByError(QObject* ,const QString & )",self.torrentStoppedByError) tor.connect("seedingAutoStopped(QObject* ,const QString & )",self.seedingAutoStopped) tor.connect("corruptedDataFound(QObject* )",self.corruptedDataFound)
def suspendedStateChanged(self,on): if on and self.auto_resume: KTorrent.log("AutoResumeScript: torrents suspended, starting timer") self.startTimer() else: self.timer.stop()
def mail(self,subject, text): msg = MIMEMultipart() msg['From'] = self.mail_user msg['To'] = self.mail_dest msg['Subject'] = subject if self.mail_add_cc: msg['CC'] = self.mail_cc if self.mail_add_bcc: msg['BCC'] = self.mail_bcc msg.attach(MIMEText(text)) KTorrent.log("Sending mail : " + subject) try: mailServer = smtplib.SMTP(self.mail_server, self.mail_port) mailServer.ehlo() if self.mail_use_tls: mailServer.starttls() mailServer.ehlo() mailServer.login(self.mail_user, self.mail_pwd) mailServer.sendmail(self.mail_user, self.mail_dest, msg.as_string()) mailServer.quit() except smtplib.SMTPRecipientsRefused: KTorrent.log("Failed to send e-mail notification: recipients refushed") except smtplib.SMTPHeloError: KTorrent.log("Failed to send e-mail notification: helo error") except smtplib.SMTPSenderRefused: KTorrent.log("Failed to send e-mail notification: sender refused") except smtplib.SMTPDataError: KTorrent.log("Failed to send e-mail notification: something went wrong sending data") except smtplib.SMTPAuthenticationError: KTorrent.log("Failed to send e-mail notification: authentication failed") except smtplib.SMTPException: KTorrent.log("Failed to send e-mail notification") except socket.error, err: KTorrent.log("Failed to send e-mail notification: %s " % err)
def mail(self, subject, text): msg = MIMEMultipart() msg['From'] = self.mail_user msg['To'] = self.mail_dest msg['Subject'] = subject if self.mail_add_cc: msg['CC'] = self.mail_cc if self.mail_add_bcc: msg['BCC'] = self.mail_bcc msg.attach(MIMEText(text)) KTorrent.log("Sending mail : " + subject) try: mailServer = smtplib.SMTP(self.mail_server, self.mail_port) mailServer.ehlo() if self.mail_use_tls: mailServer.starttls() mailServer.ehlo() mailServer.login(self.mail_user, self.mail_pwd) mailServer.sendmail(self.mail_user, self.mail_dest, msg.as_string()) mailServer.quit() except smtplib.SMTPRecipientsRefused: KTorrent.log( "Failed to send e-mail notification: recipients refushed") except smtplib.SMTPHeloError: KTorrent.log("Failed to send e-mail notification: helo error") except smtplib.SMTPSenderRefused: KTorrent.log("Failed to send e-mail notification: sender refused") except smtplib.SMTPDataError: KTorrent.log( "Failed to send e-mail notification: something went wrong sending data" ) except smtplib.SMTPAuthenticationError: KTorrent.log( "Failed to send e-mail notification: authentication failed") except smtplib.SMTPException: KTorrent.log("Failed to send e-mail notification") except socket.error, err: KTorrent.log("Failed to send e-mail notification: %s " % err)
def torrentAdded(self, ih): tor = KTorrent.torrent(ih) self.connectSignals(tor)
def timerFired(self): if KTorrent.paused(): KTorrent.log("AutoResumeScript: resuming paused torrents") KTorrent.setPaused(False)
def torrentFinished(self,tor): KTorrent.log("Torrent finished %s" % tor.name()) if self.remove_on_finish_downloading: KTorrent.log("Removing %s" % tor.name()) KTorrent.removeDelayed(tor.infoHash(),False)
def seedingAutoStopped(self,tor,reason): KTorrent.log("Torrent finished seeding %s" % tor.name()) if self.remove_on_finish_seeding: KTorrent.log("Removing %s" % tor.name()) KTorrent.removeDelayed(tor.infoHash(),False)
def torrentRemoved(self,info_hash): tor = KTorrent.torrent(info_hash) trackers = tor.trackers() for tracker in trackers: if tracker in self.tracker_map: self.removeTracker(tracker)
def torrentAdded(self, ih): tor = KTorrent.torrent(ih) KTorrent.log("Torrent added %s" % tor.name()) tor.connect("finished(QObject* )", self.torrentFinished)
except smtplib.SMTPRecipientsRefused: KTorrent.log("Failed to send e-mail notification: recipients refushed") except smtplib.SMTPHeloError: KTorrent.log("Failed to send e-mail notification: helo error") except smtplib.SMTPSenderRefused: KTorrent.log("Failed to send e-mail notification: sender refused") except smtplib.SMTPDataError: KTorrent.log("Failed to send e-mail notification: something went wrong sending data") except smtplib.SMTPAuthenticationError: KTorrent.log("Failed to send e-mail notification: authentication failed") except smtplib.SMTPException: KTorrent.log("Failed to send e-mail notification") except socket.error, err: KTorrent.log("Failed to send e-mail notification: %s " % err) except: KTorrent.log("Failed to send e-mail notification") else: KTorrent.log("Successfully sent e-mail notification") def save(self): KTScriptingPlugin.writeConfigEntry("EMailNotificationsScript","username",self.mail_user) KTScriptingPlugin.writeConfigEntry("EMailNotificationsScript","password",self.mail_pwd) KTScriptingPlugin.writeConfigEntry("EMailNotificationsScript","server",self.mail_server) KTScriptingPlugin.writeConfigEntryInt("EMailNotificationsScript","port",self.mail_port) KTScriptingPlugin.writeConfigEntry("EMailNotificationsScript","dest",self.mail_dest) KTScriptingPlugin.writeConfigEntryBool("EMailNotificationsScript","add_cc",self.mail_add_cc) KTScriptingPlugin.writeConfigEntry("EMailNotificationsScript","cc",self.mail_cc) KTScriptingPlugin.writeConfigEntryBool("EMailNotificationsScript","add_bcc",self.mail_add_bcc) KTScriptingPlugin.writeConfigEntry("EMailNotificationsScript","bcc",self.mail_bcc) KTScriptingPlugin.writeConfigEntryBool("EMailNotificationsScript","use_tls",self.mail_use_tls) KTScriptingPlugin.syncConfig("EMailNotificationsScript")
def torrentAdded(self,ih): tor = KTorrent.torrent(ih) KTorrent.log("Torrent added %s" % tor.name()) tor.connect("finished(QObject* )",self.torrentFinished) tor.connect("seedingAutoStopped(QObject* ,const QString & )",self.seedingAutoStopped)
KTorrent.log("Failed to send e-mail notification: helo error") except smtplib.SMTPSenderRefused: KTorrent.log("Failed to send e-mail notification: sender refused") except smtplib.SMTPDataError: KTorrent.log( "Failed to send e-mail notification: something went wrong sending data" ) except smtplib.SMTPAuthenticationError: KTorrent.log( "Failed to send e-mail notification: authentication failed") except smtplib.SMTPException: KTorrent.log("Failed to send e-mail notification") except socket.error, err: KTorrent.log("Failed to send e-mail notification: %s " % err) except: KTorrent.log("Failed to send e-mail notification") else: KTorrent.log("Successfully sent e-mail notification") def save(self): KTScriptingPlugin.writeConfigEntry("EMailNotificationsScript", "username", self.mail_user) KTScriptingPlugin.writeConfigEntry("EMailNotificationsScript", "password", self.mail_pwd) KTScriptingPlugin.writeConfigEntry("EMailNotificationsScript", "server", self.mail_server) KTScriptingPlugin.writeConfigEntryInt("EMailNotificationsScript", "port", self.mail_port) KTScriptingPlugin.writeConfigEntry("EMailNotificationsScript", "dest", self.mail_dest) KTScriptingPlugin.writeConfigEntryBool("EMailNotificationsScript",
def torrentFinished(self, tor): KTorrent.log("Torrent finished %s" % tor.name()) if self.command != "": KTorrent.log("Executing command: %s" % self.command) KTorrent.log("For torrent: %s" % tor.name()) call([self.command, tor.infoHash(), tor.name(), tor.pathOnDisk()])