diff options
Diffstat (limited to 'module/plugins/hoster/Xdcc.py')
-rw-r--r-- | module/plugins/hoster/Xdcc.py | 93 |
1 files changed, 46 insertions, 47 deletions
diff --git a/module/plugins/hoster/Xdcc.py b/module/plugins/hoster/Xdcc.py index d167e4cab..aba66ee94 100644 --- a/module/plugins/hoster/Xdcc.py +++ b/module/plugins/hoster/Xdcc.py @@ -8,14 +8,16 @@ import time from select import select -from module.plugins.Hoster import Hoster -from module.utils import save_join +from module.plugins.internal.Hoster import Hoster +# from module.utils import decode +from module.utils import save_join as fs_join class Xdcc(Hoster): __name__ = "Xdcc" __type__ = "hoster" - __version__ = "0.32" + __version__ = "0.34" + __status__ = "testing" __config__ = [("nick", "str", "Nickname", "pyload"), ("ident", "str", "Ident", "pyloadident"), @@ -27,20 +29,19 @@ class Xdcc(Hoster): def setup(self): - self.debug = 0 # 0,1,2 self.timeout = 30 self.multiDL = False def process(self, pyfile): - # change request type - self.req = pyfile.m.core.requestFactory.getRequest(self.__name__, type="XDCC") + #: Change request type + self.req = self.pyload.requestFactory.getRequest(self.__name__, type="XDCC") self.pyfile = pyfile for _i in xrange(0, 3): try: - nmn = self.doDownload(pyfile.url) - self.logDebug("Download of %s finished." % nmn) + nmn = self.do_download(pyfile.url) + self.log_debug("Download of %s finished." % nmn) return except socket.error, e: if hasattr(e, "errno"): @@ -49,9 +50,8 @@ class Xdcc(Hoster): errno = e.args[0] if errno == 10054: - self.logDebug("Server blocked our ip, retry in 5 min") - self.setWait(300) - self.wait() + self.log_debug("Server blocked our ip, retry in 5 min") + self.wait(300) continue self.fail(_("Failed due to socket errors. Code: %d") % errno) @@ -59,17 +59,17 @@ class Xdcc(Hoster): self.fail(_("Server blocked our ip, retry again later manually")) - def doDownload(self, url): - self.pyfile.setStatus("waiting") # real link + def do_download(self, url): + self.pyfile.setStatus("waiting") #: Real link m = re.match(r'xdcc://(.*?)/#?(.*?)/(.*?)/#?(\d+)/?', url) server = m.group(1) chan = m.group(2) bot = m.group(3) pack = m.group(4) - nick = self.getConfig('nick') - ident = self.getConfig('ident') - real = self.getConfig('realname') + nick = self.get_config('nick') + ident = self.get_config('ident') + real = self.get_config('realname') temp = server.split(':') ln = len(temp) @@ -81,30 +81,29 @@ class Xdcc(Hoster): self.fail(_("Invalid hostname for IRC Server: %s") % server) ####################### - # CONNECT TO IRC AND IDLE FOR REAL LINK + #: CONNECT TO IRC AND IDLE FOR REAL LINK dl_time = time.time() sock = socket.socket() sock.connect((host, int(port))) if nick == "pyload": - nick = "pyload-%d" % (time.time() % 1000) # last 3 digits + nick = "pyload-%d" % (time.time() % 1000) #: last 3 digits sock.send("NICK %s\r\n" % nick) sock.send("USER %s %s bla :%s\r\n" % (ident, host, real)) - self.setWait(3) - self.wait() + self.wait(3) sock.send("JOIN #%s\r\n" % chan) sock.send("PRIVMSG %s :xdcc send #%s\r\n" % (bot, pack)) - # IRC recv loop + #: IRC recv loop readbuffer = "" done = False retry = None m = None while True: - # done is set if we got our real link + #: Done is set if we got our real link if done: break @@ -115,7 +114,7 @@ class Xdcc(Hoster): sock.send("PRIVMSG %s :xdcc send #%s\r\n" % (bot, pack)) else: - if (dl_time + self.timeout) < time.time(): # todo: add in config + if (dl_time + self.timeout) < time.time(): #@TODO: add in config sock.send("QUIT :byebye\r\n") sock.close() self.fail(_("XDCC Bot did not answer")) @@ -129,8 +128,8 @@ class Xdcc(Hoster): readbuffer = temp.pop() for line in temp: - if self.debug is 2: - print "*> " + unicode(line, errors='ignore') + # if self.pyload.debug: + # self.log_debug("*> " + decode(line)) line = line.rstrip() first = line.split() @@ -145,29 +144,29 @@ class Xdcc(Hoster): continue msg = { - "origin": msg[0][1:], - "action": msg[1], - "target": msg[2], - "text": msg[3][1:] + 'origin': msg[0][1:], + 'action': msg[1], + 'target': msg[2], + 'text': msg[3][1:] } - if nick == msg['target'][0:len(nick)] and "PRIVMSG" == msg['action']: + if nick is msg['target'][0:len(nick)] and "PRIVMSG" is msg['action']: if msg['text'] == "\x01VERSION\x01": - self.logDebug("Sending CTCP VERSION") + self.log_debug("Sending CTCP VERSION") sock.send("NOTICE %s :%s\r\n" % (msg['origin'], "pyLoad! IRC Interface")) elif msg['text'] == "\x01TIME\x01": - self.logDebug("Sending CTCP TIME") + self.log_debug("Sending CTCP TIME") sock.send("NOTICE %s :%d\r\n" % (msg['origin'], time.time())) elif msg['text'] == "\x01LAG\x01": - pass # don't know how to answer + pass #: don't know how to answer - if not (bot == msg['origin'][0:len(bot)] - and nick == msg['target'][0:len(nick)] + if not (bot is msg['origin'][0:len(bot)] + and nick is msg['target'][0:len(nick)] and msg['action'] in ("PRIVMSG", "NOTICE")): continue - if self.debug is 1: - print "%s: %s" % (msg['origin'], msg['text']) + if self.pyload.debug: + self.log_debug(msg['origin'], msg['text']) if "You already requested that pack" in msg['text']: retry = time.time() + 300 @@ -179,7 +178,7 @@ class Xdcc(Hoster): if m: done = True - # get connection data + #: Get connection data ip = socket.inet_ntoa(struct.pack('L', socket.ntohl(int(m.group(2))))) port = int(m.group(3)) packname = m.group(1) @@ -189,20 +188,20 @@ class Xdcc(Hoster): self.pyfile.name = packname - download_folder = self.config['general']['download_folder'] - filename = save_join(download_folder, packname) + download_folder = self.pyload.config.get("general", "download_folder") + filename = fs_join(download_folder, packname) - self.logInfo(_("Downloading %s from %s:%d") % (packname, ip, port)) + self.log_info(_("Downloading %s from %s:%d") % (packname, ip, port)) self.pyfile.setStatus("downloading") newname = self.req.download(ip, port, filename, sock, self.pyfile.setProgress) - if newname and newname != filename: - self.logInfo(_("%(name)s saved as %(newname)s") % {"name": self.pyfile.name, "newname": newname}) + if newname and newname is not filename: + self.log_info(_("%(name)s saved as %(newname)s") % {'name': self.pyfile.name, 'newname': newname}) filename = newname - # kill IRC socket - # sock.send("QUIT :byebye\r\n") + #: kill IRC socket + #: sock.send("QUIT :byebye\r\n") sock.close() - self.lastDownload = filename - return self.lastDownload + self.last_download = filename + return self.last_download |