From 4f2eb0029716003853a38b07bac2b865fa4d89ce Mon Sep 17 00:00:00 2001 From: Tobias Hopp Date: Thu, 9 Jul 2020 20:13:27 +0200 Subject: [PATCH] Updating downloader function Took 40 minutes --- Downloader.php | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/Downloader.php b/Downloader.php index 40b28de..2fc9563 100644 --- a/Downloader.php +++ b/Downloader.php @@ -1,13 +1,54 @@ 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 * * @return bool * @throws Exception */ - public function requestSong( int $a_id ) + public function requestSong( int $a_id ): ?bool { if( ( $out = $this->downloadFile( $a_id ) ) === false ) {