Exemplo n.º 1
0
 /**
  * @param cURL\Event $event
  * @param ChannelContext $context
  */
 public function onRequestComplete(cURL\Event $event, ChannelContext $context)
 {
     $res = $event->response;
     $code = $res->getInfo(CURLINFO_HTTP_CODE);
     $feed = $res->getContent();
     if ($code != 200 || empty($feed)) {
         return;
     }
     $feed = json_decode($feed, true);
     $track =& $feed['track'];
     $replace = ['%artist' => $track['artists'][0]['name'], '%track' => $track['name'], '%duration' => TimeDuration::get((int) $track['length']), '%album' => $track['album'] ? $track['album']['name'] : 'n/d', '%released' => $track['album']['released']];
     $response = strtr('<b><color fg="white" bg="green"> Spotify </color></b>  ' . '<b>%artist - <u>%track</u></b> (%duration), album: <b>%album</b> (%released)', $replace);
     $context->send(Formatter::parse($response));
 }
Exemplo n.º 2
0
 /**
  * @param array $item
  * @param ChannelContext $context
  */
 protected function generateResponse(array $item, ChannelContext $context)
 {
     $duration = new \DateInterval($item['contentDetails']['duration']);
     if (preg_match(self::$anyUrlPattern, $item['snippet']['title'])) {
         $context->getLogger()->notice("Blocked possible YouTube loop.");
         return;
     }
     $replace = array('%title' => $item['snippet']['title'], '%views' => $this->formatBigNumber($item['statistics']['viewCount']), '%duration' => TimeDuration::format($duration), '%likes' => number_format($item['statistics']['likeCount'], 0, '.', ','), '%dislikes' => number_format($item['statistics']['dislikeCount'], 0, '.', ','));
     $response = "01,00You00,04Tube  %title (%duration), %views views," . " 03▲ %likes 04▼ %dislikes";
     $context->send(strtr($response, $replace));
 }