Example #1
0
 /**
  * ハブサーバーに通知する
  */
 public function publish()
 {
     if (empty($this->hubs) || empty($this->urls)) {
         return;
     }
     $params = $this->params();
     $http = new Http();
     foreach ($this->hubs() as $hub) {
         $http->raw(implode('&', $params));
         $http->do_post($hub);
         if ($http->status() != 204) {
             throw new Exception(sprintf('[%d] %s', $http->status(), $http->body()));
         }
     }
 }
Example #2
0
 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");
 }
Example #3
0
 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");
 }
Example #4
0
 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");
 }