Updating downloader function
Took 40 minutes
This commit is contained in:
parent
03e38bf9bb
commit
4f2eb00297
@ -1,13 +1,54 @@
|
|||||||
<?php
|
<?php
|
||||||
class Downloader
|
class Downloader
|
||||||
{
|
{
|
||||||
|
private static $loggedIn = false;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
if( !self::$loggedIn )
|
||||||
|
{
|
||||||
|
$this->login();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function login( )
|
||||||
|
{
|
||||||
|
$ch = curl_init();
|
||||||
|
|
||||||
|
curl_setopt( $ch, CURLOPT_URL, "http://usdb.animux.de/index.php?&link=home" );
|
||||||
|
curl_setopt( $ch, CURLOPT_POST, 1 );
|
||||||
|
curl_setopt( $ch, CURLOPT_COOKIEFILE, DOWNLOAD_PATH . '/cookies.txt' );
|
||||||
|
curl_setopt( $ch, CURLOPT_COOKIEJAR, DOWNLOAD_PATH . '/cookies.txt' );
|
||||||
|
// In real life you should use something like:
|
||||||
|
curl_setopt( $ch, CURLOPT_POSTFIELDS,
|
||||||
|
http_build_query(
|
||||||
|
array(
|
||||||
|
'user' => 'trump@whitehouse.gov',
|
||||||
|
'userpass3' => 'C7AFvca6Ri6VhZL'
|
||||||
|
) ) );
|
||||||
|
|
||||||
|
// Receive server response ...
|
||||||
|
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
||||||
|
|
||||||
|
$out = curl_exec( $ch );
|
||||||
|
|
||||||
|
if( strpos( $out, 'Datensatz nicht gefunden' ) !== false )
|
||||||
|
{
|
||||||
|
echo "Not found - Skip\n";
|
||||||
|
curl_close( $ch );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
curl_close( $ch );
|
||||||
|
echo "OK\n";
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $a_id
|
* @param int $a_id
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function requestSong( int $a_id )
|
public function requestSong( int $a_id ): ?bool
|
||||||
{
|
{
|
||||||
if( ( $out = $this->downloadFile( $a_id ) ) === false )
|
if( ( $out = $this->downloadFile( $a_id ) ) === false )
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user