def process(self, pyfile): self.prepare() pyfile.url = replace_patterns(pyfile.url, self.FILE_URL_REPLACEMENTS) if not re.match(self.__pattern__, pyfile.url): if self.premium: self.handleOverriden() else: self.fail("Only premium users can download from other hosters with %s" % self.HOSTER_NAME) else: try: # Due to a 0.4.9 core bug self.load would use cookies even if # cookies=False. Workaround using getURL to avoid cookies. # Can be reverted in 0.5 as the cookies bug has been fixed. self.html = getURL(pyfile.url, decode=True) self.file_info = self.getFileInfo() except PluginParseError: self.file_info = None self.location = self.getDirectDownloadLink() if not self.file_info: pyfile.name = html_unescape(unquote(urlparse( self.location if self.location else pyfile.url).path.split("/")[-1])) if self.location: self.startDownload(self.location) elif self.premium: self.handlePremium() else: self.handleFree()
def process(self, pyfile): self.req.setCookieJar(None) pyfile.url = replace_patterns(pyfile.url, self.FILE_URL_REPLACEMENTS) valid_url = pyfile.url headers = self.load(valid_url, just_header=True) self.html = None if headers.get('code') == 302: valid_url = headers.get('location') headers = self.load(valid_url, just_header=True) if headers.get('code') == 200: content_type = headers.get('content-type') if content_type and content_type.startswith("text/html"): # Undirect acces to requested file, with a web page providing it (captcha) self.html = self.load(valid_url) self.handleFree() else: # Direct access to requested file for users using free.fr as Internet Service Provider. self.download(valid_url, disposition=True) elif headers.get('code') == 404: self.offline() else: self.fail("Invalid return code: " + str(headers.get('code')))
def process(self, pyfile): pyfile.url = replace_patterns(pyfile.url, self.URL_REPLACEMENTS) valid_url = pyfile.url headers = self.load(valid_url, just_header=True) if headers.get('code') == 302: valid_url = headers.get('location') headers = self.load(valid_url, just_header=True) if headers.get('code') == 200: content_type = headers.get('content-type') if content_type and content_type.startswith("text/html"): # Undirect acces to requested file, with a web page providing it (captcha) self.html = self.load(valid_url) self.handleFree(pyfile) else: # Direct access to requested file for users using free.fr as Internet Service Provider. self.link = valid_url self.download(self.link, disposition=True) elif headers.get('code') == 404: self.offline() else: self.fail(_("Invalid return code: ") + str(headers.get('code')))
def process(self, pyfile): pyfile.url = replace_patterns(pyfile.url, self.FILE_URL_REPLACEMENTS) self.req.setOption("timeout", 120) if self.premium and (not self.SH_CHECK_TRAFFIC or self.checkTrafficLeft()): self.handlePremium() else: self.html = self.load(pyfile.url, decode=not self.SH_BROKEN_ENCODING, cookies=self.SH_COOKIES) self.getFileInfo() self.handleFree()
def getInfo(urls): h = getRequest() h.c.setopt(HTTPHEADER, ["Accept: text/html", "User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0"]) for url in urls: html = h.load(url, decode=True) file_info = parseFileInfo(ShareRapidCom, replace_patterns(url, ShareRapidCom.FILE_URL_REPLACEMENTS), html) yield file_info
def getInfo(urls): h = getRequest() h.c.setopt(HTTPHEADER, [ "Accept: text/html", "User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0" ]) for url in urls: html = h.load(url, decode=True) file_info = parseFileInfo( ShareRapidCom, replace_patterns(url, ShareRapidCom.FILE_URL_REPLACEMENTS), html) yield file_info
def decrypt(self, pyfile): pyfile.url = replace_patterns(pyfile.url, self.FILE_URL_REPLACEMENTS) self.html = self.load(pyfile.url, decode=True) package_name, folder_name = self.getPackageNameAndFolder() self.package_links = self.getLinks() if hasattr(self, 'PAGES_PATTERN') and hasattr(self, 'loadPage'): self.handleMultiPages() self.logDebug('Package has %d links' % len(self.package_links)) if self.package_links: self.packages = [(package_name, self.package_links, folder_name)] else: self.fail('Could not extract any links')
def prepare(self): self.pyfile.error = "" #@TODO: Remove in 0.4.10 self.info = {} self.html = "" self.link = "" #@TODO: Move to Hoster in 0.4.10 self.links = [] #@TODO: Move to Hoster in 0.4.10 if self.LOGIN_PREMIUM and not self.premium: self.fail(_("Required premium account not found")) if self.LOGIN_ACCOUNT and not self.account: self.fail(_("Required account not found")) self.req.setOption("timeout", 120) if isinstance(self.COOKIES, list): set_cookies(self.req.cj, self.COOKIES) self.pyfile.url = replace_patterns(self.pyfile.url, self.URL_REPLACEMENTS)
def process(self, pyfile): self.prepare() pyfile.url = replace_patterns(pyfile.url, self.FILE_URL_REPLACEMENTS) if not re.match(self.__pattern__, pyfile.url): if self.premium: self.handleOverriden() else: self.fail( "Only premium users can download from other hosters with %s" % self.HOSTER_NAME) else: try: # Due to a 0.4.9 core bug self.load would use cookies even if # cookies=False. Workaround using getURL to avoid cookies. # Can be reverted in 0.5 as the cookies bug has been fixed. self.html = getURL(pyfile.url, decode=True) self.file_info = self.getFileInfo() except PluginParseError: self.file_info = None self.location = self.getDirectDownloadLink() if not self.file_info: pyfile.name = html_unescape( unquote( urlparse(self.location if self.location else pyfile.url ).path.split("/")[-1])) if self.location: self.startDownload(self.location) elif self.premium: self.handlePremium() else: self.handleFree()
def process(self, pyfile): pyfile.url = replace_patterns(pyfile.url, self.FILE_URL_REPLACEMENTS) html = self.load(pyfile.url, decode=True) if re.search(r'<div id="player-unavailable" class="\s*player-width player-height\s*">', html): self.offline() if "We have been receiving a large volume of requests from your network." in html: self.tempOffline() #get config use3d = self.getConfig("3d") if use3d: quality = {"sd": 82, "hd": 84, "fullhd": 85, "240p": 83, "360p": 82, "480p": 82, "720p": 84, "1080p": 85, "3072p": 85} else: quality = {"sd": 18, "hd": 22, "fullhd": 37, "240p": 5, "360p": 18, "480p": 35, "720p": 22, "1080p": 37, "3072p": 38} desired_fmt = self.getConfig("fmt") if desired_fmt and desired_fmt not in self.formats: self.logWarning("FMT %d unknown - using default." % desired_fmt) desired_fmt = 0 if not desired_fmt: desired_fmt = quality.get(self.getConfig("quality"), 18) #parse available streams streams = re.search(r'"url_encoded_fmt_stream_map": "(.*?)",', html).group(1) streams = [x.split('\u0026') for x in streams.split(',')] streams = [dict((y.split('=', 1)) for y in x) for x in streams] streams = [(int(x['itag']), unquote(x['url'])) for x in streams] #self.logDebug("Found links: %s" % streams) self.logDebug("AVAILABLE STREAMS: %s" % [x[0] for x in streams]) #build dictionary of supported itags (3D/2D) allowed = lambda x: self.getConfig(self.formats[x][0]) streams = [x for x in streams if x[0] in self.formats and allowed(x[0])] if not streams: self.fail("No available stream meets your preferences") fmt_dict = dict([x for x in streams if self.formats[x[0]][4] == use3d] or streams) self.logDebug("DESIRED STREAM: ITAG:%d (%s) %sfound, %sallowed" % (desired_fmt, "%s %dx%d Q:%d 3D:%s" % self.formats[desired_fmt], "" if desired_fmt in fmt_dict else "NOT ", "" if allowed(desired_fmt) else "NOT ")) #return fmt nearest to quality index if desired_fmt in fmt_dict and allowed(desired_fmt): fmt = desired_fmt else: sel = lambda x: self.formats[x][3] # select quality index comp = lambda x, y: abs(sel(x) - sel(y)) self.logDebug("Choosing nearest fmt: %s" % [(x, allowed(x), comp(x, desired_fmt)) for x in fmt_dict.keys()]) fmt = reduce(lambda x, y: x if comp(x, desired_fmt) <= comp(y, desired_fmt) and sel(x) > sel(y) else y, fmt_dict.keys()) self.logDebug("Chosen fmt: %s" % fmt) url = fmt_dict[fmt] self.logDebug("URL: %s" % url) #set file name file_suffix = self.formats[fmt][0] if fmt in self.formats else ".flv" file_name_pattern = '<meta name="title" content="(.+?)">' name = re.search(file_name_pattern, html).group(1).replace("/", "") # Cleaning invalid characters from the file name name = name.encode('ascii', 'replace') for c in self.invalidChars: name = name.replace(c, '_') pyfile.name = html_unescape(name) time = re.search(r"t=((\d+)m)?(\d+)s", pyfile.url) ffmpeg = which("ffmpeg") if ffmpeg and time: m, s = time.groups()[1:] if not m: m = "0" pyfile.name += " (starting at %s:%s)" % (m, s) pyfile.name += file_suffix filename = self.download(url) if ffmpeg and time: inputfile = filename + "_" os.rename(filename, inputfile) subprocess.call([ ffmpeg, "-ss", "00:%s:%s" % (m, s), "-i", inputfile, "-vcodec", "copy", "-acodec", "copy", filename]) os.remove(inputfile)