Ejemplo n.º 1
0
    def parseHTML(self, html):
        """parse given html
        returns dictionary with keys: IM, Forum, Alt Forum, HTML, Direct, Forum Thumb, Alt Forum Thumb, HTML Thumb, Twitter Link and basic links"""
        soup = BeautifulSoup(html)

	textarea=soup.find('textarea').contents[0]
	text = BeautifulSoup(textarea)
	link=text.find('a')
	imageLink = link['href']
        thumbLink = link.find('img')['src']
        adLink = link['href']
        links = createLinks(adLink, None, imageLink,thumbLink)

        return links, [imageLink, thumbLink, adLink]
Ejemplo n.º 2
0
    def parseResponse(self, response, fileName):
        xmldoc = minidom.parse(StringIO(response))

        uploadSuccessful = xmldoc.getElementsByTagName("rsp")[0].getAttribute("stat") == 'ok'

        if not uploadSuccessful:
            err = xmldoc.getElementsByTagName("err")[0]
            code = err.getAttribute("code")
            msg = err.getAttribute("msg")
            raise Exception("Error: " + msg + " (" + code + ")")

        #links = {"IM":xmldoc.getElementsByTagName("mediaurl")[0].firstChild.data}
        link = xmldoc.getElementsByTagName("mediaurl")[0].firstChild.data
        links = createLinks(link, fileName)
        return links
Ejemplo n.º 3
0
    def parseHTML(self, html):
        """parse given html
        returns dictionary with keys: IM, Forum, Alt Forum, HTML, Direct, Forum Thumb, Alt Forum Thumb, HTML Thumb, Twitter Link"""
        soup = BeautifulSoup(html)

        link=soup.find('table').findNext('table').findNext('table').tr.findNext('table').findNext('table').tr.td.a
        adLink=link['href']

        thumbLink=link.img['src']

        directhtmlinput=soup.find(attrs={'name' : 'directhtml'})
        alink=BeautifulSoup(directhtmlinput['value'])
        imageLink=alink.find('img')['src']

        links = createLinks(adLink, None, imageLink,thumbLink)

        return links, [imageLink, thumbLink, adLink]
Ejemplo n.º 4
0
    def parseHTML(self, html):
        """parse given xml
        returns dictionary with keys: IM, Forum, Alt Forum, HTML, Direct, Forum Thumb, Alt Forum Thumb, HTML Thumb, Twitter Link"""
        soup = BeautifulSoup(html)

	alink=soup.find('table').tr.td.a
        adLink=alink["href"]

        inputimg=soup.find('table').findNext('table').tr.td.input
        imageLink=inputimg['value']

        inputthumb=soup.find('table').findNext('table').tr.findNext('tr').td.input
        tlink=BeautifulSoup(inputthumb['value'])
        thumbLink=tlink.find('img')['src']

        links = createLinks(adLink, None, imageLink,thumbLink)
        
        return links, [imageLink, thumbLink, adLink]
Ejemplo n.º 5
0
    def parseResponse(self, response, fileName):
        #print response
        """<rsp stat="ok"><image_hash>o03Rj</image_hash><delete_hash>9PkXVHJf7h7Ax4b</delete_hash><original_image>http://i.imgur.com/o03Rj.jpg</original_image><large_thumbnail>http://i.imgur.com/o03Rjl.jpg</large_thumbnail><small_thumbnail>http://i.imgur.com/o03Rjs.jpg</small_thumbnail><imgur_page>http://imgur.com/o03Rj</imgur_page><delete_page>http://imgur.com/delete/9PkXVHJf7h7Ax4b</delete_page></rsp>"""

        tag = "<original_image>"
        link_start = response.find(tag)
        if link_start < 0:
            raise Exception("Upload failed " + response)
        link_end = response.find("</original_image>")

        tag = "<imgur_page>"
        link_start = response.find(tag)
        if link_start < 0:
            raise Exception("Upload failed " + response)
        link_end = response.find("</imgur_page>")
        
        link = response[link_start + len(tag): link_end]
        links = createLinks(link, fileName)
        return links
Ejemplo n.º 6
0
    def upload(self, file, callbackFunction, username, password):
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.connect(("rapidshare.com", 80))

        uls = sock.send('GET /cgi-bin/rsapi.cgi?sub=nextuploadserver_v1 HTTP/1.0\r\n\r\n')
        uploadserver = str(uls)
        sock.close()

        f = open(file)
        filecontent = f.read()
        size = len(filecontent)
        md5hash = md5(filecontent)
        f.close()

        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.connect(("rs" + uploadserver + "l3.rapidshare.com", 80))

        boundary = "---------------------632865735RS4EVER5675865"
        contentheader = boundary + "\r\nContent-Disposition: form-data; name=\"rsapi_v1\"\r\n\r\n1\r\n"

        if username:
#            if type == "prem":
            contentheader += boundary + "\r\nContent-Disposition: form-data; name=\"login\"\r\n\r\n" + username + "\r\n"
            contentheader += boundary + "\r\nContent-Disposition: form-data; name=\"password\"\r\n\r\n" + password + "\r\n"

#            if type == "col":
#                contentheader += boundary + "\r\nContent-Disposition: form-data; name=\"freeaccountid\"\r\n\r\n" + username + "\r\n"
#                contentheader += boundary + "\r\nContent-Disposition: form-data; name=\"password\"\r\n\r\n" + password + "\r\n"

        contentheader += boundary + "\r\nContent-Disposition: form-data; name=\"filecontent\"; filename=\"" + file + "\"\r\n\r\n"
        contenttail = "\r\n" + boundary + "--\r\n"
        contentlength = len(contentheader) + size + len(contenttail)

        header = "POST /cgi-bin/upload.cgi HTTP/1.1\r\nHost: rs" + uploadserver + ".rapidshare.com\r\nContent-Type: multipart/form-data; boundary=" + boundary + "\r\nContent-Length: " + str(contentlength) + "\r\n\r\n" + contentheader

        sock.send(header)

        f = open(file)

        bufferlen = 0
        while True:
            chunk = f.read(64000)
            if not chunk:
                break
            sock.send(chunk)
            bufferlen += len(chunk)
            self.progress(0,0,upload_t = size, upload_d = bufferlen)
          
        sock.send(contenttail)

        result = sock.recv(1000000)
        f.close()
        sock.close()

        newhash = re.search('File1.4=(\w+)', result)
        oldhash = "File1.4=" + md5hash.hexdigest().upper()
        if not newhash:
            raise Exception("Upload unsuccessful")
        if newhash.group() == oldhash:
            upload = re.search('File1.1=(\S+)', result)
            link = upload.group()[8:]#Cut'File1.1='
            links = createLinks(link, file)
            callbackFunction(links, self.file_number, file)
        else:
            raise Exception("Upload unsuccessful")