def getImageTranscodeURL(self, path, width, height, **extraOpts): if not path: return '' params = ("&width=%s&height=%s" % (width, height)) + ''.join( ["&%s=%s" % (key, extraOpts[key]) for key in extraOpts]) if "://" in path: imageUrl = self.convertUrlToLoopBack(path) else: imageUrl = "http://127.0.0.1:" + self.getLocalServerPort() + path path = "/photo/:/transcode?url=" + compat.quote_plus(imageUrl) + params # Try to use a better server to transcode for synced servers if self.synced: import plexservermanager selectedServer = plexservermanager.MANAGER.getTranscodeServer( "photo") if selectedServer: return selectedServer.buildUrl(path, True) if self.activeConnection: return self.activeConnection.simpleBuildUrl(self, path) else: util.WARN_LOG("Server connection is None, returning an empty url") return ""
def getImageTranscodeURL(self, path, width, height, **extraOpts): if not path: return '' # Build up our parameters params = "&width={0}&height={1}".format(width, height) # if extraOpts is not None: for key in extraOpts: params += "&{0}={1}".format(key, extraOpts[key]) if "://" in path: imageUrl = self.convertUrlToLoopBack(path) else: imageUrl = "http://127.0.0.1:" + self.getLocalServerPort() + path path = "/photo/:/transcode?url=" + compat.quote_plus(imageUrl) + params # Try to use a better server to transcode for synced servers if self.synced: import plexservermanager selectedServer = plexservermanager.MANAGER.getTranscodeServer( "photo") if selectedServer: return selectedServer.buildUrl(path, True) return self.buildUrl(path, True)
def resolve_socket_url(path): if '://' in path: return path else: return 'unixhttp://' + quote_plus(os.path.realpath(path))
def run_automata(options): if options.port: assert not options.socket, "Specify either socket or port (with optional hostname)" url = 'http://' + (options.hostname or 'localhost') + ':' + str( options.port) else: assert not options.hostname, "Specify either socket or port (with optional hostname)" url = 'unixhttp://' + quote_plus( realpath(options.socket or './socket.dir/default')) a = automata_common.Automata(url, verbose=options.verbose, flags=options.flags.split(','), infoprints=True) if options.abort: a.abort() return try: a.wait(ignore_old_errors=not options.just_wait) except JobError: # An error occured in a job we didn't start, which is not our problem. pass if options.just_wait: return module_ref = find_automata(a, options.package, options.script) if getargspec(module_ref.main).args == ['urd']: # the future! if 'URD_AUTH' in environ: user, password = environ['URD_AUTH'].split(':', 1) else: user, password = None, None info = a.info() urd = automata_common.Urd(a, info, user, password, options.horizon) if options.quick: a.update_method_deps() else: a.update_methods() module_ref.main(urd) return assert not options.horizon, '--horizon is only compatible with urd-enabled automatas' module_ref.auto = automata_common module_ref.a = a module_ref.PATH = a.info()['path'] module_ref.Seq = a.seq # Args you can get to autamata_foo.main # I would say automata, seq and path are the only reasonable names here. path = module_ref.PATH argd = dict(a=a, automata=a, PATH=path, path=path) # run automata script kw = {} for arg in getargspec(module_ref.main).args: kw[arg] = argd[arg] module_ref.main(**kw) return
def cfcookie(netloc, ua, timeout): try: headers = {'User-Agent': ua} req = urllib2.Request(netloc, headers=headers) try: urllib2.urlopen(req, timeout=int(timeout)) except urllib2.HTTPError as response: result = response.read(5242880) jschl = re.findall('name="jschl_vc" value="(.+?)"/>', result)[0] init = re.findall('setTimeout\(function\(\){\s*.*?.*:(.*?)};', result)[-1] builder = re.findall(r"challenge-form\'\);\s*(.*)a.v", result)[0] decryptVal = parseJSString(init) lines = builder.split(';') for line in lines: if len(line) > 0 and '=' in line: sections = line.split('=') line_val = parseJSString(sections[1]) decryptVal = int( eval( str(decryptVal) + str(sections[0][-1]) + str(line_val))) answer = decryptVal + len(urlparse(netloc).netloc) query = '%s/cdn-cgi/l/chk_jschl?jschl_vc=%s&jschl_answer=%s' % ( netloc, jschl, answer) if 'type="hidden" name="pass"' in result: passval = re.findall('name="pass" value="(.*?)"', result)[0] query = '%s/cdn-cgi/l/chk_jschl?pass=%s&jschl_vc=%s&jschl_answer=%s' % ( netloc, quote_plus(passval), jschl, answer) time.sleep(5) cookies = cookielib.LWPCookieJar() handlers = [ urllib2.HTTPHandler(), urllib2.HTTPSHandler(), urllib2.HTTPCookieProcessor(cookies) ] opener = urllib2.build_opener(*handlers) urllib2.install_opener(opener) try: req = urllib2.Request(query, headers=headers) urllib2.urlopen(req, timeout=int(timeout)) except BaseException: pass cookie = '; '.join(['%s=%s' % (i.name, i.value) for i in cookies]) return cookie except BaseException: pass