2020-06-24 16:46:39 +02:00
|
|
|
|
<?php
|
2020-07-16 20:38:51 +02:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Application web pour voir la durée pour finir à 100% des jeux de son compte steam
|
|
|
|
|
|
|
|
|
|
author: rick@gnous.eu
|
|
|
|
|
git: https://git.gnous.eu/Rick/triAchievements
|
2020-07-21 11:12:26 +02:00
|
|
|
|
version: 1.1.0
|
2020-07-16 20:38:51 +02:00
|
|
|
|
*/
|
|
|
|
|
|
2020-06-24 16:46:39 +02:00
|
|
|
|
// ~ 4 minutes pour ~ 350 jeux
|
|
|
|
|
$config = parse_ini_file("config.ini");
|
|
|
|
|
define('API_KEY', $config["steam_api_key"]);
|
|
|
|
|
|
|
|
|
|
$apikey = $config["steam_api_key"];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* retourne un objet json à partir d'une url
|
2020-07-16 20:38:51 +02:00
|
|
|
|
*
|
|
|
|
|
* @param string $url
|
|
|
|
|
* l’url retournant un json
|
|
|
|
|
* @return
|
|
|
|
|
* - l’objet JSON de l’url
|
|
|
|
|
* - NULL si l’url ne renvoie pas de json
|
2020-06-24 16:46:39 +02:00
|
|
|
|
*/
|
|
|
|
|
function getJson($url)
|
|
|
|
|
{
|
|
|
|
|
$array = file_get_contents($url);
|
|
|
|
|
$ret = json_decode($array, true);
|
|
|
|
|
return $ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* renvoie le nombre d'heures qu'il faut pour finir un jeu à 100%
|
2020-07-16 20:38:51 +02:00
|
|
|
|
*
|
|
|
|
|
* @param int $appid
|
|
|
|
|
* l’id steam du jeu dont il faut récupérer l’heure de complétion sur astat
|
|
|
|
|
* @return string|null
|
|
|
|
|
* - le temps qu’il faut pour finir le jeu
|
|
|
|
|
* - null si le jeu n’a pas de temps renseigné
|
2020-06-24 16:46:39 +02:00
|
|
|
|
*/
|
|
|
|
|
function getHours($appid)
|
|
|
|
|
{
|
|
|
|
|
$url = "http://astats.astats.nl/astats/Steam_Game_Info.php?AppID="; // 813630";
|
2020-07-21 11:11:02 +02:00
|
|
|
|
$html = new DOMDocument();
|
|
|
|
|
$html->loadHTMLFile($url.$appid);
|
|
|
|
|
|
|
|
|
|
$span = $html->getElementsByTagName('td');
|
|
|
|
|
|
|
|
|
|
$searchFor = 'Hours to 100%';
|
|
|
|
|
$regex = '/(?<=\b'.$searchFor.'\s)(?:[\w|,|.]+)/is';
|
|
|
|
|
foreach($span as $node) {
|
|
|
|
|
$text = $node->nodeValue;
|
|
|
|
|
$text = preg_replace('/\s+/', ' ',$text);
|
|
|
|
|
if (preg_match($regex, $text, $matches, PREG_OFFSET_CAPTURE)) {
|
|
|
|
|
return $matches[0][0];
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-06-24 16:46:39 +02:00
|
|
|
|
}
|
2020-07-21 11:11:02 +02:00
|
|
|
|
return null;
|
2020-06-24 16:46:39 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* check si un jeu a des succès
|
2020-07-16 20:38:51 +02:00
|
|
|
|
*
|
|
|
|
|
* @param int $appid
|
|
|
|
|
* id du jeu à vérifier
|
|
|
|
|
* @return bool
|
|
|
|
|
* true si le jeu à des succès, false sinon
|
2020-06-24 16:46:39 +02:00
|
|
|
|
*/
|
|
|
|
|
function hasAchievements($appid)
|
|
|
|
|
{
|
|
|
|
|
file_get_contents("http://api.steampowered.com/ISteamUserStats/GetGlobalAchievementPercentagesForApp/v0002/?gameid=".$appid);
|
|
|
|
|
$pattern = preg_quote(' 403 ', '/');
|
|
|
|
|
$pattern = "/^.*$pattern.*\$/m";
|
|
|
|
|
if(preg_match($pattern, $http_response_header[0])){
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* verifie si le jeu est fini à 100%
|
2020-07-16 20:38:51 +02:00
|
|
|
|
*
|
|
|
|
|
* @param int $appid
|
|
|
|
|
* le numéro du jeu à vérifier
|
|
|
|
|
* @param int $steamid
|
|
|
|
|
* l’id steam du compte possédant le jeu
|
|
|
|
|
* @return bool
|
|
|
|
|
* true si le jeu est fini, false sinon
|
2020-06-24 16:46:39 +02:00
|
|
|
|
*/
|
|
|
|
|
function checkComplete($appid, $steamid)
|
|
|
|
|
{
|
|
|
|
|
$gameInfo = getJson("http://api.steampowered.com/ISteamUserStats/GetPlayerAchievements/v0001/?key=".API_KEY."&steamid=".$steamid."&appid=" . $appid);
|
|
|
|
|
$listAchievements = $gameInfo["playerstats"]["achievements"];
|
|
|
|
|
foreach ($listAchievements as $key => $value) {
|
|
|
|
|
if ($value["achieved"] == 0) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* affiche un tableau HTML contenant les jeux triés par ordre croissant de temps de fin
|
|
|
|
|
*/
|
|
|
|
|
if (isset($_POST['steamid'])) {
|
|
|
|
|
$ret = array();
|
|
|
|
|
$steamid = $_POST['steamid'];
|
|
|
|
|
$url = "http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key=".API_KEY."&steamid=".$steamid;
|
|
|
|
|
$listGames = file_get_contents($url);
|
2020-07-19 01:42:11 +02:00
|
|
|
|
$responseListGames = json_decode($listGames, true)["response"];
|
2020-06-24 16:46:39 +02:00
|
|
|
|
if ($listGames == NULL) {
|
|
|
|
|
$ret = array('error' => 'User not found.', 'response' => $http_response_header);
|
2020-07-19 01:42:11 +02:00
|
|
|
|
} elseif (empty($responseListGames)) {
|
2020-07-21 11:11:02 +02:00
|
|
|
|
$ret = array('error' => 'Private Account.', 'response' => $http_response_header);
|
2020-06-24 16:46:39 +02:00
|
|
|
|
} else {
|
|
|
|
|
$url = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=".API_KEY."&steamids=".$steamid;
|
|
|
|
|
$userInformations = getJson($url);
|
|
|
|
|
$ret["username"] = $userInformations["response"]["players"][0]["personaname"];
|
|
|
|
|
|
|
|
|
|
$listGamesJson = json_decode($listGames, true);
|
|
|
|
|
$listGamesJson = $listGamesJson["response"];
|
|
|
|
|
$url = "http://api.steampowered.com/ISteamUserStats/GetPlayerAchievements/v0001/?key=".API_KEY."&steamid=".$steamid."&appid=";
|
|
|
|
|
|
|
|
|
|
foreach ($listGamesJson["games"] as $key => $value) {
|
|
|
|
|
$appid = $value["appid"];
|
|
|
|
|
if (hasAchievements($appid)) {
|
|
|
|
|
if (!checkComplete($appid, $steamid)) {
|
|
|
|
|
$gameName = getJson($url.$appid);
|
|
|
|
|
$gameName = $gameName["playerstats"]["gameName"];
|
|
|
|
|
$hours = getHours($appid);
|
|
|
|
|
|
|
|
|
|
if ($hours == null) {
|
|
|
|
|
$ret["gameWithoutTime"][] = array('gamename' => $gameName, 'hours' => $hours);
|
|
|
|
|
} else {
|
|
|
|
|
$ret["gameWithTime"][] = array('gamename' => $gameName, 'hours' => $hours);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$retJson = json_encode($ret);
|
|
|
|
|
$_POST["game"] = $retJson;
|
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
|
echo $retJson;
|
|
|
|
|
}
|
|
|
|
|
?>
|