/
linkbyartist.php
79 lines (69 loc) · 2.32 KB
/
linkbyartist.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
/**
* Analyses a FOF song and gets tracks & difficulties
*/
include dirname( __FILE__ ) . '/lib/autoload.php';
$input = new ezcConsoleInput();
$dryRunOption = $input->registerOption( new ezcConsoleOption( 'd', 'dry-run', ezcConsoleInput::TYPE_NONE, false ) );
$quietOption = $input->registerOption( new ezcConsoleOption( 'q', 'quiet', ezcConsoleInput::TYPE_NONE, false ) );
$helpOption = $input->registerOption( new ezcConsoleOption( 'h', 'help' ) );
$verboseOption = $input->registerOption( new ezcConsoleOption( 'v', 'verbose', ezcConsoleInput::TYPE_NONE, false ) );
$input->argumentDefinition = new ezcConsoleArguments();
$input->argumentDefinition[0] = new ezcConsoleArgument( "artist" );
$input->argumentDefinition[0]->mandatory = true;
$input->argumentDefinition[0]->shorthelp = "The artist to search for";
$output = new ezcConsoleOutput();
$output->formats->info->color = 'blue';
$output->formats->error->color = 'red';
$output->formats->error->style = array( 'bold' );
$output->formats->fatal->color = 'red';
$output->formats->fatal->style = array( 'bold', 'underlined' );
$output->formats->fatal->bgcolor = 'black';
try
{
$input->process();
}
catch ( ezcConsoleArgumentMandatoryViolationException $e )
{
if ( $helpOption->value === true )
{
$output->outputText( $input->getHelpText( "Auto-link by artist name" ) );
exit;
}
else
{
$output->outputLine( "No arguments given", "fatal" );
$output->outputText( $input->getHelpText( "Auto-link by artist name" ) );
exit( 1 );
}
}
catch ( ezcConsoleException $e )
{
die( $e->getMessage() );
}
if ( $input->argumentDefinition["artist"]->value === null)
{
$output->outputLine( "The <artist> argument is mandatory", 'fatal' );
$output->outputText( $input->getHelpText( "Auto-link by artist name" ), 'fatal' );
exit;
}
var_dump( $verboseOption->value );
$it = new FOFSongIterator( '/home/xbmc/fof/songs/Packs' );
$it->addFilter( 'artist', $input->argumentDefinition["artist"]->value );
foreach ( $it as $song )
{
$linkName = $song->name;
if ( file_exists( $linkName ) and ( $verboseOption->value === true ) )
{
$output->outputLine( "$linkName already exists", "info" );
}
else
{
$path = $song->directory->getPathname();
if ( $quietOption !== false)
$output->outputLine( "$linkName => $path" );
if ( $dryRunOption->value !== true )
symlink( $path, $linkName );
}
}
?>