def get_info(cls, url="", html=""): url = fixurl(url, unquote=True) info = { "name": parse_name(url), "pattern": {}, "size": 0, "status": 3 if url else 8, "url": replace_patterns(url, cls.URL_REPLACEMENTS), } try: info["pattern"] = re.match(cls.__pattern__, url).groupdict() except Exception: pass return info
def handle_premium(self, pyfile): #: Fix the links for simply-debrid.com! self.link = replace_patterns(pyfile.url, [("clz.to", "cloudzer.net/file") ("http://share-online", "http://www.share-online") ("ul.to", "uploaded.net/file") ("uploaded.com", "uploaded.net") ("filerio.com", "filerio.in") ("lumfile.com", "lumfile.se")]) if 'fileparadox' in self.link: self.link = self.link.replace("http://", "https://") self.data = self.load("http://simply-debrid.com/api.php", get={'dl': self.link}) if 'tiger Link' in self.data or 'Invalid Link' in self.data or ('API' in self.data and 'ERROR' in self.data): self.error(_("Unable to unrestrict link")) self.link = self.data self.wait(5)
def prepare(self): self.direct_dl = False 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 self.LINK_PATTERN: if self.LINK_FREE_PATTERN is None: self.LINK_FREE_PATTERN = self.LINK_PATTERN if self.LINK_PREMIUM_PATTERN is None: self.LINK_PREMIUM_PATTERN = self.LINK_PATTERN if self.DIRECT_LINK is None: self.direct_dl = bool(self.account) else: self.direct_dl = self.DIRECT_LINK self.pyfile.url = replace_patterns(self.pyfile.url, self.URL_REPLACEMENTS)
if html: if cls.OFFLINE_PATTERN and re.search(cls.OFFLINE_PATTERN, html) is not None: info['status'] = 1 elif cls.TEMP_OFFLINE_PATTERN and re.search(cls.TEMP_OFFLINE_PATTERN, html) is not None: info['status'] = 6 elif cls.NAME_PATTERN: m = re.search(cls.NAME_PATTERN, html) if m is not None: info['status'] = 2 info['pattern'].update(m.groupdict()) if 'N' in info['pattern']: name = replace_patterns(info['pattern']['N'], cls.NAME_REPLACEMENTS) info['name'] = parse_name(name) return info #@TODO: Remove in 0.4.10 def setup_base(self): account_name = self.classname.rsplit("Folder", 1)[0] if self.account: self.req = self.pyload.requestFactory.getRequest(account_name, self.account.user) self.premium = self.account.info['data']['premium'] #@NOTE: Avoid one unnecessary get_info call by `self.account.premium` here else: self.req = self.pyload.requestFactory.getRequest(account_name) self.premium = False
def process(self, pyfile): pyfile.url = replace_patterns(pyfile.url, self.URL_REPLACEMENTS) html = self.load(pyfile.url) 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.temp_offline() #: Get config use3d = self.get_config('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.get_config('fmt') if not desired_fmt: desired_fmt = quality.get(self.get_config('quality'), 18) elif desired_fmt not in self.formats: self.log_warning(_("FMT %d unknown, using default") % desired_fmt) desired_fmt = 0 #: 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']), urllib.unquote(x['url'])) for x in streams] # self.log_debug("Found links: %s" % streams) self.log_debug("AVAILABLE STREAMS: %s" % [x[0] for x in streams]) #: Build dictionary of supported itags (3D/2D) allowed = lambda x: self.get_config(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] is use3d] or streams) self.log_debug("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.log_debug("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.log_debug("Chosen fmt: %s" % fmt) url = fmt_dict[fmt] self.log_debug("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.invalid_chars: 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 m is None: 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)