diff --git a/.gitignore b/.gitignore index f9a36d3..b9becb8 100644 --- a/.gitignore +++ b/.gitignore @@ -13,8 +13,11 @@ data/games/nsz/** !data/games/nsz/index.html data/games/xci/** !data/games/xci/index.html -import !data/sms/.htaccess !data/user/.htaccess import/folder.txt -data/base.db \ No newline at end of file +data/base.db +import/token/** +import/temp/** +!import/token/.htaccess +!import/temp/.htaccess \ No newline at end of file diff --git a/import/drive2db.php b/import/drive2db.php new file mode 100644 index 0000000..0108059 --- /dev/null +++ b/import/drive2db.php @@ -0,0 +1,78 @@ +$jsoncredential['expires_in']-300){ + updateToken(); + } + $pathPageToken = "./temp/$idfolder.token"; + $pageToken = (file_exists($pathPageToken))?file_get_contents($pathPageToken):null; + + ulang: + echo $pageToken; + + $list = listFiles($idfolder,$pageToken); + + foreach($list['items'] as $item){ + if($item['fileExtension']=='nsz' || $item['fileExtension']=='xci'){ + if($item['parents'][0]['id'] == $idfolder && !empty($item['title'])){ + $gameid = getGameID($item['title']); + $gameName = $db->get("t_switch","name",['titleid'=>$gameid]); + if(empty($gameName)) $gameName = str_replace([".xci",".nsp",".nsz"],"",$item['title']); + $db->insert('t_games_url',[ + 'url'=>$item['id'], + 'filename'=>$item['title'], + 'title'=>$gameName, + 'titleid'=>$gameid, + 'fileSize'=>$item['fileSize'], + 'md5Checksum'=>$item['md5Checksum'], + 'root'=>$idfolder, + 'owner'=>trim($item['owners'][0]['emailAddress']), + 'folder'=>$folder, + 'shared'=>($item['shared'])?"1":"0", + ]); + $id = $db->id(); + if($id){ + echo $db->id()." - ".$item['title']."\n"; + }else{ + echo json_encode($db->error())."\n".$item['title']."\n"; + } + }else{ + echo "Parents different ".$item['parents'][0]['id']."\n"; + } + }else{ + echo "NOT XCI/NSZ - ".$item['title']."\n"; + } + } + + + if(isset($list['nextLink']) && !empty($list['nextLink'])){ + $pageToken = $list['nextLink']; + file_put_contents("$pathPageToken",$pageToken); + if(!empty($pageToken)) + goto ulang; + else die("EMPTY $idfolder"); + } + + file_put_contents("$pathPageToken",''); + echo "$idfolder FINISH\n\n"; +} + diff --git a/import/file2db.php b/import/file2db.php new file mode 100644 index 0000000..1e774fc --- /dev/null +++ b/import/file2db.php @@ -0,0 +1,13 @@ + $client_id, + 'client_secret' => $client_sc, + 'refresh_token' => $refresh_token, + 'grant_type' => 'refresh_token' + ])); + $authToken = curl_exec($ch); + curl_close($ch); + $jsoncredential = json_decode($authToken,true); + if(isset($jsoncredential['access_token'])){ + file_put_contents("token/credentials.txt", $authToken); + } +} + + +function listFiles($folderID,$nextToken){ + global $jsoncredential,$proxy; + if(!empty($nextToken)){ + $url = $nextToken; + }else{ + $url = 'https://www.googleapis.com/drive/v2/files?q=\''.$folderID.'\'+in+parents' ; + } + echo "$url\n"; + $ch = curl_init($url); + curl_setopt($ch, CURLOPT_PROXY, $proxy); + curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json','Authorization: Bearer '.$jsoncredential['access_token'])); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true ); + $result = curl_exec($ch); + curl_close($ch); + return json_decode($result,true); +} + +function getGameID($str){ + $regex = '/\[\w{16,16}\]/'; + preg_match_all($regex, $str, $matches); + $hasil = str_replace("[","",str_replace("]","",$matches[0][0])); + echo "GameID $hasil\n"; + return $hasil; +} \ No newline at end of file diff --git a/import/importGameData.php b/import/importGameData.php new file mode 100644 index 0000000..93f4a77 --- /dev/null +++ b/import/importGameData.php @@ -0,0 +1,126 @@ +get("t_games", ['titleid', 'size'], ['titleid' => $titleid]); + if (empty($game)) { + try { + $db->insert("t_games", [ + 'titleid' => preg_replace("/[^a-zA-Z0-9]+/", "", $data['titleid']) . "", + 'name' => $data['name'] . "", + 'publisher' => $data['publisher'] . "", + 'languages' => $data['languages'] . "", + 'size' => $data['trimmedsize'] . "", + 'description' => "", + 'image' => "", + 'rating' => "", + 'size' => 0 + ]); + if($db->id()>0){ + echo $titleid . " " . $db->id() . "\n"; + }else{ + print_r($db->error()); + } + } catch (Exception $e) { + print_r($data); + echo "\n"; + echo $data['name'] . " ERROR\n"; + } + } else { + if (empty($game['size'])) { + $db->update("t_games", ['size' => $data['trimmedsize'] * 1], ['titleid' => $titleid]); + echo $titleid . " " . $data['trimmedsize'] . "\n"; + } + } +} +#tinfoil +$releases = json_decode(file_get_contents("https://raw.githubusercontent.com/blawar/titledb/master/US.en.json"), true); +echo count($releases) . " titles\n"; +sleep(4); +foreach ($releases as $version => $data) { + try { + if (!empty($data['name'])) { + if (strlen($data['id']) >= 16) { + $titleid = substr(preg_replace("/[^a-zA-Z0-9]+/", "", $data['id']), 0, 16); + if ($db->has('t_games', ['titleid' => $data['id']])) { + if (!empty($data['iconUrl'] && empty($db->get("t_games", 'image', ['titleid' => $titleid])))) { + echo "image update " . $data['name'] . "\n"; + $db->update( + "t_games", + [ + 'image' => $data['iconUrl'] . "" + ], + ['titleid' => $titleid] + ); + } + if (!empty($data['rating'] && empty($db->get("t_games", 'rating', ['titleid' => $titleid])))) { + echo "rating update " . $data['name'] . "\n"; + $db->update( + "t_games", + [ + 'rating' => $data['rating'] . "" + ], + ['titleid' => $titleid] + ); + } + if (!empty($data['description'] && empty($db->get("t_games", 'description', ['titleid' => $titleid])))) { + echo "description update " . $data['name'] . "\n"; + $db->update( + "t_games", + [ + 'description' => $data['description'] . "" + ], + ['titleid' => $titleid] + ); + } + if (empty($db->get("t_games", 'size', ['titleid' => $titleid]))) { + $hasil = $db->update( + "t_games", + [ + 'size' => $data['size'] * 1 + ], + ['titleid' => $titleid] + ); + if ($hasil->rowCount() > 0) { + echo $hasil->rowCount() . " size update " . $data['size'] . "\n"; + } else { + print_r($db->error()); + } + } + } else { + echo "insert " . $data['name'] . "\n"; + $db->insert("t_games", [ + 'titleid' => preg_replace("/[^a-zA-Z0-9]+/", "", $data['id']) . "", + 'name' => $data['name'] . "", + 'publisher' => $data['publisher'] . "", + 'languages' => implode(",", (array)$data['languages']), + 'image' => $data['iconUrl'] . "", + 'rating' => $data['rating'] . "", + 'description' => $data['description'] . "", + 'size' => $data['size'] * 1 + ]); + } + } + } + } catch (Exception $e) { + print_r($data); + echo "\n"; + echo $data['name'] . " ERROR\n"; + } +} diff --git a/import/index.html b/import/index.html new file mode 100644 index 0000000..7e0a6be --- /dev/null +++ b/import/index.html @@ -0,0 +1 @@ +This folder only run from command line \ No newline at end of file diff --git a/import/login.php b/import/login.php new file mode 100644 index 0000000..4574b06 --- /dev/null +++ b/import/login.php @@ -0,0 +1,49 @@ + urldecode($_GET['code']), + 'client_id' => $client_id, + 'client_secret' => $client_sc, + 'redirect_uri' => $redirectURI, + 'grant_type' => 'authorization_code' + ])); + $authToken = curl_exec($ch); + curl_close($ch); + $json = json_decode($authToken,true); + if(isset($json['access_token'])){ + //save refresh token + file_put_contents("token/refresh.token",$json['refresh_token']); + //save real token + file_put_contents("token/credentials.txt",$authToken); + }else{ + echo "gagal"; + } + echo $authToken; + } +} + +connectWithGoogle( + $scopes, + $redirect +); \ No newline at end of file diff --git a/import/temp/.htaccess b/import/temp/.htaccess new file mode 100644 index 0000000..14249c5 --- /dev/null +++ b/import/temp/.htaccess @@ -0,0 +1 @@ +Deny from all \ No newline at end of file diff --git a/import/token/.htaccess b/import/token/.htaccess new file mode 100644 index 0000000..14249c5 --- /dev/null +++ b/import/token/.htaccess @@ -0,0 +1 @@ +Deny from all \ No newline at end of file