private function matchTwitchStreamsToModpacks()
 {
     $modpacks_array = [];
     $streams_array = [];
     $modpacks = Modpack::all();
     $modpack_aliases = ModpackAlias::all();
     $streams = TwitchStream::where('online', 1)->get();
     foreach ($modpacks as $modpack) {
         $modpacks_array[] = ['id' => $modpack->id, 'name' => $modpack->name];
     }
     foreach ($modpack_aliases as $alias) {
         $modpacks_array[] = ['id' => $alias->modpack_id, 'name' => $alias->alias];
     }
     foreach ($streams as $stream) {
         $id = $stream->channel_id;
         $streams_array[$id] = $stream->status;
     }
     foreach ($streams_array as $s_id => $stream) {
         $stream_database = TwitchStream::find($s_id);
         foreach ($modpacks_array as $mod) {
             preg_match('/' . $mod['name'] . '/i', $stream, $match);
             if ($match) {
                 $stream_database->modpack_id = $mod['id'];
                 $stream_database->save();
                 $this->info('Matched \'' . $stream . '\' to ' . $mod['name']);
                 break;
             } else {
                 $stream_database->delete();
             }
         }
     }
 }
Exemplo n.º 2
0
 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]);
 }
Exemplo n.º 3
0
 public function getStreams($modpack = 'all')
 {
     $streams = [];
     $limit = 100;
     $offset = 0;
     $input = Input::only('limit', 'offset');
     if ($input['limit']) {
         $limit = $input['limit'];
     }
     if ($input['offset']) {
         $offset = $input['offset'];
     }
     if ($modpack == 'all') {
         $raw_streams = TwitchStream::skip($offset)->take($limit)->get();
         $stream_count = TwitchStream::select('id')->count();
     } else {
         $raw_streams = TwitchStream::where('modpack_id', $modpack)->skip($offset)->take($limit)->get();
         $stream_count = TwitchStream::select('id')->where('modpack_id', $modpack)->count();
     }
     if (!$raw_streams) {
         return Response::json(['error' => 'No results.']);
     }
     foreach ($raw_streams as $stream) {
         $streams['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];
     }
     $streams['meta'] = ['total_results' => $stream_count, 'limit' => $limit, 'offset' => $offset];
     return Response::json($streams);
 }