diff --git a/README.md b/README.md index 46b722a..26de174 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# SSLScrobbler v0.24 +# SSLScrobbler v0.25 [![Testing sslscrobbler](https://github.com/ben-xo/sslscrobbler/actions/workflows/testing.yml/badge.svg)](https://github.com/ben-xo/sslscrobbler/actions/workflows/testing.yml) diff --git a/SSL/CLIPlugin.php b/SSL/CLIPlugin.php index cd2c766..ce9d9e8 100644 --- a/SSL/CLIPlugin.php +++ b/SSL/CLIPlugin.php @@ -52,4 +52,12 @@ public function parseOption($arg, array &$argv); * @param SSLPluggable $sslpluggable */ public function addPluginsTo(SSLPluggable $sslpluggable); + + /** + * Interactive arg setting. Modified $argv in place. + * + * @param array $argv + */ + public function addPrompts(array &$argv); + } \ No newline at end of file diff --git a/SSL/Factories/OsascriptPromptFactory.php b/SSL/Factories/OsascriptPromptFactory.php new file mode 100644 index 0000000..98dac24 --- /dev/null +++ b/SSL/Factories/OsascriptPromptFactory.php @@ -0,0 +1,36 @@ +addPrompts($argv); + continue; + } + + if($arg == '--prompt-osascript') + { + Inject::map('PromptFactory', new OsascriptPromptFactory()); + $this->addPrompts($argv); + continue; + } + if($arg == '--debug-help') { $this->help = true; @@ -578,4 +591,13 @@ protected function getMostRecentFile($from_dir, $type) if($fp) return $fp; throw new RuntimeException("No $type file found in $from_dir"); } + + protected function addPrompts(array &$argv) + { + foreach($this->cli_plugins as $plugin) + { + /* @var $plugin CLIPlugin */ + $plugin->addPrompts($argv); + } + } } diff --git a/SSL/Plugins/DB/CLIDBPlugin.php b/SSL/Plugins/DB/CLIDBPlugin.php index 7aab8e0..964de16 100644 --- a/SSL/Plugins/DB/CLIDBPlugin.php +++ b/SSL/Plugins/DB/CLIDBPlugin.php @@ -69,7 +69,12 @@ public function parseOption($arg, array &$argv) return false; } - + + public function addPrompts(array &$argv) + { + // not worth it + } + public function addPluginsTo(SSLPluggable $sslpluggable) { L::level(L::DEBUG) && diff --git a/SSL/Plugins/IrcCat/CLIIrcCatPlugin.php b/SSL/Plugins/IrcCat/CLIIrcCatPlugin.php index e158919..4d9886e 100644 --- a/SSL/Plugins/IrcCat/CLIIrcCatPlugin.php +++ b/SSL/Plugins/IrcCat/CLIIrcCatPlugin.php @@ -77,7 +77,12 @@ public function parseOption($arg, array &$argv) return false; } - + + public function addPrompts(array &$argv) + { + // not worth it + } + public function addPluginsTo(SSLPluggable $sslpluggable) { L::level(L::DEBUG) && diff --git a/SSL/Plugins/JsonServer/CLIJsonServerPlugin.php b/SSL/Plugins/JsonServer/CLIJsonServerPlugin.php index fbfe184..63f0418 100644 --- a/SSL/Plugins/JsonServer/CLIJsonServerPlugin.php +++ b/SSL/Plugins/JsonServer/CLIJsonServerPlugin.php @@ -63,10 +63,17 @@ public function parseOption($arg, array &$argv) $this->plugins[] = $this->newJsonServerPlugin($this->config, $port); return true; } - return false; } - + + public function addPrompts(array &$argv) + { + $port = 8080; + echo "Json Server: now playing info will be available at http://localhost:$port/nowplaying.json\n"; + $argv[] = '-J'; + $argv[] = $port; + } + public function addPluginsTo(SSLPluggable $sslpluggable) { L::level(L::DEBUG) && diff --git a/SSL/Plugins/Last.fm/CLILastfmPlugin.php b/SSL/Plugins/Last.fm/CLILastfmPlugin.php index e7f6fce..a7d3da7 100644 --- a/SSL/Plugins/Last.fm/CLILastfmPlugin.php +++ b/SSL/Plugins/Last.fm/CLILastfmPlugin.php @@ -66,7 +66,42 @@ public function parseOption($arg, array &$argv) return false; } - + + public function addPrompts(array &$argv) + { + $ui = new UI(); + $lastfm_session_files = glob('lastfm-*.txt'); + if($lastfm_session_files) + { + $lastfm_session_file = $lastfm_session_files[0]; + preg_match('/lastfm-([^.]+)\.txt/', $lastfm_session_file, $matches); + if(isset($matches[1])) { + $lastfm_name = $matches[1]; + while(true) { + $answer = strtolower($ui->readline("Last.fm: do you want to scrobble to www.last.fm/user/$lastfm_name? [Y/n] ")); + if ($answer == 'y' || $answer == '') { + $argv[] = '-L'; + $argv[] = $lastfm_name; + return; + } elseif($answer == 'n') { + $answer = strtolower($ui->readline("Last.fm: do you want to log out from www.last.fm/user/$lastfm_name? [y/N] ")); + if ($answer == 'y') { + unlink($lastfm_session_file); + } + break; + } + } + } + } + + $lastfm_name = $ui->readline("Last.fm: type your Last.fm user name (empty to skip): "); + if ($lastfm_name) { + $argv[] = '-L'; + $argv[] = $lastfm_name; + return; + } + } + public function addPluginsTo(SSLPluggable $sslpluggable) { L::level(L::DEBUG) && diff --git a/SSL/Plugins/Twitter/CLITwitterPlugin.php b/SSL/Plugins/Twitter/CLITwitterPlugin.php index e56f398..b7497b1 100644 --- a/SSL/Plugins/Twitter/CLITwitterPlugin.php +++ b/SSL/Plugins/Twitter/CLITwitterPlugin.php @@ -75,6 +75,41 @@ public function parseOption($arg, array &$argv) return false; } + + public function addPrompts(array &$argv) + { + $ui = new UI(); + $twitter_session_files = glob('twitter-*.txt'); + if($twitter_session_files) + { + $twitter_session_file = $twitter_session_files[0]; + preg_match('/twitter-([^.]+)\.txt/', $twitter_session_file, $matches); + if(isset($matches[1])) { + $twitter_name = $matches[1]; + while(true) { + $answer = strtolower($ui->readline("Twitter: do you want to tweet to @$twitter_name? [Y/n] ")); + if ($answer == 'y' || $answer == '') { + $argv[] = '-T'; + $argv[] = $twitter_name; + return; + } elseif($answer == 'n') { + $answer = strtolower($ui->readline("Twitter: do you want to log out from @$twitter_name? [y/N] ")); + if ($answer == 'y') { + unlink($twitter_session_file); + } + break; + } + } + } + } + + $twitter_name = $ui->readline("Twitter: type your Twitter name (empty to skip): @"); + if ($twitter_name) { + $argv[] = '-T'; + $argv[] = $twitter_name; + return; + } + } public function addPluginsTo(SSLPluggable $sslpluggable) { diff --git a/SSL/Prompts/OsascriptPrompt.php b/SSL/Prompts/OsascriptPrompt.php new file mode 100644 index 0000000..1e62b78 --- /dev/null +++ b/SSL/Prompts/OsascriptPrompt.php @@ -0,0 +1,42 @@ +newPrompt()->readline($prompt_text); } } \ No newline at end of file diff --git a/config.php-default b/config.php-default index 3c7d7a9..bf1b155 100644 --- a/config.php-default +++ b/config.php-default @@ -54,7 +54,7 @@ $curlConfig = array( ); $plugins = array( - new GrowlPlugin($growlConfig), + // new GrowlPlugin($growlConfig), new NowPlayingLoggerPlugin($nowplayingloggerConfig), // uncomment the Popup Notifier if you want Popup Notifications - but don't use diff --git a/macOS/build.sh b/macOS/build.sh new file mode 100755 index 0000000..0a6c6dc --- /dev/null +++ b/macOS/build.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +set -e + +if [[ `which platypus` == "" ]]; then + echo "Please install platypus through Mac Homebrew" +fi + +VERSION=$(head -n 1 ../README.md | cut -d' ' -f3) + +platypus -i '../vinyl.icns' \ + -a 'SSL Scrobbler' \ + -o 'Text Window' \ + -p '/usr/bin/php' \ + -V $VERSION \ + -I am.xo.SSLScrobbler \ + -f '../SSL' -f '../config.php-default' -f '../External' -f '../historyreader.php' -f '../README.md' -f '../LICENSE' \ + -C '--prompt-osascript|--immediate' \ + '../historyreader.php' $@