Updating downloader function
Took 29 minutes
This commit is contained in:
parent
2ff2ee5b07
commit
03e38bf9bb
@ -9,34 +9,49 @@ class AudioVideoHandler
|
|||||||
echo "[INFO] Fetching directories...";
|
echo "[INFO] Fetching directories...";
|
||||||
$this->directories = glob( DOWNLOAD_PATH . '/*', GLOB_ONLYDIR );
|
$this->directories = glob( DOWNLOAD_PATH . '/*', GLOB_ONLYDIR );
|
||||||
echo "OK\n";
|
echo "OK\n";
|
||||||
|
artistChoose:
|
||||||
|
$artist = readline( "Artist: " );
|
||||||
|
if( $artist === 'exit' )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$dir = realpath( DOWNLOAD_PATH . '/' . readline( "Artist: " ) );
|
$dir = realpath( DOWNLOAD_PATH . '/' . $artist );
|
||||||
$dir = str_replace( "\\", '/', $dir );
|
$dir = str_replace( "\\", '/', $dir );
|
||||||
echo "[INFO] Loading results...\n";
|
echo "[INFO] Loading results...";
|
||||||
echo $dir;
|
|
||||||
|
|
||||||
$matches = 0;
|
$matches = 0;
|
||||||
|
$index = 0;
|
||||||
|
$_found = '';
|
||||||
foreach ( $this->directories as $index => $_dir )
|
foreach ( $this->directories as $index => $_dir )
|
||||||
{
|
{
|
||||||
|
|
||||||
if ( ( $lev = levenshtein( $_dir, $dir ) ) < 3 )
|
if ( ( $lev = levenshtein( $_dir, $dir ) ) < 3 )
|
||||||
{
|
{
|
||||||
echo "[MATCH#$lev] Did you mean: $_dir? [$index]\n";
|
$_found .= "$index | $_dir\n";
|
||||||
$matches++;
|
$matches++;
|
||||||
}
|
}
|
||||||
#echo $lev . "\n";
|
#echo $lev . "\n";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
echo "OK\n";
|
||||||
if ( $matches === 0 )
|
if ( $matches === 0 )
|
||||||
{
|
{
|
||||||
echo "[INFO] No matches found!\n";
|
echo "[INFO] No matches found!\n";
|
||||||
return;
|
goto artistChoose;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
indexChoose:
|
||||||
|
if( $matches > 1 )
|
||||||
|
{
|
||||||
|
echo "[FOUND] $matches are found!\nIndex | Artist\n";
|
||||||
|
echo $_found;
|
||||||
$index = readline( "Name the index-number: " );
|
$index = readline( "Name the index-number: " );
|
||||||
|
}
|
||||||
if ( isset( $this->directories[$index] ) === false )
|
if ( isset( $this->directories[$index] ) === false )
|
||||||
{
|
{
|
||||||
echo "[ERROR] Index is invalid!\n";
|
echo "[ERROR] Index is invalid!\n";
|
||||||
return;
|
goto indexChoose;
|
||||||
}
|
}
|
||||||
$dir = $this->directories[$index];
|
$dir = $this->directories[$index];
|
||||||
|
|
||||||
@ -48,37 +63,61 @@ class AudioVideoHandler
|
|||||||
if ( count( $files ) < 1 )
|
if ( count( $files ) < 1 )
|
||||||
{
|
{
|
||||||
echo "[WARNING] Directory $dir is empty!\n";
|
echo "[WARNING] Directory $dir is empty!\n";
|
||||||
return;
|
goto artistChoose;
|
||||||
}
|
}
|
||||||
$_titleOrFull = readline( "Do you want to download all songs or just an explicit title?[A/t]: " );
|
echo "[INFO] " . count($files) . " songs found.";
|
||||||
if ( stripos( $_titleOrFull, 't' ) !== false )
|
$_titleOrFull = readline( "Do you want to download all songs or just an specific title?[A/t]: " );
|
||||||
|
if ( stripos( $_titleOrFull, 't' ) !== false || stripos( $_titleOrFull, 'title' ) !== false )
|
||||||
{
|
{
|
||||||
echo "\n";
|
echo "\n";
|
||||||
// Only one
|
// Only one
|
||||||
$song = readline( "Enter the Song name: " );
|
songChoose:
|
||||||
|
$song = readline( "Enter the Song name('list' to list): " );
|
||||||
|
if( $song === 'exit' )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if( $song === 'list' )
|
||||||
|
{
|
||||||
|
echo "Listing all Songs...\n";
|
||||||
|
foreach( $files as $_song )
|
||||||
|
{
|
||||||
|
echo "$_song\n";
|
||||||
|
}
|
||||||
|
goto songChoose;
|
||||||
|
}
|
||||||
echo "[INFO] Searching...\n";
|
echo "[INFO] Searching...\n";
|
||||||
$matches = 0;
|
$matches = 0;
|
||||||
$artist = basename( $dir );
|
$artist = basename( $dir );
|
||||||
|
$_found = '';
|
||||||
|
$index = 0;
|
||||||
foreach ( $files as $index => $name )
|
foreach ( $files as $index => $name )
|
||||||
{
|
{
|
||||||
$name = str_replace( array( '.txt', '.mp3', '.mp4' ), '', $name );
|
$name = str_replace( array( '.txt', '.mp3', '.mp4' ), '', $name );
|
||||||
if ( ( $lev = levenshtein( $name, $artist . ' - ' . $song ) ) < 4 )
|
if ( ( $lev = levenshtein( $name, $artist . ' - ' . $song ) ) < 4 )
|
||||||
{
|
{
|
||||||
echo "[MATCH#$lev] Did you mean: $name? [$index]\n";
|
$_found .= "$index | $song\n";
|
||||||
$matches++;
|
$matches++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( $matches === 0 )
|
if ( $matches === 0 )
|
||||||
{
|
{
|
||||||
echo "[WARNING] No matches found!\n";
|
echo "[WARNING] No matches found!\n";
|
||||||
return;
|
goto songChoose;
|
||||||
}
|
}
|
||||||
|
if( $matches > 1 )
|
||||||
|
{
|
||||||
|
echo "[FOUND] $matches are found!\nIndex | Song\n";
|
||||||
|
echo $_found;
|
||||||
$index = readline( "Name the index-number: " );
|
$index = readline( "Name the index-number: " );
|
||||||
|
}
|
||||||
|
|
||||||
if ( isset( $files[$index] ) === false )
|
if ( isset( $files[$index] ) === false )
|
||||||
{
|
{
|
||||||
echo "[ERROR] Index is invalid!\n";
|
echo "[ERROR] Index is invalid!\n";
|
||||||
return;
|
goto songChoose;
|
||||||
}
|
}
|
||||||
|
|
||||||
$files[$index] = str_replace( array( '.txt', '.mp3', '.mp4' ), '', $files[$index] );
|
$files[$index] = str_replace( array( '.txt', '.mp3', '.mp4' ), '', $files[$index] );
|
||||||
$this->download( $files[$index] );
|
$this->download( $files[$index] );
|
||||||
|
|
||||||
|
@ -9,4 +9,4 @@ error_reporting(0);
|
|||||||
require_once 'AudioVideoHandler.php';
|
require_once 'AudioVideoHandler.php';
|
||||||
require_once 'Downloader.php';
|
require_once 'Downloader.php';
|
||||||
|
|
||||||
define( 'CURL_PHPSESSID', '' );
|
define( 'CURL_PHPSESSID', 'hi' );
|
Loading…
x
Reference in New Issue
Block a user