Skip to content

Commit

Permalink
#1 Make categories configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
willemstuursma committed Mar 5, 2021
1 parent 0b4b9d9 commit 19928ce
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 9 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ Download the `castblock-php.phar` file from the Releases page.
Run `php castblock-php.phar` on a device that is in the same network as your Chromecast device or
devices.

You can adjust the debugging verbosity by adding `-v`, `-vv` or `-vvv`.

For example, you can install it as a service with systemd or run it in a screen.

### Options

* `--category`: Select which category to skip. Repeat multiple times to skip multiple categories. Default: `--category sponsor --category interaction`.

You can adjust the debugging verbosity by adding `-v`, `-vv` or `-vvv`.

## Contributions

Contributions via Issues or Pull Requests are welcomed.
42 changes: 35 additions & 7 deletions src/Commands/RunCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Logger\ConsoleLogger;
use Symfony\Component\Console\Output\OutputInterface;
use WillemStuursma\CastBlock\ChromeCastConnector;
Expand Down Expand Up @@ -39,23 +40,50 @@ class RunCommand extends Command
*/
private $sponsorBlock;

public function __construct(?string $name = null)
protected function initialize(InputInterface $input, OutputInterface $output)
{
parent::__construct($name);

$this->connector = new ChromeCastConnector();
$this->sponsorBlock = new SponsorBlockApi();
}

protected function configure()
{
$this
->setDescription("Run Castblock PHP")
->setHelp("Runs Castblock PHP. Any sponsorship segments on Chromcasts will be skipped automatically.")
->addOption(
"category",
"c",
InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED,
"Which categories do you want to automatically skip?",
[SponsorblockCategory::INTERACTION()->getValue(), SponsorblockCategory::SPONSOR()->getValue()]
)
;
}

/**
* @return SponsorblockCategory[]
*/
private function getCategories(InputInterface $input): array
{
$selectedCategories = $input->getOption("category");

$categories = [];

foreach ($selectedCategories as $selectedCategory) {
$categories[] = SponsorblockCategory::from($selectedCategory);
}

return $categories;

}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$logger = new ConsoleLogger($output);
$logger->debug("Starting CastBlock PHP...");

$categories = [
SponsorblockCategory::SPONSOR(),
SponsorblockCategory::INTERACTION(),
];
$categories = $this->getCategories($input);

while (true) {

Expand Down

0 comments on commit 19928ce

Please sign in to comment.