Skip to content

Instantly share code, notes, and snippets.

@Chaser324
Last active January 3, 2016 20:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Chaser324/34b312bc3355e629cc8a to your computer and use it in GitHub Desktop.
Save Chaser324/34b312bc3355e629cc8a to your computer and use it in GitHub Desktop.
GiantBomb API - PHP to get release's multiplayer, resolutions and controls.
<?php
function relextra($html, $end, &$pos){
$buf = GetBetween($html, '<dd', '>'.$end, $pos);
return stripos($buf, '"yes"') !== false;
}
function relextracheck($releaseId, $categoryId, $html, $end, &$pos){
$nowhave = relextra($html, $end, $pos);
echo(strip_tags($end).' is turned '.($nowhave ? 'on' : 'off').' within giantbomb and the releaseId '.
$releaseId.' and the categoryId: '.$categoryId.'<br/>');
}
function extrainfo(){
$releaseID = 5; // this is the ID of our game within our database, not giantbomb
$giantReleaseId = 102897; // this is the id of the release within giantbomb
$url = 'http://www.giantbomb.com/anything-here-all-right/3030-31709/releaseInfo/?id='.
$giantReleaseId;
$buf = @file_get_contents($url);
if ($buf && ($json = json_decode($buf))){
$html = $json->html;
$pos = 0;
echo('Qnt of YES in html: '.substr_count($html, '"yes"').'<br/>');
// pegando resoluções
$resbuf = GetBetween($html, 'Supported Resolutions</th>', '/td>', $pos);
$res = EasyBetween($resbuf, '<td>', '<');
$resarr = array();
if (stripos($res, 'N/A') === false)
$resarr = explode(',', $res);
else
echo('Sem resolução: '.$res);
foreach ($resarr as $res){
$res = trim($res);
// what I did here was:
// 1 - Check if the resolution exists
// 1.1 No - Add it
// 2 - Check if the resolution is attached to the release
// 2.1 No - Add it
}
// What I do down here is check every item of multiplayer and controls.
// the idea is to create an array with the ID of that item within my database as the key
// and the html part to check as the value of the array
// agora yes/no para controles
$controles = array(
400 => 'Camera support',
401 => 'Voice control',
405 => 'Motion control',
406 => 'Driving wheel',
410 => 'Flightstick',
412 => 'PC gamepad',
413 => 'Head tracking'
);
foreach ($controles as $cat_cod => $block)
relextracheck($releaseID, $cat_cod, $html, $block, $pos);
// agora yes/no para multiplayer
$multiplayer = array(
945 => 'Local co-op',
946 => 'LAN co-op',
949 => 'Online co-op',
960 => 'Local competitive',
961 => 'LAN competitive',
962 => 'Online competitive',
963 => 'Local splitscreen',
964 => 'Online splitscreen',
965 => 'Pass and play',
966 => 'Voice chat',
967 => 'Asynchronous multiplayer'
);
foreach ($multiplayer as $cat_cod => $block)
relextracheck($releaseID, $cat_cod, $html, $block, $pos);
}
}
function GetBetween($str, $begtext, $endtext, &$from){
$beglen = strlen($begtext);
$ini = stripos($str, $begtext, $from);
if ($ini === false)
return false;
$inipluslen = $ini + $beglen;
$end = stripos($str, $endtext, $inipluslen);
if ($ini !== false && $end !== false){
$from = $end + strlen($endtext);
return trim(substr($str, $inipluslen, $end - $inipluslen));
}
return false;
}
function EasyBetween($str, $begtext, $endtext, $from=0){
$beglen = strlen($begtext);
$ini = stripos($str, $begtext, $from);
if ($ini === false)
return false;
$inipluslen = $ini + $beglen;
$end = stripos($str, $endtext, $inipluslen);
if ($ini !== false && $end !== false){
$from = $end + strlen($endtext);
return trim(substr($str, $inipluslen, $end - $inipluslen));
}
return false;
}
?>
@Chaser324
Copy link
Author

Created by jonathanrezende. See here for more info.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment