public function getChannel($channel) { $channel = TwitchStream::where('display_name', $channel)->first(); if (!$channel) { return Redirect::action('TwitchController@getStreams'); } $modpack = $channel->modpack; if (!$modpack) { $modpack_name = 'Unknown'; } else { $modpack_name = $modpack->name; } $broadcaster_language = strtoupper($channel->broadcaster_language); $title = $channel->display_name . ' Streaming ' . $modpack_name . ' - ' . $this->site_name; $meta_description = 'Watch ' . $channel->display_name . ' play your favorite Modpack.'; return View::make('twitch.channel', ['title' => $title, 'channel' => $channel, 'modpack_name' => $modpack_name, 'broadcaster_language' => $broadcaster_language, 'meta_description' => $meta_description]); }
public function getStream($id) { $stream = TwitchStream::find($id); if (!$stream) { return json_encode(['error' => 'No stream with that ID is currently live.']); } $results = ['channel_id' => $stream->channel_id, 'modpack_id' => $stream->modpack_id, 'status' => $stream->status, 'display_name' => $stream->display_name, 'language' => $stream->language, 'preview_image_url' => $stream->preview, 'twitch_url' => $stream->url, 'viewers' => $stream->viewers, 'followers' => $stream->followers, 'created_at' => $stream->created_at, 'updated_at' => $stream->updated_at]; return Response::json($results); }
public function getStream() { $twitch = new TwitchStream(); $online_streams = $twitch->getOnlineStreams(); print_r($online_streams); }
private function updateTwitchStreams() { $known_online_channel_ids = []; $known_channel_ids = []; $online_channel_ids = []; $twitch = new TwitchStream(); $known_streams = $twitch::all(); $online_streams = $twitch->getOnlineStreams(); $language_codes = TwitchStream::getLanguageCodes(); foreach ($online_streams as $online_stream) { $online_channel_ids[] = $online_stream->channel->_id; } foreach ($known_streams as $known_stream) { if ($known_stream->online == 1) { $known_online_channel_ids[] = $known_stream->channel_id; } $known_channel_ids[] = $known_stream->channel_id; } foreach ($known_online_channel_ids as $channel_id) { $database_channel = new TwitchStream(); $stream = $database_channel::where('channel_id', $channel_id)->first(); if (!in_array($channel_id, $online_channel_ids)) { $stream->delete(); } else { $channel = $online_streams[$channel_id]; if (isset($channel->channel->status)) { $stream->status = $channel->channel->status; } if (isset($channel->viewers)) { $stream->viewers = $channel->viewers; } if (isset($channel->channel->followers)) { $stream->followers = $channel->channel->followers; } if (isset($channel->preview->medium)) { $stream->preview = str_replace('http://', 'https://', $channel->preview->medium); } if (isset($channel->channel->url)) { $stream->url = $channel->channel->url; } if (isset($channel->channel->display_name)) { $stream->display_name = $channel->channel->display_name; } if (isset($channel->channel->broadcaster_language)) { if (array_key_exists($channel->channel->broadcaster_language, $language_codes)) { $language_code = $channel->channel->broadcaster_language; $language = $language_codes[$language_code]; $stream->language = $language; } else { $stream->language = $channel->channel->broadcaster_language; } } $stream->online = 1; $stream->save(); } } foreach ($online_streams as $online_stream) { if (!in_array($online_stream->channel->_id, $known_channel_ids)) { $database_channel = new TwitchStream(); if (isset($online_stream->channel->_id)) { $database_channel->channel_id = $online_stream->channel->_id; } if (isset($online_stream->channel->display_name)) { $database_channel->display_name = $online_stream->channel->display_name; } if (isset($online_stream->channel->url)) { $database_channel->url = $online_stream->channel->url; } if (isset($online_stream->channel->status)) { $database_channel->status = $online_stream->channel->status; } if (isset($online_stream->viewers)) { $database_channel->viewers = $online_stream->viewers; } if (isset($online_stream->channel->followers)) { $database_channel->followers = $online_stream->channel->followers; } if (isset($online_stream->preview->medium)) { $database_channel->preview = str_replace('http://', 'https://', $online_stream->preview->medium); } if (isset($online_stream->channel->broadcaster_language)) { if (array_key_exists($online_stream->channel->broadcaster_language, $language_codes)) { $language_code = $online_stream->channel->broadcaster_language; $language = $language_codes[$language_code]; $database_channel->language = $language; } else { $database_channel->language = $online_stream->channel->broadcaster_language; } } $database_channel->online = 1; $database_channel->save(); } } }
<?php /* Plugin Name: Twitch live Description: Twitch stream - plugin to display broadcasts Hearthstone. Version: 1.0 Author: Dmitry G. Author URI: http://hearthzone.ru/ Plugin URI: http://hearthzone.ru/streams/ */ require_once 'application.php'; require_once 'frontend.php'; add_shortcode('getstreams', array($twitch_frontend, 'get_streams')); add_action('admin_menu', array($twitch_stream, 'add_admin_menu')); $twitch_stream = new TwitchStream(); $twitch_frontend = new TwitchFrontend(); $last_tick_time = get_option("ts-last-update"); if ($last_tick_time < time() - 30) { $twitch_stream->get_information(); update_option("ts-last-update", time()); }
/** * Print streams */ function get_streams() { global $wpdb; $streamers = $wpdb->get_results('SELECT * FROM wp_streams'); require_once 'application.php'; $twitch_stream = new TwitchStream(); $checkpage = $twitch_stream->is_page(); if ($checkpage !== false) { $this->get_checked_online($streamers); $this->get_other_online($streamers); } }