/** * Muestra los videos del canal seleccionado * @param $id * @return \Illuminate\View\View */ public function index($id) { $youtube = new \Madcoda\Youtube(array('key' => 'AIzaSyC4DkOm379a_5p77mjjLlEsBubtPXYO584')); $video = ChannelVideos::where('channel_id', '=', $id)->Where('viewed', '=', 0)->first(); if ($video != null) { $info = $youtube->getVideoInfo($video->url); $time = $this->timeCalculate($info->contentDetails->duration); $this->viewedUpdate($video->id); } return view("youparty.show", compact('video', 'time')); }
/** * Muestra los resultados con el botón para agregar los videos al canal. * @return \Illuminate\View\View */ public function create() { $word = Input::get('search'); $channel_id = Input::get('channel_id'); $youtube = new \Madcoda\Youtube(array('key' => 'AIzaSyC4DkOm379a_5p77mjjLlEsBubtPXYO584')); // Set Default Parameters $params = array('q' => $word, 'type' => 'video', 'part' => 'id, snippet', 'maxResults' => 20); // Make Intial Call. With second argument to reveal page info such as page tokens. $search = $youtube->searchAdvanced($params, true); // check if we have a pageToken if (isset($search['info']['nextPageToken'])) { $params['pageToken'] = $search['info']['nextPageToken']; } // Make Another Call and Repeat $videos = $youtube->searchAdvanced($params, true); return view('youparty.search', compact('videos', 'channel_id')); }
/* |-------------------------------------------------------------------------- | Application Routes |-------------------------------------------------------------------------- | | Here is where you can register all of the routes for an application. | It's a breeze. Simply tell Laravel the URIs it should respond to | and give it the Closure to execute when that URI is requested. | */ Route::get('/', function () { return View::make('hello'); }); Route::any('/inbound/slack/notshinyunicorn/general', function () { $x = Input::all(); $strText = str_replace("<http://", "", $x["text"]); $strText = str_replace("<https://", "", $strText); if (substr($strText, 0, 23) == "open.spotify.com/track/") { $strText = str_replace("open.spotify.com/track/", "", $strText); $strText = str_replace(">", "", $strText); $strTest = file_get_contents("https://api.spotify.com/v1/tracks/" . $strText); $json = $objJSON = json_decode($strTest); $youtube = new \Madcoda\Youtube(array('key' => $_ENV["YOUTUBE_KEY"])); $videoList = $youtube->searchVideos($json->artists[0]->name . " " . $json->name); if (isset($videoList[0]->id->videoId)) { Slack::to('#' . $x["channel_name"])->send("https://www.youtube.com/watch?v=" . $videoList[0]->id->videoId); } else { Slack::to('#' . $x["channel_name"])->send("No match found for Spotify track."); } } });
public function search() { $word = (string) Input::get('artist'); if (isset($word)) { $youtube = new \Madcoda\Youtube(array('key' => 'AIzaSyDKLmH2_s3qJUGBWATDh880Hahw_3rh_UE')); $allVideos = $youtube->searchVideos($word); $videoId = $allVideos[0]->id->videoId; if (!empty($videoId)) { $videos = $youtube->getVideoInfo($videoId); return response()->json($videos); } else { response()->json(['status' => 'no video']); } } else { response()->json(['status' => 'no artist']); } }
/** * Display a listing of the resource. * * @return Response */ public function index() { $youtube = new \Madcoda\Youtube(array('key' => 'AIzaSyC4DkOm379a_5p77mjjLlEsBubtPXYO584')); $videoId = $youtube->parseVIdFromURL('https://www.youtube.com/watch?v=OsjdYQJc748&list=PLPKuYmN_zBQnhH3CNtt3ESwlDP7gWb7WU&index=1'); dd($youtube->getVideoInfo($videoId)); }
<?php require_once __DIR__ . '/../bootstrap.php'; $client = new Madcoda\Youtube(['key' => $config->youtube->key]); $mostRecentVideoDateTime = $db->getRead()->fetchValue("SELECT `datetime` FROM `jpemeric_stream`.`youtube` ORDER BY `datetime` DESC LIMIT 1"); $mostRecentVideoDateTime = new DateTime($mostRecentVideoDateTime); try { $playlist = $client->getPlaylistItemsByPlaylistId($config->youtube->favorites_playlist, 10); } catch (Exception $e) { $logger->addError($e->getMessage()); exit; } foreach ($playlist as $playlistItem) { $datetime = new DateTime($playlistItem->snippet->publishedAt); if ($datetime <= $mostRecentVideoDateTime) { break; } $uniqueVideoCheck = $db->getRead()->fetchValue("SELECT 1 FROM `jpemeric_stream`.`youtube` WHERE `video_id` = :video_id LIMIT 1", ['video_id' => $playlistItem->contentDetails->videoId]); if ($uniqueVideoCheck !== false) { continue; } $datetime->setTimezone(new DateTimeZone('America/Phoenix')); $db->getWrite()->perform("INSERT INTO `jpemeric_stream`.`youtube` (`video_id`, `datetime`, `metadata`) " . "VALUES (:video_id, :datetime, :metadata)", ['video_id' => $playlistItem->contentDetails->videoId, 'datetime' => $datetime->format('Y-m-d H:i:s'), 'metadata' => json_encode($playlistItem)]); }