Bugfix when artist was found direct

Bugfix when son was found direct
Bugfix when user entered a search

Took 1 hour 47 minutes
This commit is contained in:
Tobias Hopp 2020-07-12 18:25:18 +02:00
parent 4f2eb00297
commit 0312c57ace
4 changed files with 28 additions and 15 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/sortTest.php

View File

@ -16,19 +16,20 @@ class AudioVideoHandler
return;
}
$dir = realpath( DOWNLOAD_PATH . '/' . $artist );
$dir = str_replace( "\\", '/', $dir );
$searchDir = DOWNLOAD_PATH . '/' . $artist;
$searchDir = str_replace( "\\", '/', $searchDir );
echo "[INFO] Loading results...";
$matches = 0;
$index = 0;
$_indexmatch = 0;
$_found = '';
foreach ( $this->directories as $index => $_dir )
{
if ( ( $lev = levenshtein( $_dir, $dir ) ) < 3 )
if ( ( $lev = levenshtein( $_dir, $searchDir ) ) < 3 )
{
$_found .= "$index | $_dir\n";
$_indexmatch = $index;
$matches++;
}
#echo $lev . "\n";
@ -48,16 +49,23 @@ class AudioVideoHandler
echo $_found;
$index = readline( "Name the index-number: " );
}
else
{
$index = $_indexmatch;
}
if ( isset( $this->directories[$index] ) === false )
{
echo "[ERROR] Index is invalid!\n";
goto indexChoose;
}
$dir = $this->directories[$index];
echo "[INFO] Scanning Artist directory...";
$files = scandir( $dir );
unset( $files[0], $files[1] );
echo "OK\n";
if ( count( $files ) < 1 )
@ -90,7 +98,7 @@ class AudioVideoHandler
$matches = 0;
$artist = basename( $dir );
$_found = '';
$index = 0;
$_indexmatch = 0;
foreach ( $files as $index => $name )
{
$name = str_replace( array( '.txt', '.mp3', '.mp4' ), '', $name );
@ -98,6 +106,7 @@ class AudioVideoHandler
{
$_found .= "$index | $song\n";
$matches++;
$_indexmatch = $index;
}
}
if ( $matches === 0 )
@ -111,6 +120,10 @@ class AudioVideoHandler
echo $_found;
$index = readline( "Name the index-number: " );
}
else
{
$index = $_indexmatch;
}
if ( isset( $files[$index] ) === false )
{

View File

@ -11,8 +11,9 @@ class Downloader
}
}
private function login( )
private function login( ): void
{
echo "[LOGIN] Logging in...";
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, "http://usdb.animux.de/index.php?&link=home" );
@ -30,15 +31,10 @@ class Downloader
// 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 );
self::$loggedIn = true;
echo "OK\n";
}
@ -46,15 +42,17 @@ class Downloader
* @param int $a_id
*
* @return bool
*
* @throws Exception
*/
public function requestSong( int $a_id ): ?bool
public function requestSong( int $a_id ): bool
{
if( ( $out = $this->downloadFile( $a_id ) ) === false )
{
return false;
}
$this->saveFile( $out );
return true;
}
/**
@ -145,7 +143,7 @@ class Downloader
return false;
}
if( ( $file = fopen( DOWNLOAD_PATH . "/$artist/$artist - $title.txt", 'w+' ) ) === false )
if( ( $file = fopen( DOWNLOAD_PATH . "/$artist/$artist - $title.txt", 'wb+' ) ) === false )
{
throw new RuntimeException( "$artist - $title *** Cannot open file handler" );
}

1
start.bat Normal file
View File

@ -0,0 +1 @@
php C:\Users\hoppt\PhpstormProjects\karaoke-management\karaoke-management.php