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 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);
 }