summaryrefslogtreecommitdiffstats
path: root/pyload/plugins/hoster/Xdcc.py
diff options
context:
space:
mode:
authorGravatar Stefano <l.stickell@yahoo.it> 2013-07-22 20:50:34 +0200
committerGravatar Stefano <l.stickell@yahoo.it> 2013-07-22 21:20:06 +0200
commitaaaf5a4cddec894aacd7400c59a9f2f5e710362f (patch)
tree9d9e89aff86598b3ffcc86117abd554b193e28b5 /pyload/plugins/hoster/Xdcc.py
parentimplemented media type filter (diff)
downloadpyload-aaaf5a4cddec894aacd7400c59a9f2f5e710362f.tar.xz
Fixed PEP 8 violations in Hosters
(cherry picked from commit 2edeee0532ec6d6b4b26fd045a5971f67ca455da) Conflicts: pyload/plugins/hoster/BasePlugin.py pyload/plugins/hoster/MultishareCz.py pyload/plugins/hoster/NetloadIn.py pyload/plugins/hoster/PremiumizeMe.py pyload/plugins/hoster/RapidshareCom.py
Diffstat (limited to 'pyload/plugins/hoster/Xdcc.py')
-rw-r--r--pyload/plugins/hoster/Xdcc.py121
1 files changed, 58 insertions, 63 deletions
diff --git a/pyload/plugins/hoster/Xdcc.py b/pyload/plugins/hoster/Xdcc.py
index d0630bd29..bd8c6025a 100644
--- a/pyload/plugins/hoster/Xdcc.py
+++ b/pyload/plugins/hoster/Xdcc.py
@@ -23,40 +23,39 @@ from os import makedirs
import re
import sys
import time
-import socket, struct
+import socket
+import struct
from select import select
-from module.utils import save_join
+from module.utils import save_join
from module.plugins.Hoster import Hoster
class Xdcc(Hoster):
__name__ = "Xdcc"
__version__ = "0.32"
- __pattern__ = r'xdcc://.*?(/#?.*?)?/.*?/#?\d+/?' # xdcc://irc.Abjects.net/#channel/[XDCC]|Shit/#0004/
+ __pattern__ = r'xdcc://.*?(/#?.*?)?/.*?/#?\d+/?' # xdcc://irc.Abjects.net/#channel/[XDCC]|Shit/#0004/
__type__ = "hoster"
__config__ = [
- ("nick", "str", "Nickname", "pyload"),
- ("ident", "str", "Ident", "pyloadident"),
- ("realname", "str", "Realname", "pyloadreal")
- ]
+ ("nick", "str", "Nickname", "pyload"),
+ ("ident", "str", "Ident", "pyloadident"),
+ ("realname", "str", "Realname", "pyloadreal")
+ ]
__description__ = """A Plugin that allows you to download from an IRC XDCC bot"""
__author_name__ = ("jeix")
__author_mail__ = ("jeix@hasnomail.com")
-
+
def setup(self):
- self.debug = 0 #0,1,2
+ 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")
-
+
self.pyfile = pyfile
- for i in range(0,3):
+ for i in range(0, 3):
try:
nmn = self.doDownload(pyfile.url)
self.logDebug("%s: Download of %s finished." % (self.__name__, nmn))
@@ -66,35 +65,34 @@ class Xdcc(Hoster):
errno = e.errno
else:
errno = e.args[0]
-
+
if errno in (10054,):
self.logDebug("XDCC: Server blocked our ip, retry in 5 min")
self.setWait(300)
self.wait()
- continue
+ continue
self.fail("Failed due to socket errors. Code: %d" % errno)
-
- self.fail("Server blocked our ip, retry again later manually")
+ self.fail("Server blocked our ip, retry again later manually")
def doDownload(self, url):
- self.pyfile.setStatus("waiting") # real link
+ self.pyfile.setStatus("waiting") # real link
download_folder = self.config['general']['download_folder']
location = join(download_folder, self.pyfile.package().folder.decode(sys.getfilesystemencoding()))
- if not exists(location):
+ if not exists(location):
makedirs(location)
-
+
m = re.search(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')
-
+ chan = m.group(2)
+ bot = m.group(3)
+ pack = m.group(4)
+ nick = self.getConfig('nick')
+ ident = self.getConfig('ident')
+ real = self.getConfig('realname')
+
temp = server.split(':')
ln = len(temp)
if ln == 2:
@@ -103,22 +101,21 @@ class Xdcc(Hoster):
host, port = temp[0], 6667
else:
self.fail("Invalid hostname for IRC Server (%s)" % server)
-
-
+
#######################
# 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))
time.sleep(3)
sock.send("JOIN #%s\r\n" % chan)
sock.send("PRIVMSG %s :xdcc send #%s\r\n" % (bot, pack))
-
+
# IRC recv loop
readbuffer = ""
done = False
@@ -129,7 +126,7 @@ class Xdcc(Hoster):
# done is set if we got our real link
if done:
break
-
+
if retry:
if time.time() > retry:
retry = None
@@ -142,37 +139,36 @@ class Xdcc(Hoster):
sock.close()
self.fail("XDCC Bot did not answer")
-
fdset = select([sock], [], [], 0)
if sock not in fdset[0]:
continue
-
+
readbuffer += sock.recv(1024)
temp = readbuffer.split("\n")
readbuffer = temp.pop()
for line in temp:
- if self.debug is 2: print "*> " + unicode(line, errors='ignore')
- line = line.rstrip()
+ if self.debug is 2:
+ print "*> " + unicode(line, errors='ignore')
+ line = line.rstrip()
first = line.split()
if first[0] == "PING":
sock.send("PONG %s\r\n" % first[1])
-
+
if first[0] == "ERROR":
self.fail("IRC-Error: %s" % line)
-
+
msg = line.split(None, 3)
if len(msg) != 4:
continue
-
- msg = { \
- "origin":msg[0][1:], \
- "action":msg[1], \
- "target":msg[2], \
- "text" :msg[3][1:] \
- }
+ msg = {
+ "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 msg["text"] == "\x01VERSION\x01":
@@ -182,34 +178,34 @@ class Xdcc(Hoster):
self.logDebug("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
-
- if not (bot == msg["origin"][0:len(bot)]
- and nick == msg["target"][0:len(nick)]
- and msg["action"] in ("PRIVMSG", "NOTICE")):
+ pass # don't know how to answer
+
+ if not (bot == msg["origin"][0:len(bot)]
+ and nick == 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 "You already requested that pack" in msg["text"]:
retry = time.time() + 300
-
+
if "you must be on a known channel to request a pack" in msg["text"]:
self.fail("Wrong channel")
-
+
m = re.match('\x01DCC SEND (.*?) (\d+) (\d+)(?: (\d+))?\x01', msg["text"])
if m:
done = True
-
+
# get connection data
- ip = socket.inet_ntoa(struct.pack('L', socket.ntohl(int(m.group(2)))))
- port = int(m.group(3))
+ ip = socket.inet_ntoa(struct.pack('L', socket.ntohl(int(m.group(2)))))
+ port = int(m.group(3))
packname = m.group(1)
-
+
if len(m.groups()) > 3:
self.req.filesize = int(m.group(4))
-
+
self.pyfile.name = packname
filename = save_join(location, packname)
self.logInfo("XDCC: Downloading %s from %s:%d" % (packname, ip, port))
@@ -219,11 +215,10 @@ class Xdcc(Hoster):
if newname and newname != filename:
self.logInfo("%(name)s saved as %(newname)s" % {"name": self.pyfile.name, "newname": newname})
filename = newname
-
+
# kill IRC socket
# sock.send("QUIT :byebye\r\n")
sock.close()
self.lastDownload = filename
return self.lastDownload
-