diff --git a/goLive.php b/goLive.php index fba743c..1493c1e 100644 --- a/goLive.php +++ b/goLive.php @@ -1,22 +1,16 @@ login(IG_USERNAME, IG_PASS); + $ig->login(IG_USERNAME, IG_PASS, true); } catch (\Exception $e) { - echo 'Error While Logging in to Instagram: '.$e->getMessage()."\n"; + echo 'Error While Logging in to Instagram: ' . $e->getMessage() . "\n"; exit(0); } //Block Responsible for Creating the Livestream. try { - if (!$ig->isMaybeLoggedIn) { - logM("Couldn't Login! Exiting!"); - exit(); - } logM("Logged In! Creating Livestream..."); - $stream = $ig->live->create(); + $stream = $ig->liveRequest->create_live(); $broadcastId = $stream->getBroadcastId(); - $ig->live->start($broadcastId); + $ig->liveRequest->start_live($broadcastId); // Switch from RTMPS to RTMP upload URL, since RTMPS doesn't work well. $streamUploadUrl = preg_replace( '#^rtmps://([^/]+?):443/#ui', @@ -51,83 +41,96 @@ ); //Grab the stream url as well as the stream key. - $split = preg_split("[".$broadcastId."]", $streamUploadUrl); + $split = preg_split("[" . $broadcastId . "]", $streamUploadUrl); $streamUrl = $split[0]; - $streamKey = $broadcastId.$split[1]; + $streamKey = $broadcastId . $split[1]; - logM("================================ Stream URL ================================\n".$streamUrl."\n================================ Stream URL ================================"); + logM("================================ Stream URL ================================\n" . $streamUrl . "\n================================ Stream URL ================================"); - logM("======================== Current Stream Key ========================\n".$streamKey."\n======================== Current Stream Key ========================"); + logM("======================== Current Stream Key ========================\n" . $streamKey . "\n======================== Current Stream Key ========================"); logM("^^ Please Start Streaming in OBS/Streaming Program with the URL and Key Above ^^"); logM("Live Stream is Ready for Commands:"); - newCommand($ig->live, $broadcastId, $streamUrl, $streamKey); + newCommand($ig->liveRequest, $broadcastId, $streamUrl, $streamKey); logM("Something Went Super Wrong! Attempting to At-Least Clean Up!"); - $ig->live->getFinalViewerList($broadcastId); - $ig->live->end($broadcastId); + $ig->liveRequest->getFinalViewerList($broadcastId); + $ig->liveRequest->end_live($broadcastId); } catch (\Exception $e) { - echo 'Error While Creating Livestream: '.$e->getMessage()."\n"; + echo 'Error While Creating Livestream: ' . $e->getMessage() . "\n"; } /** * The handler for interpreting the commands passed via the command line. + * + * @param \InstagramFollowers\Request\LiveRequest $live + * @param $broadcastId + * @param $streamUrl + * @param $streamKey + * @throws Exception */ -function newCommand(Live $live, $broadcastId, $streamUrl, $streamKey) { +function newCommand(\InstagramFollowers\Request\LiveRequest $live, $broadcastId, $streamUrl, $streamKey) { print "\n> "; - $handle = fopen ("php://stdin","r"); + $handle = fopen("php://stdin", "r"); $line = trim(fgets($handle)); - if($line == 'ecomments') { - $live->enableComments($broadcastId); + if ($line == 'ecomments') { + $live->MuteUnmuteComments(false, $broadcastId); logM("Enabled Comments!"); } elseif ($line == 'dcomments') { - $live->disableComments($broadcastId); + $live->MuteUnmuteComments(true, $broadcastId); logM("Disabled Comments!"); } elseif ($line == 'stop' || $line == 'end') { fclose($handle); //Needs this to retain, I guess? $live->getFinalViewerList($broadcastId); - $live->end($broadcastId); - logM("Stream Ended!\nWould you like to keep the stream archived for 24 hours? Type \"yes\" to do so or anything else to not."); - print "> "; - $handle = fopen ("php://stdin","r"); - $archived = trim(fgets($handle)); - if ($archived == 'yes') { - logM("Adding to Archive!"); - $live->addToPostLive($broadcastId); - logM("Livestream added to archive!"); - } + $live->end_live($broadcastId); logM("Wrapping up and exiting..."); exit(); } elseif ($line == 'url') { - logM("================================ Stream URL ================================\n".$streamUrl."\n================================ Stream URL ================================"); + logM("================================ Stream URL ================================\n" . $streamUrl . "\n================================ Stream URL ================================"); } elseif ($line == 'key') { - logM("======================== Current Stream Key ========================\n".$streamKey."\n======================== Current Stream Key ========================"); + logM("======================== Current Stream Key ========================\n" . $streamKey . "\n======================== Current Stream Key ========================"); } elseif ($line == 'info') { $info = $live->getInfo($broadcastId); $status = $info->getStatus(); - $muted = var_export($info->is_Messages(), true); + $active = $info->getBroadcastStatus(); $count = $info->getViewerCount(); - logM("Info:\nStatus: $status\nMuted: $muted\nViewer Count: $count"); + logM("Info:\nStatus: $status\nActive: $active\nViewer Count: $count"); } elseif ($line == 'viewers') { logM("Viewers:"); $live->getInfo($broadcastId); foreach ($live->getViewerList($broadcastId)->getUsers() as &$cuser) { - logM("@".$cuser->getUsername()." (".$cuser->getFullName().")"); + logM("@" . $cuser->getUsername() . " (" . $cuser->getFullName() . ")"); } } elseif ($line == 'help') { - logM("Commands:\nhelp - Prints this message\nurl - Prints Stream URL\nkey - Prints Stream Key\ninfo - Grabs Stream Info\nviewers - Grabs Stream Viewers\necomments - Enables Comments\ndcomments - Disables Comments\nstop - Stops the Live Stream"); + logM("Commands:\nhelp - Prints this message\nurl - Prints Stream URL\nkey - Prints Stream Key\ninfo - Grabs Stream Info\nviewers - Grabs Stream Viewers\necomments - Enables Comments\ndcomments - Disables Comments\ncomment - Posts New Comment\npin - Pins Comments\nunpin - Unpins Comments\nstop - Stops the Live Stream"); + } elseif ($line == 'comment') { + $live->comment(getInput("Please insert your comment"), $live->create_live_response->getBroadcastId()); + logM("Finished\nCommend Id:" . $live->comment_response->getComment()->getPk()); + } elseif ($line == 'pin') { + $live->PinUnpinLiveComment(true, $live->create_live_response->getBroadcastId(), getInput("Please insert comment Id")); + logM("Finished."); + } elseif ($line == 'unpin') { + $live->PinUnpinLiveComment(false, $live->create_live_response->getBroadcastId(), getInput("Please insert comment id")); + logM("Finished."); + } else { - logM("Invalid Command. Type \"help\" for help!"); + logM("Invalid Command. Type \"help\" for help!"); } fclose($handle); newCommand($live, $broadcastId, $streamUrl, $streamKey); } +function getInput($message) { + print "$message:\n> "; + $h = fopen("php://stdin", "r"); + return trim(fgets($h)); +} + /** * Logs a message in console but it actually uses new lines. */ function logM($message) { - print $message."\n"; -} \ No newline at end of file + print $message . "\n"; +}