Exemplo n.º 1
0
 /**
  * @Route("/played", name="_played")
  * @Template()
  */
 public function playedAction()
 {
     $data = [];
     $idVideo = $this->getRequest()->request->get('videoid');
     if ($this->getRequest()->isXmlHttpRequest()) {
         $played = new Played();
         $played->setIdVideo($idVideo)->setDatePlayed(new \DateTime());
         $em = $this->getDoctrine()->getManager();
         $playedQuery = new PlayedQuery($em);
         if ($this->getUser()) {
             $played->setUser($this->getUser());
         }
         $playedQuery->persist($played);
         $data['video'] = $this->get('youtubeVideo')->setId($idVideo)->getResult();
         $title = $data['video']->items[0]->snippet->title;
         $result = $this->get('lastFmMusicSearch')->setTrack($title)->getResults();
         $trackMatches = $result->results->trackmatches;
         if (isset($trackMatches->track)) {
             $artistName = $trackMatches->track[0]->artist;
             $artistQuery = new ArtistQuery($this->get('doctrine_mongodb')->getManager());
             $artist = $artistQuery->setName($artistName)->getSingle();
             if (!$artist) {
                 $this->get('ArtistCreator')->setArtistName($artistName)->run();
             }
         }
         $response = new Response(json_encode($data));
         $response->headers->set('Content-Type', 'application/json');
         return $response;
     }
 }
Exemplo n.º 2
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.º 4
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);
         }
     }
 }
Exemplo n.º 5
0
 /**
  * @Route("artist_content/{artistName}", name="_artistDetailContent", requirements={"artistName" = ".*"})
  * @Template()
  */
 public function contentArtistAction($artistName)
 {
     $dm = $this->get('doctrine_mongodb')->getManager();
     $artistQuery = new ArtistQuery($dm);
     $artist = $artistQuery->isProcessed()->setName(urldecode($artistName))->getSingle();
     $data = [];
     $data['artist'] = $artist;
     $data['modal'] = $this->getRequest()->get('modal', false);
     $data['tab'] = 'artist';
     if ($artist instanceof Artist) {
         $similarArtists = $artistQuery->reset()->getSimilarArtists($artist);
         $data['similarArtists'] = $similarArtists;
     }
     if ($this->getUser()) {
         $data['user'] = $this->getUser();
         $data['connected'] = true;
     } else {
         $data['connected'] = false;
     }
     return $data;
 }