#!/usr/bin/env python # -*- coding: utf-8 -*- import re from time import time from module.Plugin import Plugin import hashlib import logging class RapidshareCom(Plugin): def __init__(self, parent): Plugin.__init__(self, parent) props = {} props['name'] = "RapidshareCom" props['type'] = "hoster" props['pattern'] = r"http://[\w\.]*?rapidshare.com/files/(\d*?)/(.*)" props['version'] = "0.5" props['description'] = """Rapidshare.com Download Plugin""" props['author_name'] = ("spoob", "RaNaN", "mkaay") props['author_mail'] = ("spoob@pyload.org", "ranan@pyload.org", "mkaay@mkaay.de") self.props = props self.parent = parent self.html = [None, None] self.html_old = None #time() where loaded the HTML self.time_plus_wait = None #time() + wait in seconds self.want_reconnect = False self.no_slots = True self.logger = logging.getLogger("log") self.read_config() if self.config['premium']: self.multi_dl = True else: self.multi_dl = False self.start_dl = False def prepare(self, thread): pyfile = self.parent self.want_reconnect = False tries = 0 while not self.start_dl or not pyfile.status.url: self.req.clear_cookies() self.download_html() pyfile.status.exists = self.file_exists() if not pyfile.status.exists: raise Exception, "The file was not found on the server." self.download_api_data() pyfile.status.filename = self.get_file_name() if self.config['premium']: pyfile.status.url = self.parent.url return True while self.no_slots: self.download_serverhtml() pyfile.status.waituntil = self.time_plus_wait pyfile.status.want_reconnect = self.want_reconnect thread.wait(pyfile) pyfile.status.url = self.get_file_url() if self.no_slots: raise Exception, "No free slots!" tries += 1 if tries > 5: raise Exception, "Error while preparing, HTML dump:"+ str(self.html[0]) + str(self.html[1]) return True def download_api_data(self): """ http://images.rapidshare.com/apidoc.txt """ url = self.parent.url api_url_base = "http://api.rapidshare.com/cgi-bin/rsapi.cgi" api_param = {"sub": "checkfiles_v1", "files": "", "filenames": "", "incmd5": "1"} m = re.compile(self.props['pattern']).search(url) if m: api_param["files"] = m.group(1) api_param["filenames"] = m.group(2) src = self.req.load(api_url_base, cookies=False, get=api_param) if src.startswith("ERROR"): return fields = src.split(",") self.api_data = {} self.api_data["fileid"] = fields[0] self.api_data["filename"] = fields[1] self.api_data["size"] = fields[2] # in bytes self.api_data["serverid"] = fields[3] self.api_data["status"] = fields[4] """ status codes: 0=File not found 1=File OK (Downloading possible without any logging) 2=File OK (TrafficShare direct download without any logging) 3=Server down 4=File marked as illegal 5=Anonymous file locked, because it has more than 10 downloads already 6=File OK (TrafficShare direct download with enabled logging) """ self.api_data["shorthost"] = fields[5] self.api_data["checksum"] = fields[6].strip().lower() # md5 self.api_data["mirror"] = "http://rs%(serverid)s%(shorthost)s.rapidshare.com/files/%(fileid)s/%(filename)s" % self.api_data def download_html(self): """ gets the url from self.parent.url saves html in self.html and parses """ url = self.parent.url self.html[0] = self.req.load(url, cookies=True) self.html_old = time() def download_serverhtml(self): """downloads html with the important informations """ file_server_url = re.search(r"
%s.+/(.+)