/** * @Template() * @Route("/p/{playlist}/s/{song}", name="song", defaults={"playlist" = null, "song" = null}) * @Route("/p/{playlist}", name="playlist", defaults={"playlist" = null}) * @Route("/", name="homepage") * @ParamConverter("playlist", class="AppBundle:Playlist", isOptional="true") * @ParamConverter("song", class="AppBundle:Song", isOptional="true") */ public function indexAction(Request $request, Playlist $playlist = null, Song $song = null) { $songs = []; $videoId = null; $nextVideoId = null; $nextSong = null; $form = $this->createForm("playlist_form", null, ["data" => ["playlist" => $playlist]]); $form->handleRequest($request); if ($form->isSubmitted()) { return $this->redirectToRoute("playlist", ["playlist" => $form->get("playlist")->getData()->id()]); } if (!is_null($playlist)) { /** @var Song[] $songs */ $songs = $this->getDoctrine()->getRepository("AppBundle:Song")->findByPlaylist($playlist); } if (count($songs) > 0) { foreach ($songs as $key => $testSong) { if ($testSong->id() !== $song->id()) { continue; } if (array_key_exists($key + 1, $songs)) { $nextSong = $songs[$key + 1]; $nextVideoId = $nextSong->id(); } else { $nextSong = $songs[0]; $nextVideoId = $nextSong->id(); } break; } } return ["videoId" => $videoId, "nextVideoId" => $nextVideoId, "song" => $song, "nextSong" => $nextSong, "songs" => $songs, "playlist" => $playlist, "playlistForm" => $form->createView()]; }
private function scrap(Song $song) { $arr = []; $crawler = $this->client->request('GET', $song->url()); $arr["title"] = $crawler->filter("title")->text(); $arr["thumbnail_url"] = sprintf('http://img.youtube.com/vi/%s/1.jpg', $song->videoId()); return $arr; }
public function addSong($sender, $keyword, Event $event, EventUser $eventuser) { $temp_song = new Song(); $namecheck = explode(" ", $keyword); $em = $this->getEntityManager(); $temp_song->setSender($sender); $temp_song->setKeyword($keyword); $temp_song->setEvent($event); $temp_song->setEventUser($eventuser); $temp_song->setIsSearchable($this->checkSearchable($keyword)); $temp_song->setSkipped(false); $em->persist($temp_song); if ($namecheck[0] == "#name") { $name = join(" ", array_slice($namecheck, 1)); $eventuser->setNickname($name); } $em->flush(); return $temp_song; }
/** * Add song * * @param \AppBundle\Entity\Song $song * * @return Album */ public function addSong(\AppBundle\Entity\Song $song) { $this->songs[] = $song; $song->setAlbum($this); return $this; }