【问题标题】:It's working in Localhost but it's not working in my Hosting? (youtube-mp3.org link)它在本地主机中工作,但在我的主机中不起作用? (youtube-mp3.org 链接)
【发布时间】:2017-08-20 22:03:05
【问题描述】:

我正在安装这个链接:youtube-mp3.org download class

youtubetomp3.php //类 php

    <?php
 class YoutubeToMP3 {
    const DOWNLOAD = 1;
    const LINK = 2;

    /**
     * Obtem o link de download do MP3 de um video do YouTube
     * @param  string  $url    URL do video no YouTube
     * @param  integer $action Acão que será executada com o link (YoutubeToMP3::DOWNLOAD,  YoutubeToMP3::LINK) 
     * @return mixed           Quando o parametro $action for definido como YoutubeToMP3::DOWNLOAD redireciona 
     *                         para o download do arquivo, quando YoutubeToMP3::LINK traz o link como retorno
     */
    public static function get($url, $action = self::LINK) {
        $currentTime = time();
        $videoId = self::getYoutubeId($url);

        $itemInfoUrl = "http://www.youtube-mp3.org/a/itemInfo/?video_id={$videoId}&ac=www&t=grp&r={$currentTime}";
        $itemInfo = self::httpRequest($itemInfoUrl);

        $sequence = $videoId . $currentTime;
        $requestId = $itemInfo['h'];
        $cc = self::cc($sequence);

        $MP3URL = "http://www.youtube-mp3.org/get?ab=128&video_id={$videoId}&h={$requestId}&r={$currentTime}.{$cc}";

        if ($action == self::DOWNLOAD):
            self::redirect($MP3URL);
        else:
            return $MP3URL;
        endif;
    }

    /**
     * Realiza uma requisição do tipo GET para uma url dada
     * @param  string $url Url que será requisitada
     * @return array       Array associativo do JSON retornado
     */
    private static function httpRequest ($url) {
        $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

        $result = curl_exec($ch);
        curl_close($ch);

        // Clear response string
        $jsonString = str_replace(array('info = ', ';'), '', $result);
        $parsedJSON = json_decode($jsonString, true);

        return $parsedJSON;
    }

    /**
     * Obtem o ID do um video do YouTube a partir de uma URL
     * @param  string $url URL do video
     * @return mixed       String com o id caso seja uma URL válida ou false do contrário
     */
    private static function getYoutubeId ($url) {
        $pattern = '%^(?:https?://)?(?:www\.)?(?:youtu\.be/|youtube\.com(?:/embed/|/v/|.*v=))([\w-]{10,12})($|&).*$%x';
        $result = preg_match($pattern, $url, $matches);

        if ($result !== false):
            return $matches[1];
        endif;

        return false;
    }

    /**
     * Gera uma sequencia necessária para a API do youtube-mp3.org
     * @param  string $a Id do video concatenado com o timestamp atual
     * @return string    Sequencia
     */
    private static function cc ($a) {
        $AM = 65521; 
        $c = 1; 
        $b = 0;
        $d; 
        $e;

        for ($e = 0; $e < strlen($a); $e++):
            $d = self::charCodeAt($a,$e);
        $c = ($c + $d) % $AM;
        $b = ($b + $c) % $AM;
        endfor;

        return $b << 16 | $c;
    }

    /**
     * Metodo utilitário
     */
    private static function charCodeAt($str, $i){
        return ord(substr($str, $i, 1));
    }

    /**
     * Header Redirect
     *
     * Header redirect in two flavors
     * For very fine grained control over headers, you could use the Output
     * Library's set_header() function.
     *
     * @param string $uri URL
     * @param string $method Redirect method  'auto', 'location' or 'refresh'
     * @param int    $code HTTP Response status code
     * @return void
     */
    private static function redirect ($uri = '', $method = 'auto', $code = NULL) {
        if (!preg_match('#^(\w+:)?//#i', $uri)) {
            $uri = site_url($uri);
        }

        if ($method === 'auto' && isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') !== FALSE) {
            $method = 'refresh';
        } elseif ($method !== 'refresh' && (empty($code) OR ! is_numeric($code))) {
            if (isset($_SERVER['SERVER_PROTOCOL'], $_SERVER['REQUEST_METHOD']) && $_SERVER['SERVER_PROTOCOL'] === 'HTTP/1.1') {
                $code = ($_SERVER['REQUEST_METHOD'] !== 'GET')? 303 : 307;
            } else {
                $code = 302;
            }
        }

        switch ($method) {
            case 'refresh':
                header('Refresh:0;url='.$uri);
            break;
            default:
                header('Location: '.$uri, TRUE, $code);
            break;
        }
        exit;
    }
}
?>

//使用php

<?php 
include ('youtubetomp3.php');
echo $link = YoutubeToMP3::get('http://www.youtube.com/watch?v=tGa5-nojscY', YoutubeToMP3::DOWNLOAD);
?>

可能是这些问题;

  • a-) 是因为 youtube-mp3.org 还是我的托管?

  • b-) 是不是因为 $currentTime = time(); ?

  • c-) 是不是因为 $requestId = $itemInfo['h']; ?

【问题讨论】:

  • 有什么问题?你得到什么错误(检查日志!)?你希望它做什么?
  • 可能是您的主机中没有启用或安装 curl,这就是您无法使用它的原因,您应该检查日志以查看错误。
  • 你的 localhost 和使用 phpinfo() 托管有什么区别;
  • @Burak, @Bart Friederichs (error dosyasında bunlar yazıyor) 这是我的错误日志:PHP Warning: curl_setopt() [&lt;a href='function.curl-setopt'&gt;function.curl-setopt&lt;/a&gt;]: CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is enabled or an open_basedir is set in /home/***/public_html/***.com/youtubetomp3.php on line 44

标签: php hash time localhost hosting


【解决方案1】:

根据您在 cmets 中提到的日志中的错误,您需要设置 safe_mode = Off 并删除 php.ini 文件中有关 open_base_dir 的行。如果您无法访问您的 php.ini 文件,请咨询您的托管服务提供商。

【讨论】:

    【解决方案2】:

    这是因为 ip adress.Youtube-MP3.org 在他们的下载链接中使用了 info.h。而 info.h 是为用户的 ip 地址生成的,下载链接只属于连接器用户。所以你不能与其他人分享users.Clearly,在网站中,服务器使用自己的 ip 地址并从 youtubemp3 获取链接以获取自己的 ip 地址,用户无法使用它。但在 localhost 服务器和用户的 ip 地址相同,因此 php 可以正常运行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-25
      • 2013-05-20
      • 2019-12-27
      • 2019-05-24
      • 1970-01-01
      相关资源
      最近更新 更多