@@ 22-73 (lines=52) @@ | ||
19 | use Symfony\Component\Console\Input\InputOption; |
|
20 | use Symfony\Component\Console\Output\OutputInterface; |
|
21 | ||
22 | class SearchSpotifyArtistCommand extends Command |
|
23 | { |
|
24 | /** |
|
25 | * @var Service |
|
26 | */ |
|
27 | protected $spotifyService; |
|
28 | ||
29 | protected function configure() |
|
30 | { |
|
31 | $this |
|
32 | ->setName('music-info:search:spotify:artist') |
|
33 | ->setDescription('Search an artist on Spotify') |
|
34 | ->setHelp("This command will search and return an artist using the Spotify API") |
|
35 | ->addOption('save', 'p', InputOption::VALUE_OPTIONAL, false) |
|
36 | ->addArgument('query', InputArgument::REQUIRED, 'Artist name') |
|
37 | ; |
|
38 | } |
|
39 | ||
40 | protected function execute(InputInterface $input, OutputInterface $output) |
|
41 | { |
|
42 | $artist = $input->getArgument('query'); |
|
43 | if(!$artist) { |
|
44 | throw new \InvalidArgumentException('Artist missing'); |
|
45 | } |
|
46 | ||
47 | $result = $this->spotifyService->artist()->getByName($artist); |
|
48 | ||
49 | $table = new Table($output); |
|
50 | $table |
|
51 | ->setHeaders(['ID','Artist']); |
|
52 | ||
53 | if(!$result) { |
|
54 | $output->writeln('No results'); |
|
55 | } else { |
|
56 | /** @var Artist $artist */ |
|
57 | foreach($result as $artist) { |
|
58 | $table |
|
59 | ->addRow([ |
|
60 | $artist->getId(), |
|
61 | $artist->getName() |
|
62 | ]); |
|
63 | } |
|
64 | ||
65 | $table->render(); |
|
66 | } |
|
67 | } |
|
68 | ||
69 | public function setSpotifyService(Service $service) |
|
70 | { |
|
71 | $this->spotifyService = $service; |
|
72 | } |
|
73 | } |
@@ 22-74 (lines=53) @@ | ||
19 | use Symfony\Component\Console\Input\InputOption; |
|
20 | use Symfony\Component\Console\Output\OutputInterface; |
|
21 | ||
22 | class SearchSpotifyTrackCommand extends Command |
|
23 | { |
|
24 | /** |
|
25 | * @var Service |
|
26 | */ |
|
27 | protected $spotifyService; |
|
28 | ||
29 | protected function configure() |
|
30 | { |
|
31 | $this |
|
32 | ->setName('music-info:search:spotify:track') |
|
33 | ->setDescription('Search a track on Spotify') |
|
34 | ->setHelp("This command will search and return a track using the Spotify API") |
|
35 | ->addOption('save', 'p', InputOption::VALUE_OPTIONAL, false) |
|
36 | ->addArgument('query', InputArgument::REQUIRED, 'Track title') |
|
37 | ; |
|
38 | } |
|
39 | ||
40 | protected function execute(InputInterface $input, OutputInterface $output) |
|
41 | { |
|
42 | $trackTitle = $input->getArgument('query'); |
|
43 | if(!$trackTitle) { |
|
44 | throw new \InvalidArgumentException('Track title missing'); |
|
45 | } |
|
46 | ||
47 | $result = $this->spotifyService->title()->getByName($trackTitle); |
|
48 | ||
49 | $table = new Table($output); |
|
50 | $table |
|
51 | ->setHeaders(['ID','Artist', 'Name']); |
|
52 | ||
53 | if(!$result) { |
|
54 | $output->writeln('No results'); |
|
55 | } else { |
|
56 | /** @var Track $track */ |
|
57 | foreach($result as $track) { |
|
58 | $table |
|
59 | ->addRow([ |
|
60 | $track->getId(), |
|
61 | $track->getTrackArtists(), |
|
62 | $track->getName() |
|
63 | ]); |
|
64 | } |
|
65 | ||
66 | $table->render(); |
|
67 | } |
|
68 | } |
|
69 | ||
70 | public function setSpotifyService(Service $service) |
|
71 | { |
|
72 | $this->spotifyService = $service; |
|
73 | } |
|
74 | } |