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 suspendedStateChanged(self, on): if on and self.auto_resume: KTorrent.log( "AutoResumeScript: torrents suspended, starting timer") self.startTimer() else: self.timer.stop()
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 torrentRemoved(ih): tor = KTorrent.torrent(ih) KTorrent.log("torrentRemoved=%s" % tor.name())
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()) tor.connect("finished(QObject* )", self.torrentFinished)
#!/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 suspendedStateChanged(self,on): if on and self.auto_resume: KTorrent.log("AutoResumeScript: torrents suspended, starting timer") self.startTimer() else: self.timer.stop()
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)
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 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)
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 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)
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 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 torrentAdded(self, ih): tor = KTorrent.torrent(ih) KTorrent.log("Torrent added %s" % tor.name()) for tk in self.trackers: tor.addTracker(tk)
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()])