public function download($save_dir, $save_filename, $ext = true) { $b = new Http(); $b->do_get($this->url() . "&fmt=22"); if (preg_match("/var[\\s]+swfArgs[\\s]*=[\\s]*(\\{.+?\\})/m", $b->body(), $match)) { $json = Text::parse_json($match[1]); $base_url = "http://www.youtube.com/get_video?video_id=" . $json["video_id"] . "&t=" . $json["t"]; $url = $base_url . "&fmt=22"; if ($b->do_head($url)->status() !== 200) { $url = $base_url . "&fmt=18"; } $b->do_download($url, File::absolute($save_dir, $save_filename) . ($ext ? $this->ext : "")); return; } throw new Exception("undef video"); }
/** * 短縮urlから復元する * @param $url * @return string */ public static function lookup($url) { if (strpos($url, "http://tinyurl.com/") !== 0) { $url = "http://tinyurl.com/" . $url; } $http = new Http(); $http->status_redirect(false); $http->do_get($url); if ($http->status() === 301 && preg_match("/Location:[ ](.*)/i", $http->head(), $redirect_url)) { return trim($redirect_url[1]); } return $url; /*** eq("http://rhaco.org",Tinyurl::lookup("http://tinyurl.com/6bkavu")); eq("http://rhaco.org",Tinyurl::lookup("6bkavu")); */ }
public function download($save_dir, $save_filename, $ext = true) { $b = new Http(); if (!empty($this->original_image_url)) { $b->do_download($this->original_image_url, File::absolute($save_dir, $save_filename) . ($ext ? ".jpg" : "")); return; } else { $b->do_get($this->url); if (Tag::setof($tag, $b->body(), "body")) { foreach ($tag->in("script") as $s) { if (preg_match("/addVariable\\('url', '(.+?)'\\)/", $s->value(), $match)) { $b->do_download(trim($match[1]), File::absolute($save_dir, $save_filename) . ($ext ? ".flv" : "")); return; } } } } throw new Exception("undef video"); }
/** * Repositoryが提供するアプリケーションとライブラリの一覧を表示する * -rep rhaco.org */ public static function __setup_rep__(Request $req, $value) { $http = new Http(); $q = $req->in_vars("q"); foreach (array("lib" => "Libraries:", "app" => "\nApplications:") as $type => $label) { if (Tag::setof($tag, $http->do_get(Repository::xml_url($type, $value)), "repository")) { $list = array(); $max_length = 0; foreach ($tag->in("package") as $p) { if (empty($q) || Text::imatch($p->in_param("name") . " " . $p->in_param("path") . " " . $p->in_param("summary") . " " . $p->value(), $q)) { $list[] = $p; if ($max_length < strlen($p->in_param("path"))) { $max_length = strlen($p->in_param("path")); } } } if (!empty($list)) { self::info_print($label); foreach ($list as $p) { self::println(" " . str_pad($p->in_param("path"), $max_length) . " " . $p->in_param("summary")); } } } } }
private static function server_address($url) { $server = $url; if (strpos($server, "://") === false) { $server = isset(self::$server_alias[$server]) ? self::$server_alias[$server] : "http://" . $server; } if (substr($server, -1) == "/") { $server = substr($server, 0, -1); } try { $http = new Http(); if ($http->do_get($server . "/__repository__.php/check")->status() === 200 && $http->body() == "") { return $server; } if ($http->do_get($server . "/__repository__.xml")->status() === 200) { if (Tag::setof($tag, $http->body(), "map")) { foreach ($tag->in("repository") as $rep) { try { if (!$rep->is_param("domain")) { return self::server_address($rep->in_param("url")); } } catch (InvalidArgumentException $e) { } } } } } catch (InvalidArgumentException $e) { } throw new InvalidArgumentException("server `" . $url . "` not found"); }