Exemple #1
0
 /**
  * Efetua a requisição de um arquivo ao servidor.
  *
  * @param  string
  *
  * @return string Arquivo ou link para o arquivo
  */
 public function download($filename = null)
 {
     $http = new Http();
     list($file, $info, $header) = $http->httpRequest("http://legendas.tv/downloadarquivo/{$this->id}");
     if ($filename === null) {
         preg_match('/Location: http:\\/\\/f\\.legendas\\.tv\\/\\w+\\/(.*)/', $header, $filename);
         // O formato abaixo é o nome de retorno do arquivo do legendas.tv, que não diz muita coisa
         $filename = trim($filename[1]);
         // Alteramos para o nome de arquivo refletir o nome completo da legenda
         $filename = $this->data['arquivo'] . substr($filename, strrpos($filename, '.'));
     }
     $filename = str_replace(array('/', '\\'), '_', $filename);
     file_put_contents($filename, $file);
     return $filename;
 }
Exemple #2
0
 /**
  * 发送异步http请求
  * 
  * @param string $url
  * @param string $method
  * @param array $data
  * @param array $cookie
  * @param string $errno
  * @param string $errstr
  * @param number $timeout
  * @param string $response
  * @return Ambigous <boolean, Ambigous, string>
  */
 public static function asyncHttpRequest($url, $method = 'GET', $data = array(), $cookie = array(), &$errno = '', &$errstr = '', $timeout = 3, $response = false)
 {
     // no protocol
     if (!preg_match('/:\\/\\//i', $url)) {
         $url = 'http://' . $url;
     }
     $url_array = parse_url($url);
     if (empty($url_array['host'])) {
         die('url error.');
     }
     $host = $url_array['host'];
     $port = isset($url_array['port']) ? $url_array['port'] : 80;
     $path = !empty($url_array['path']) ? $url_array['path'] : '/';
     $query = !empty($url_array['query']) ? $url_array['query'] : '';
     return Http::httpRequest($host, $port, $method, $path . "?" . $query, $data, $cookie, $errno, $errstr, $timeout, $response);
 }
 /**
  * Loga um usuario junto ao legendas.tv.
  *
  * @param string $username Nome de usuário no legendas.tv
  * @param string $password Senha
  *
  * @return booelan
  *
  * @throws Exception Em caso de problemas no login
  */
 public function login($username, $password)
 {
     $http = new Http();
     list($content) = $http->httpRequest('http://legendas.tv/login', array('data[User][username]' => $username, 'data[User][password]' => $password), 'POST');
     # Trata possíveis erros
     if (strpos($content, 'Usuário ou senha inválidos') !== false) {
         # Remover cookies faz com que não caia no captcha, a princípio
         $this->deletaCookie();
         throw new Exception('Não foi possível se logar no site: Usuário ou senha inválidos.');
     } elseif (strpos($content, 'Palavras de segurança incorretas') !== false) {
         $this->deletaCookie();
         throw new Exception('Muitas tentativas de login incorretas, captcha encontrado');
     }
     # Usuário (provavelmente) logado :P
     return true;
 }