Exemplo n.º 1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $artistQuery = new ArtistQuery($this->getContainer()->get('doctrine_mongodb')->getManager());
     $youtubeSearch = $this->getContainer()->get('youtubeSearch');
     $artists = $artistQuery->notProcessed()->setLimit(5)->getList();
     foreach ($artists as $artist) {
         if ($artist->getName() != '[unknown]') {
             if (count($artist->getAlbums())) {
                 foreach ($artist->getAlbums() as $album) {
                     foreach ($album->getTracks() as $track) {
                         $result = $youtubeSearch->setQuery($artist->getName() . ' - ' . $track->getName())->getResults();
                         if (isset($result->items)) {
                             foreach ($result->items as $item) {
                                 if (strpos(strtolower($item->snippet->title), strtolower($track->getName()))) {
                                     $output->writeln($item->id->videoId . ' ' . $artist->getName() . ' ' . $track->getName());
                                     $track->setYoutubeId($item->id->videoId);
                                     if ($this->hasNoInvalidateWords($item->snippet->title, $track->getName())) {
                                         break;
                                     }
                                 }
                             }
                         }
                     }
                 }
             } else {
                 $artist->setDisabled();
             }
         }
         $artist->setProcessed();
         $artistQuery->persist($artist);
     }
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $artistQuery = new ArtistQuery($this->getContainer()->get('doctrine_mongodb')->getManager());
     /** @var Album $lastFmArtistAlbumService */
     $lastFmArtistAlbumService = $this->getContainer()->get('lastFmArtistAlbum');
     /** @var Filesystem $fileSystem */
     $fileSystem = $this->getContainer()->get('knp_gaufrette.filesystem_map')->get('local');
     $artists = $artistQuery->addOrderBy('name')->setSearchLikeImageHttp()->isProcessed()->isNotDisabled()->getList();
     foreach ($artists as $artist) {
         if ($artist->getName() != '[unknown]') {
             $output->writeln(sprintf('Start process for artist: %s', $artist->getName()));
             foreach ($artist->getAlbums() as $album) {
                 if ($fileSystem->has($album->getImage()) || $album->getImage() === '') {
                     continue;
                 }
                 $output->writeln(sprintf('Image doesn\'t exist for album: %s', $album->getName()));
                 $albumResult = $lastFmArtistAlbumService->setArtist($artist->getName())->getResults();
                 if (!isset($albumResult->error) && isset($albumResult->topalbums->album)) {
                     if (!is_array($albumResult->topalbums->album)) {
                         $albums = array($albumResult->topalbums->album);
                     } else {
                         $albums = $albumResult->topalbums->album;
                     }
                     $found = false;
                     foreach ($albums as $albumResult) {
                         if ($album->getName() == $albumResult->name) {
                             if (is_array($albumResult->image)) {
                                 $image = $albumResult->image[count($albumResult->image) - 1];
                                 $var = '#text';
                                 if ('' !== $image->{$var}) {
                                     $fileName = substr($image->{$var}, strrpos($image->{$var}, '/'));
                                     $fileSystem->write($fileName, file_get_contents($image->{$var}), true);
                                     $album->setImage($fileName);
                                     $found = true;
                                     break;
                                 } else {
                                     $album->setImage('');
                                 }
                             }
                         }
                     }
                     if (!$found) {
                         $output->writeln(sprintf('Album not found: %s', $album->getName()));
                         $album->setImage('');
                     }
                 } else {
                     $album->setImage('');
                     $output->writeln(sprintf('Fail to get information for album: %s', $album->getName()));
                 }
             }
             $output->writeln(sprintf('End process for artist: %s', $artist->getName()));
             $artistQuery->persist($artist);
         }
     }
 }
Exemplo n.º 3
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $artistQuery = new ArtistQuery($this->getContainer()->get('doctrine_mongodb')->getManager());
     $artists = $artistQuery->getList();
     foreach ($artists as $artist) {
         if (count($artist->getAlbums()) == 0) {
             $artist->setDisabled();
             $artistQuery->persist($artist);
         }
     }
 }