it-books API没有;不要让用户直接下载所选的书


it-books API doesn't let the user download directly a chosen book

我需要一些帮助,因为我编写了一个使用这个好的API的PHP类:http://it-ebooks-api.info而且效果很好。在我的表单中,你可以放置一个参数,比如PHP、Jquery等,你会得到前10本书的结果,最后我使用Select让用户查看所有其他的结果/书。

现在我注意到只有API的原始网站可以让你直接下载书籍。我猜他们会将一些JavaScript代码与一段时间后出现故障的会话一起使用,以阻止他们的免费API用户直接下载您可能需要的书籍。

如果你点击下载链接,你会在另一个页面上看到你必须完成的带有captcha的书的详细信息!完成后,下载终于开始了!

有没有可能避免这种情况,并有可能直接下载我需要的书,而不必用那个烦人的captcha登录该死的页面?

这是一个免费的API,但这种行为超越了自由:你必须接受访问该页面,以正确的方式执行captcha(当然),然后,感谢他们或看在上帝的份上,你才能下载你选择的书。

这种态度让我很生气,因为我不喜欢这样一个假的免费API,但尽管如此,我还是在网上搜索了一下,但我没有得到更好的东西。

我真的很感激你的帮助。

这是我的课,我称之为EboksSearchDownload

    <?php
     class EbooksSearchDownload 
     {
     // Error code / description (Note: request success code = 0)
     public $Error;
    // Request query execution time (seconds)
    public $Time; 
    // Array which contains all details of the books
    public $books;
    // The total number of books found 
    public $total;
   // The total number of pages/results (Note: limit = 10 books per page)
   public $pages;

    public function __construct($ebook, $page)
    {
        /**
         * See here for info about this API: http://it-ebooks-api.info/
         * First the book search, this way:          
         * http://it-ebooks-api.info/v1/search/{QUERY}/page/{NUMBER}
         */
        $response = $this->fetch("http://it-ebooks-api.info/v1/search/{$ebook}/page/{$page}");
        // decode the JSON into an associative array, setting the option to true
        $data = json_decode($response, true);
        # This will print out the contents of the array in a nice readable format     
        # echo '<pre>' . print_r($data, true) . '</pre>';
        $this->total = $data['Total'];
        /**
         * HOW TO GET THE TOTAL NUMBER OF PAGES:
         *
         * As the API shows only 10 books per page, if I want to know how many pages contain 
         * all books (here the property, $total), I have to pass thru three different steps:
         *
         * 1) I divide the total number of the books by 10: e.g. 141/10 gives 14,1
         *
         * 2) then I use the function intval() to get the integer value stripping the 
         *    the decimal part: e.g. 14
         *
         * 3) then, if there is a remainder from the division, I get it with the modulus
         *    operator % and I add one more page to obtain the number of the total pages:
         *    e.g. here the 1 and in this case, I've got 141 books on 15 pages. 
         */
        $this->pages = intval($data['Total']/10) + ($data['Total']%10 ? 1 : 0);

        // Extract all details about the books
        // Here I use 'Books' as the key to the array to get all info. 
        // 'Books' and 'ID' come from the API above.
        for ( $i = 0; $i < count($data['Books']); $i++ ) 
            {
                /** 
                 * Then the download and other info of the chosen book, this way:
                 * http://it-ebooks-api.info/v1/book/{ID}
                 */
                    $response = $this->fetch("http://it-ebooks-api.info/v1/book/{$data['Books'][$i]['ID']}");
                    $this->books[] = json_decode($response, true);
            }               
        }
    public function fetch($host) 
    {
        if ( function_exists('curl_init') )
            {   
                    $ch = curl_init();
                    curl_setopt($ch, CURLOPT_URL, $host);
                    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                    $response = curl_exec($ch);
                    curl_close($ch);
            }
        else if ( ini_get('allow_url_fopen') ) 
            {
                    $response = file_get_contents($host, 'r');
            }
        return $response;
        }
 }

以下是我如何使用它(我省略了头部和身体标签):

<?php
error_reporting(E_ALL ^ E_NOTICE);
require_once 'settings_ebook.php';
require_once 'EbooksSearchDownload.class.php';
echo "
<h1 class='centra sottolineato grassetto rosso'>Cerca un argomento e scarica un ebook</h1>
<form action='ebook.php' method='get' id='ebookForm'>
    <fieldset>
        <legend class='centra'>Inserisci un argomento e cerca un ebook</legend>
        <ol>
            <li>
                <label for='ebook'>Ebook<abbr title='campo obbligatorio'>*</abbr></label>
                <input type='text' name='ebook' id='ebook' value='" . ( isset($_GET['ebook']) && ! empty($_GET['ebook']) ? strip_tags(trim($_GET['ebook'])) : '' ) . "' class='" . ( isset($_GET['ebook']) && empty($_GET['ebook']) ? 'error' : '' ) . "'  />   
            </li>
        </ol>
    </fieldset>
        <p class='controls'>   
            <input type='submit' value='Invia' />           
        </p> 
</form>";

if ( isset($_GET['ebook']) && ! empty($_GET['ebook']) ) 
    {
        $_GET['page'] = isset($_GET['page']) ? $_GET['page'] : 1;
        $eb = new EbooksSearchDownload($_GET['ebook'], $_GET['page']);
        /**
         * Check for the results!
         * 
         */         
        if ( is_array($eb->books) )
            { 
                echo "Totale libri: " . $eb->total . " - Pagina {$_GET['page']} di " . $eb->pages . "<br /><br /><hr class='style-eight'></hr>";
                foreach ( $eb->books as $book )
                    {   
                        // the first 10 books:                      
                        echo '<p>' .                    
                        //  'Error code: ' . $book['Error']  . '<br />' .
                        //  'Request query execution time: ' . $book['Time']  . '<br /></p>' .
                            'Tempo esecuzione della query: ' . $book['Time'] . '<br /></p>' .
                            '<p class="grassetto">' . 'ID ebook: ' . '</p>' .
                            '<p>' . $book['ID'] . '</p>' .
                            '<p class="grassetto rosso sottolineato">' . 'Titolo: ' . '</p>' .
                            '<p class="rosso">' . $book['Title'] . '</p>' . 
                            '<p class="grassetto" >' . 'Sottotitolo: ' . '</p>' .
                            '<p>' . $book['SubTitle'] . '</p>' .
                            '<p class="grassetto">' . 'Descrizione: ' . '</p>' .
                            '<p>' . $book['Description'] . '<br /></p>' .
                            '<p class="grassetto rosso sottolineato">' . 'Autore: ' . '</p>' .
                            '<p class="rosso">' . $book['Author'] . '<br /></p>' .
                            '<p class="grassetto">' . 'ISBN: ' . '</p>' .   
                            '<p>' . $book['ISBN'] . '<br /></p>' .
                            '<p class="grassetto">' . 'Anno: ' . '</p>' .
                            '<p>' . $book['Year'] . '<br /></p>' .
                            '<p class="grassetto">' . 'Pagine: ' . '</p>' .
                            '<p>' . $book['Page'] . '<br /></p>' .
                            '<p class="grassetto rosso sottolineato">' . 'Casa Editrice: ' . '</p>' .
                            '<p class="rosso">' . $book['Publisher'] . '<br /></p>' .
                            '<p><img src="' . $book['Image'] . '" alt="" />' . '</p>' .
                            '<p><a href="' . $book['Download'] . '" target="_blank">' . 'scarica' . '</a>' . '<br /></p><hr class="style-eight"></hr>';
                    }
                echo "
                    <form action='ebook.php' method='get'>
                            Pagina
                                <select name='page' onchange='this.form.submit()'>";
                        for ( $i = 1; $i <= $eb->pages; $i++ )
                            {
                                echo "
                                    <option value='{$i}'" . ( $i == $_GET['page'] ? " selected='selected'" : "" ) . ">{$i}</option>";
                            }
                        echo "
                                </select>
                            <input type='hidden' name='ebook' value='{$_GET['ebook']}' />
                    </form>";
                        // show a message for the correct data
                        $info_message = '<p class="info">' . $ebook_existing . '</p>';
             }
    }
   /* ERRORS TO BE PRINTED ON THE SCREEN */
  // if not all required fields have been filled
  if (  isset($_GET['ebook']) && empty($_GET['ebook']) )
   $info_message = '<p class="error">' . $error_missing_field . '</p>';
  // if the ebook doesn't exist
   else if ( isset($_GET['ebook']) && ! empty($_GET['ebook']) && !    is_array($eb->books) )
    $info_message = '<p class="error">' . $ebook_unexisting . '</p>';

   // Show both a confirm message and an error message
   if ( isset( $info_message) && strlen($info_message) ) 
     echo $info_message;        
?>

这是我的网站(意大利语),使用如上所述的API。如果你想看一看:

谢谢。

这不是一个bug,而是一个特性。

可能是出于安全原因,以防止(D)DOS攻击和/或可能是出于许可原因,以阻止大规模下载。

但如果你感到幸运:下载URL 的书

http://filepi.com/i/qqkNNW2

可以在上实际下载(输入captcha后)

http://cdn2.filepi.com/g/qqkNNW2/1446376978/4a79bb1807795fdec1313e97bfd43d1b

其遵循以下模式:

http://cdn2.filepi.com/[g instead of i]/[book id]/[current timestamp]/[md5 hash]

如果哈希是在简单的东西上生成的,那么这个谜题可能是可以破解的。所以,关于你的逆向工程想法:祝你好运!