“6.0.0”
This commit is contained in:
parent
0e0cf3c96f
commit
8036b261ad
80
download.py
80
download.py
@ -1,12 +1,13 @@
|
||||
import os,requests,json,time,sys,argparse,psutil
|
||||
Log=""
|
||||
UA={'User-Agent':'GeMCAPI/5.0.0 (GeMC API Sync 5.0.0;Release)'}
|
||||
UA={'User-Agent':'GeMCAPI/6.0.0 (GeMC API Sync 6.0.0;Release)'}
|
||||
parser=argparse.ArgumentParser()
|
||||
parser.add_argument("--url", help="The online url of the file which need to download.")
|
||||
parser.add_argument("--file", help="The file path of the file which need to download.")
|
||||
parser.add_argument("--other", help="Other parameter which help some special file to download correctly.")
|
||||
parser.add_argument("--url")
|
||||
parser.add_argument("--file")
|
||||
parser.add_argument("--type")
|
||||
parser.add_argument("--type_sub")
|
||||
parser=parser.parse_args()
|
||||
proxies={'http':'http://127.0.0.1:4780'}
|
||||
proxies={'http':'http://127.0.0.1:4780'}#Proxy Setting
|
||||
def log(log_type,logvar):
|
||||
global Log
|
||||
if(log_type=="info"):
|
||||
@ -16,14 +17,69 @@ def log(log_type,logvar):
|
||||
elif(log_type=="error"):
|
||||
log_type="ERROR"
|
||||
Log=Log + '\n' + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[' + log_type + ']' + logvar
|
||||
def is_json(url):
|
||||
global Log
|
||||
global UA
|
||||
global proxies
|
||||
online_return=requests.get(url, headers=UA, proxies=proxies).text
|
||||
try:
|
||||
json.loads(online_return)
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
def download(url, dirpath):
|
||||
global Log
|
||||
global UA
|
||||
global proxies
|
||||
global last_dirpath
|
||||
global return_format
|
||||
global return_headers
|
||||
log("info",'We are downloading the file ' + dirpath + '.')
|
||||
return_headers=requests.get(url, headers=UA, proxies=proxies).headers['content-type']
|
||||
last_dirpath=''
|
||||
make_dir_exist('file/' + parser.file[::-1].split('/', 1)[-1][::-1])
|
||||
try:
|
||||
download=requests.get(url, headers=UA, proxies=proxies)
|
||||
with open(dirpath,"wb") as code:
|
||||
code.write(download.content)
|
||||
if(return_headers=="application/json"):
|
||||
return_format="json"
|
||||
if('.json' in dirpath):
|
||||
download=requests.get(url, headers=UA, proxies=proxies)
|
||||
with open(dirpath,"wb") as code:
|
||||
code.write(download.content)
|
||||
else:
|
||||
make_dir_exist(dirpath)
|
||||
download=requests.get(url, headers=UA, proxies=proxies)
|
||||
with open(dirpath + '/index.json',"wb") as code:
|
||||
code.write(download.content)
|
||||
last_dirpath='/index.json'
|
||||
elif(return_headers=="application/json; charset=utf-8"):
|
||||
return_format="json"
|
||||
if('.json' in dirpath):
|
||||
download=requests.get(url, headers=UA, proxies=proxies)
|
||||
with open(dirpath,"wb") as code:
|
||||
code.write(download.content)
|
||||
else:
|
||||
make_dir_exist(dirpath)
|
||||
download=requests.get(url, headers=UA, proxies=proxies)
|
||||
with open(dirpath + '/index.json',"wb") as code:
|
||||
code.write(download.content)
|
||||
last_dirpath='/index.json'
|
||||
elif(return_headers=="application/java-archive"):
|
||||
return_format="jar"
|
||||
if('.jar' in dirpath):
|
||||
download=requests.get(url, headers=UA, proxies=proxies)
|
||||
with open(dirpath,"wb") as code:
|
||||
code.write(download.content)
|
||||
else:
|
||||
make_dir_exist(dirpath)
|
||||
download=requests.get(url, headers=UA, proxies=proxies)
|
||||
with open(dirpath + '/index.jar',"wb") as code:
|
||||
code.write(download.content)
|
||||
last_dirpath='/index.jar'
|
||||
else:
|
||||
return_format=""
|
||||
download=requests.get(url, headers=UA, proxies=proxies)
|
||||
with open(dirpath,"wb") as code:
|
||||
code.write(download.content)
|
||||
except:
|
||||
log("error",'There has a error in task while downloading the file ' + dirpath + '.')
|
||||
else:
|
||||
@ -35,5 +91,9 @@ def make_dir_exist(dirpath):
|
||||
else:
|
||||
log("info",'The dir ' + dirpath + ' does not exist.We will create one.')
|
||||
os.makedirs(dirpath)
|
||||
make_dir_exist(parser.file[::-1].split('/', 1)[-1][::-1])
|
||||
download(parser.url,parser.file)
|
||||
download(parser.url,'file/' + parser.file)
|
||||
print("INSERT INTO `common` (`path`, `source`, `last_update`, `type`, `type_sub`, `format`, `header`, `file`) VALUES ('" + parser.file + "', '" + parser.url + "', '" + str(round(float(time.time()))) + "', '" + parser.type + "', '" + parser.type_sub + "', '" + return_format + "', '" + return_headers + "', 'file/" + parser.file + last_dirpath + "');")
|
||||
make_dir_exist('logs')
|
||||
logwrite=open("logs/" + str(time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime()) + '.txt'),mode='w')
|
||||
logwrite.write(Log)
|
||||
logwrite.close()
|
1
file/forge/list/10/index.json
Normal file
1
file/forge/list/10/index.json
Normal file
@ -0,0 +1 @@
|
||||
[{"_id":"5be154787dc7d7bc03067b81","build":1,"__v":0,"version":"1.3.2.1","modified":"2012-02-02T21:42:00.000Z","mcversion":"1.1","files":[{"category":"changelog","format":"txt"},{"category":"client","format":"zip"},{"category":"server","format":"zip"},{"category":"src","format":"zip"}],"branch":null},{"_id":"5be154787dc7d7bc03067b82","build":2,"__v":0,"version":"1.3.2.2","modified":"2012-10-28T15:41:00.000Z","mcversion":"1.1","files":[{"category":"changelog","format":"txt"},{"category":"client","format":"zip"},{"category":"server","format":"zip"},{"category":"src","format":"zip"}],"branch":null},{"_id":"5be154787dc7d7bc03067b83","build":6,"__v":0,"version":"1.3.2.6","modified":"2012-08-22T11:44:00.000Z","mcversion":"1.1","files":[{"category":"changelog","format":"txt"},{"category":"client","format":"zip"},{"category":"server","format":"zip"},{"category":"src","format":"zip"}],"branch":null},{"_id":"5be154787dc7d7bc03067b84","build":5,"__v":0,"version":"1.3.2.5","modified":"2012-08-22T11:43:00.000Z","mcversion":"1.1","files":[{"category":"changelog","format":"txt"},{"category":"client","format":"zip"},{"category":"server","format":"zip"},{"category":"src","format":"zip"}],"branch":null},{"_id":"5be154787dc7d7bc03067b85","build":3,"__v":0,"version":"1.3.2.3","modified":"2012-10-28T15:41:00.000Z","mcversion":"1.1","files":[{"category":"changelog","format":"txt"},{"category":"client","format":"zip"},{"category":"server","format":"zip"},{"category":"src","format":"zip"}],"branch":null},{"_id":"5be154787dc7d7bc03067b86","build":4,"__v":0,"version":"1.3.2.4","modified":"2012-08-22T11:43:00.000Z","mcversion":"1.1","files":[{"category":"changelog","format":"txt"},{"category":"client","format":"zip"},{"category":"server","format":"zip"},{"category":"src","format":"zip"}],"branch":null},{"_id":"5be154787dc7d7bc03067b87","build":12,"__v":0,"version":"1.3.3.12","modified":"2012-08-22T11:44:00.000Z","mcversion":"1.1","files":[{"category":"changelog","format":"txt"},{"category":"client","format":"zip"},{"category":"server","format":"zip"},{"category":"src","format":"zip"}],"branch":null},{"_id":"5be154787dc7d7bc03067c0f","build":183,"__v":0,"version":"4.0.0.183","modified":"2012-08-13T15:33:00.000Z","mcversion":"1.3.2","files":[{"category":"changelog","format":"txt"},{"category":"src","format":"zip"},{"category":"universal","format":"zip"}],"branch":null},{"_id":"5be154787dc7d7bc03067b88","build":7,"__v":0,"version":"1.3.2.7","modified":"2012-10-28T15:41:00.000Z","mcversion":"1.1","files":[{"category":"changelog","format":"txt"},{"category":"client","format":"zip"},{"category":"server","format":"zip"},{"category":"src","format":"zip"}],"branch":null},{"_id":"5be154787dc7d7bc03067b89","build":8,"__v":0,"version":"1.3.2.8","modified":"2012-10-28T15:41:00.000Z","mcversion":"1.1","files":[{"category":"changelog","format":"txt"},{"category":"client","format":"zip"},{"category":"server","format":"zip"},{"category":"src","format":"zip"}],"branch":null}]
|
1149
file/liteloader/dl/versions/versions.json
Normal file
1149
file/liteloader/dl/versions/versions.json
Normal file
File diff suppressed because it is too large
Load Diff
345
index.php
345
index.php
@ -1,261 +1,194 @@
|
||||
<?php
|
||||
error_reporting(0);
|
||||
ini_set('user_agent', 'GeMCAPI/5.0.0 (GeMC API Sync 5.0.0;Release)');
|
||||
$active=array('mojang/launchermeta/mc/game/version_manifest.json','forge/last','optifine/versionlist','liteloader/dl/versions/versions.json');
|
||||
$type=array('.com','.net','.com','.moe');
|
||||
//[0]:mojang,[1]:fabricmc,[2]:liteloader,[3]:authlib-injector
|
||||
function url_exists($url){
|
||||
error_reporting(0);//抑制部分无关紧要的报错
|
||||
/*---------------------
|
||||
6.0.0正在开发,请不要使用
|
||||
6.0.0正在开发,请不要使用
|
||||
6.0.0正在开发,请不要使用
|
||||
---------------------*/
|
||||
ini_set('user_agent', 'GeMCAPI/6.0.0 (GeMC API Sync 6.0.0;Release)');//设置默认UA
|
||||
$server_id=1;//服务器的ID
|
||||
$active=array('mojang/launchermeta/mc/game/version_manifest.json','forge/last','optifine/versionlist','liteloader/dl/versions/versions.json','forge/minecraft');//需要保持最新的文件
|
||||
$type=array('.com','.net','.com','.moe','.net');//分配域名
|
||||
//[0]:mojang,[1]:fabricmc,[2]:liteloader,[3]:authlib-injector,[4]:minecraft
|
||||
function is_url_exists($url){
|
||||
$opts = array(
|
||||
'http'=>array(
|
||||
'timeout'=>3,
|
||||
)
|
||||
);
|
||||
$context = stream_context_create($opts);
|
||||
return @file_get_contents($url, false, $context);
|
||||
return @file_get_contents($url, false, $context);//尝试访问文件,无法访问则不存在
|
||||
}
|
||||
function download_file($url,$file,$other){//下载文件
|
||||
system('python download.py --url "'.$url.'" --file "'.$file.'" --other "'.$other.'"');
|
||||
function download_file($url,$file,$type,$type_sub){
|
||||
global $link;
|
||||
ob_start();
|
||||
$result_download=system('python download.py --url "'.$url.'" --file "'.$file.'" --type "'.$type.'" --type_sub "'.$type_sub.'"');
|
||||
ob_clean();
|
||||
//echo $result_download;
|
||||
//echo 'python download.py --url "'.$url.'" --file "'.$file.'" --type "'.$type.'" --type_sub "'.$type_sub.'"';
|
||||
mysqli_query($link,$result_download);
|
||||
//使用Python下载,避开了PHP下载文件的不稳定劣势
|
||||
}
|
||||
function get_main_domain($file){
|
||||
//使用正则表达式筛选信息
|
||||
$str=preg_replace('/^[^\/]*\//is','',$file);
|
||||
$str2=str_replace('/'.$str,'',$file);
|
||||
return $str2;
|
||||
}
|
||||
function get_sub_domain($file){
|
||||
//使用正则表达式筛选信息
|
||||
$str=preg_replace('/^[^\/]*\//is','',$file);
|
||||
$str2=preg_replace('/^[^\/]*\//is','',$str);
|
||||
$str3=str_replace('/'.$str2,'',$str);
|
||||
return $str3;
|
||||
}
|
||||
function get_file_path($file){
|
||||
//使用正则表达式筛选信息
|
||||
$str=preg_replace('/^[^\/]*\//is','',$file);
|
||||
$str2=preg_replace('/^[^\/]*\//is','',$str);
|
||||
return $str2;
|
||||
}
|
||||
function get_online_url($file,$id){
|
||||
function get_online_url($file){
|
||||
//字符串拼接用函数
|
||||
global $type;
|
||||
$str='http://'.get_sub_domain($file).'.'.get_main_domain($file).$type[$id].'/'.get_file_path($file);
|
||||
global $id;
|
||||
if(strstr($file,"maven")){
|
||||
$str="https://bmclapi2.bangbang93.com/".$file;
|
||||
}elseif(strstr($file,"forge/")){
|
||||
$str="https://bmclapi2.bangbang93.com/".$file;
|
||||
}elseif(strstr($file,"optifine/")){
|
||||
$str="https://bmclapi2.bangbang93.com/".$file;
|
||||
}elseif(strstr($file,"liteloader/list")){
|
||||
$str="https://bmclapi2.bangbang93.com/".str_replace('list/','list?',$file);
|
||||
}else{
|
||||
$str='https://'.get_sub_domain($file).'.'.get_main_domain($file).$type[$id].'/'.get_file_path($file);
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
function get_online_domain($file,$id){
|
||||
function get_online_domain($file){
|
||||
//字符串拼接用函数
|
||||
global $type;
|
||||
$str='http://'.get_sub_domain($file).'.'.get_main_domain($file).$type[$id].'/';
|
||||
global $id;
|
||||
$str='https://'.get_sub_domain($file).'.'.get_main_domain($file).$type[$id].'/';
|
||||
return $str;
|
||||
}
|
||||
function check_file_update($file,$dir,$url,$time){
|
||||
global $replace_mode;
|
||||
if($replace_mode==true){
|
||||
$file=str_replace('?','/',$file);
|
||||
}
|
||||
header('Content-Disposition: attachment; filename="'.basename($file).'"');
|
||||
$time=time()-@filemtime($file);
|
||||
if($time<$time){//检查文件是否超出过期期限(1天,86400秒)
|
||||
echo file_get_contents($file);
|
||||
function output_file($array){
|
||||
header('Content-type: '.$array['header']);
|
||||
if($array['header']=="application/json"){
|
||||
//是JSON文件,不强制下载
|
||||
}else{
|
||||
if(url_exists($url.'/'.str_replace($dir,'',$file))){//防止源无法访问而损坏文件
|
||||
if(file_get_contents($url.'/'.str_replace($dir,'',$file))==@file_get_contents($file)){
|
||||
echo file_get_contents($file);
|
||||
}else{
|
||||
echo file_get_contents($url.'/'.str_replace($dir,'',$file));
|
||||
download_file($url.'/'.str_replace($dir,'',$file),$file,'');
|
||||
}
|
||||
}else{
|
||||
echo file_get_contents($file);
|
||||
}
|
||||
//非JSON文件,直接强制下载
|
||||
header('Content-Disposition: attachment; filename="'.basename($array['file']).'"');
|
||||
}
|
||||
echo file_get_contents($array['file']);
|
||||
}
|
||||
function check_file_update_json($file,$dir,$url,$time){
|
||||
global $replace_mode;
|
||||
if($replace_mode==true){
|
||||
$file=str_replace('?','/',$file);
|
||||
}
|
||||
header('Content-Disposition: attachment; filename="'.basename($file).'.json"');
|
||||
$time=time()-@filemtime($file.'/index.json');
|
||||
if($time<$time){//检查文件是否超出过期期限(1天,86400秒)
|
||||
echo file_get_contents($file.'/index.json');
|
||||
function check_file_update($file,$url,$time){
|
||||
global $result;
|
||||
if(is_file('file/'.$file)){//判断本地文件是否存在
|
||||
$time=time()-@filemtime('file/'.$file);
|
||||
if($time<$time){//检查文件是否超出过期期限
|
||||
echo file_get_contents('file/'.$file);
|
||||
}else{
|
||||
if(is_url_exists($url)){//防止源无法访问而损坏文件
|
||||
if(file_get_contents($url)==@file_get_contents('file/'.$file)){
|
||||
echo file_get_contents('file/'.$file);
|
||||
}else{
|
||||
ob_start();
|
||||
system('python download.py --url "'.$url.'" --file "'.$file.'" --type "pass" --type_sub "pass"');
|
||||
ob_clean();
|
||||
echo file_get_contents('file/'.$file);
|
||||
}
|
||||
}else{
|
||||
echo file_get_contents('file/'.$file);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
if(url_exists($url.'/'.str_replace($dir,'',$file))){//防止源无法访问而损坏文件
|
||||
if(file_get_contents($url.'/'.str_replace($dir,'',$file))==@file_get_contents($file.'/index.json')){
|
||||
echo file_get_contents($file);
|
||||
}else{
|
||||
echo file_get_contents($url.'/'.str_replace($dir,'',$file));
|
||||
download_file($url.'/'.str_replace($dir,'',$file),$file.'/index.json','');
|
||||
}
|
||||
}else{
|
||||
echo file_get_contents($file.'/index.json');
|
||||
}
|
||||
ob_start();
|
||||
system('python download.py --url "'.$url.'" --file "'.$file.'" --type "pass" --type_sub "pass"');
|
||||
ob_clean();
|
||||
echo file_get_contents('file/'.$file);
|
||||
}
|
||||
}
|
||||
function check_file_update_jar($file,$dir,$url,$time){
|
||||
global $replace_mode;
|
||||
if($replace_mode==true){
|
||||
$file=str_replace('?','/',$file);
|
||||
}
|
||||
header('Content-Disposition: attachment; filename="'.basename($file).'.jar"');
|
||||
$time=time()-@filemtime($file.'/index.jar');
|
||||
if($time<$time){//检查文件是否超出过期期限(1天,86400秒)
|
||||
echo file_get_contents($file.'/index.jar');
|
||||
}else{
|
||||
if(url_exists($url.'/'.str_replace($dir,'',$file))){//防止源无法访问而损坏文件
|
||||
if(file_get_contents($url.'/'.str_replace($dir,'',$file))==@file_get_contents($file.'/index.jar')){
|
||||
echo file_get_contents($file);
|
||||
}else{
|
||||
echo file_get_contents($url.'/'.str_replace($dir,'',$file));
|
||||
download_file($url.'/'.str_replace($dir,'',$file),$file.'/index.jar','');
|
||||
}
|
||||
}else{
|
||||
echo file_get_contents($file.'/index.jar');
|
||||
}
|
||||
}
|
||||
function is_server_alive($file){
|
||||
global $type;
|
||||
global $id;
|
||||
$url='https://'.get_sub_domain($file).'.'.get_main_domain($file).$type[$id];
|
||||
$opts = array(
|
||||
'http'=>array(
|
||||
'timeout'=>3,
|
||||
)
|
||||
);
|
||||
$context = stream_context_create($opts);
|
||||
return @file_get_contents($url, false, $context);//尝试访问文件,无法访问则不存在
|
||||
}
|
||||
function check_file_update_adv($file,$url,$check_url){
|
||||
global $replace_mode;
|
||||
if($replace_mode==true){
|
||||
$file=str_replace('?','/',$file);
|
||||
}
|
||||
header('Content-Disposition: attachment; filename="'.basename($file).'"');
|
||||
$time=time()-@filemtime($file);
|
||||
if($time<86400){//检查文件是否超出过期期限(1天,86400秒)
|
||||
echo file_get_contents($file);
|
||||
}else{
|
||||
if(url_exists($check_url)){//防止源无法访问而损坏文件
|
||||
if(file_get_contents($url)==@file_get_contents($file)){
|
||||
echo file_get_contents($file);
|
||||
}else{
|
||||
echo @file_get_contents($url);
|
||||
download_file($url,$file,'');
|
||||
}
|
||||
}else{
|
||||
echo file_get_contents($file);
|
||||
}
|
||||
}
|
||||
if(strstr($_GET['path'],'?')!=False){//判断有无特殊字符
|
||||
$get_path=str_replace('?','/',$_GET['path']);
|
||||
}else{
|
||||
$get_path=$_GET['path'];
|
||||
}
|
||||
if(strstr($_GET['path'],'liteloader')!=False){//替换掉Literloader源中的特殊字符
|
||||
$replace_mode=true;
|
||||
}
|
||||
if(get_main_domain($_GET['path'])=='mojang'){//分配顶级域名尾
|
||||
if(get_main_domain($get_path)=='mojang'){//分配顶级域名尾
|
||||
$id=0;
|
||||
}elseif(get_main_domain($_GET['path'])=='fabricmc'){
|
||||
}elseif(get_main_domain($get_path)=='fabricmc'){
|
||||
$id=1;
|
||||
}elseif(get_main_domain($_GET['path'])=='liteloader'){
|
||||
}elseif(get_main_domain($get_path)=='liteloader'){
|
||||
$id=2;
|
||||
}elseif(get_main_domain($_GET['path'])=='yushi'){
|
||||
}elseif(get_main_domain($get_path)=='yushi'){
|
||||
$id=3;
|
||||
}elseif(get_main_domain($get_path)=='minecraft'){
|
||||
$id=4;
|
||||
}
|
||||
if($_GET['error']!=""){
|
||||
echo '{"wikis":"https://gitee.com/ghink/gemcapi/wikis","code":'.$_GET['error'].',"server_time":'.time().'}';
|
||||
}elseif($_GET['path']==""){
|
||||
echo '{"wikis":"https://gitee.com/ghink/gemcapi/wikis","code":200,"server_time":'.time().'}';
|
||||
header('Content-type: application/json');
|
||||
echo '{"wikis":"https://gitee.com/ghink/gemcapi/wikis","code":'.$_GET['error'].',"server_time":'.time().',"server_id":'.$server_id.'}';
|
||||
}elseif($get_path==""){
|
||||
header('Content-type: application/json');
|
||||
echo '{"wikis":"https://gitee.com/ghink/gemcapi/wikis","code":200,"server_time":'.time().',"server_id":'.$server_id.'}';
|
||||
}else{
|
||||
if(is_file($_GET['path'])){
|
||||
//文件存在
|
||||
if(in_array($_GET['path'],$active)){//判断是否为需要保持最新的文件
|
||||
if(strstr($_GET['path'],'mojang/')!=False){//目录分组
|
||||
if(strstr($_GET['path'],'mojang/launchermeta/')!=False){
|
||||
check_file_update('mojang/launchermeta/mc/game/version_manifest.json',get_main_domain($_GET['path']).'/'.get_sub_domain($_GET['path']).'/','http://launchermeta.mojang.com',86400);
|
||||
}
|
||||
}elseif(strstr($_GET['path'],'forge/')!=False){//目录分组
|
||||
if(strstr($_GET['path'],'forge/last')!=False){
|
||||
check_file_update_adv('forge/last/index.json','https://download.mcbbs.net/forge/last','https://download.mcbbs.net/maven/net/minecraftforge/forge/1.7.10-10.13.0.1151/forge-1.7.10-10.13.0.1151-installer.jar');
|
||||
}
|
||||
}elseif(strstr($_GET['path'],'optifine/')!=False){//目录分组
|
||||
if(strstr($_GET['path'],'optifine/versionlist')!=False){
|
||||
check_file_update_adv('optifine/versionlist/index.json','https://download.mcbbs.net/optifine/versionlist','https://download.mcbbs.net/maven/net/minecraftforge/forge/1.7.10-10.13.0.1151/forge-1.7.10-10.13.0.1151-installer.jar');
|
||||
}
|
||||
}elseif(strstr($_GET['path'],'liteloader/')!=False){//目录分组
|
||||
if(strstr($_GET['path'],'liteloader/dl/versions')!=False){
|
||||
check_file_update_adv('liteloader/dl/versions/versions.json','http://dl.liteloader.com/versions/versions.json','http://dl.liteloader.com/versions/versions.json');
|
||||
}
|
||||
$link=mysqli_connect("localhost","gemcapi","ghink2014","gemcapi");
|
||||
$result=mysqli_query($link,"SELECT * FROM `common` WHERE `path` = '".$get_path."';");
|
||||
$result=mysqli_fetch_array($result);
|
||||
if(in_array($get_path,$active)){
|
||||
//需要保持最新的文件,不进行数据库操作
|
||||
if(strstr($get_path,'mojang/')!=False){//目录分组
|
||||
if(strstr($get_path,'mojang/launchermeta/')!=False){
|
||||
header('Content-type: application/json');
|
||||
check_file_update('mojang/launchermeta/mc/game/version_manifest.json','https://launchermeta.mojang.com/mc/game/version_manifest.json','http://launchermeta.mojang.com',86400);
|
||||
}
|
||||
}else{//无需频繁更新的文件
|
||||
if(@file_get_contents(get_online_url($_GET['path'],$id)=="")){
|
||||
check_file_update($_GET['path'],get_main_domain($_GET['path']).'/'.get_sub_domain($_GET['path']).'/',get_online_domain($_GET['path'],$id),2592000);
|
||||
}else{
|
||||
check_file_update_json($_GET['path'],get_main_domain($_GET['path']).'/'.get_sub_domain($_GET['path']).'/',get_online_domain($_GET['path'],$id),2592000);
|
||||
}elseif(strstr($get_path,'forge/')!=False){//目录分组
|
||||
if(strstr($get_path,'forge/last')!=False){
|
||||
header('Content-type: application/json');
|
||||
check_file_update('forge/last/index.json','https://download.mcbbs.net/forge/last','https://download.mcbbs.net/maven/net/minecraftforge/forge/1.7.10-10.13.0.1151/forge-1.7.10-10.13.0.1151-installer.jar',86400);
|
||||
}elseif(strstr($get_path,'forge/minecraft')!=False){
|
||||
header('Content-type: application/json');
|
||||
check_file_update('forge/minecraft/index.json','https://download.mcbbs.net/forge/minecraft','https://download.mcbbs.net/maven/net/minecraftforge/forge/1.7.10-10.13.0.1151/forge-1.7.10-10.13.0.1151-installer.jar',86400);
|
||||
}
|
||||
}elseif(strstr($get_path,'optifine/')!=False){//目录分组
|
||||
if(strstr($get_path,'optifine/versionlist')!=False){
|
||||
header('Content-type: application/json');
|
||||
check_file_update('optifine/versionlist/index.json','https://download.mcbbs.net/optifine/versionlist','https://download.mcbbs.net/maven/net/minecraftforge/forge/1.7.10-10.13.0.1151/forge-1.7.10-10.13.0.1151-installer.jar',86400);
|
||||
}
|
||||
}elseif(strstr($get_path,'liteloader/')!=False){//目录分组
|
||||
if(strstr($get_path,'liteloader/dl/versions')!=False){
|
||||
header('Content-type: application/json');
|
||||
check_file_update('liteloader/dl/versions/versions.json','http://dl.liteloader.com/versions/versions.json','http://dl.liteloader.com/versions/versions.json',86400);
|
||||
}
|
||||
}
|
||||
}elseif(is_dir($_GET['path'])){
|
||||
//目录存在
|
||||
if(strstr($_GET['path'],'forge/minecraft')!=False){//特殊目录返回
|
||||
check_file_update_adv('forge/minecraft/minecraft.json','https://download.mcbbs.net/forge/minecraft','https://download.mcbbs.net/maven/net/minecraftforge/forge/1.7.10-10.13.0.1151/forge-1.7.10-10.13.0.1151-installer.jar');
|
||||
}elseif(strstr($_GET['path'],'yushi/authlib-injector')!=False){
|
||||
check_file_update_adv('yushi/authlib-injector/list.json','https://authlib-injector.yushi.moe','https://download.mcbbs.net/maven/net/minecraftforge/forge/1.7.10-10.13.0.1151/forge-1.7.10-10.13.0.1151-installer.jar');
|
||||
//此处暂时使用bmclapi源检测文件欺骗检测authlib-injector,原因见底部注释
|
||||
}elseif(is_file($_GET['path'].'/index.json')){
|
||||
check_file_update_json($_GET['path'],get_main_domain($_GET['path']).'/'.get_sub_domain($_GET['path']).'/',get_online_domain($_GET['path'],$id),86400);
|
||||
}elseif(is_file($_GET['path'].'/index.jar')){
|
||||
check_file_update_jar($_GET['path'],get_main_domain($_GET['path']).'/'.get_sub_domain($_GET['path']).'/',get_online_domain($_GET['path'],$id),31536000);
|
||||
}else{
|
||||
header('Content-Disposition: attachment; filename="'.basename($_GET['path']).'"');
|
||||
echo file_get_contents($_GET['path']);
|
||||
}
|
||||
}else{
|
||||
//目录或文件不存在
|
||||
if(strstr($_GET['path'],'forge/')!=False){//特殊Forge,采用二级源 BMCLAPI
|
||||
if(url_exists('https://download.mcbbs.net/maven/net/minecraftforge/forge/1.7.10-10.13.0.1151/forge-1.7.10-10.13.0.1151-installer.jar')){
|
||||
if(strstr($_GET['path'],'forge/minecraft')!=False){//forge/minecraft目录特殊同步
|
||||
if($_GET['path']=='forge/minecraft'){
|
||||
check_file_update_adv('forge/minecraft/minecraft.json','https://download.mcbbs.net/forge/minecraft','https://download.mcbbs.net/maven/net/minecraftforge/forge/1.7.10-10.13.0.1151/forge-1.7.10-10.13.0.1151-installer.jar');
|
||||
}else{
|
||||
check_file_update_adv($_GET['path'].'/index.json','https://download.mcbbs.net/'.$_GET['path'],'https://download.mcbbs.net/maven/net/minecraftforge/forge/1.7.10-10.13.0.1151/forge-1.7.10-10.13.0.1151-installer.jar');
|
||||
}
|
||||
}elseif(strstr($_GET['path'],'forge/last')!=False){
|
||||
check_file_update_adv($_GET['path'].'/index.json','https://download.mcbbs.net/'.$_GET['path'],'https://download.mcbbs.net/maven/net/minecraftforge/forge/1.7.10-10.13.0.1151/forge-1.7.10-10.13.0.1151-installer.jar');
|
||||
}elseif(strstr($_GET['path'],'forge/download')!=False){//forge/download目录特殊同步
|
||||
check_file_update_adv($_GET['path'].'/index.jar','https://download.mcbbs.net/'.$_GET['path'],'https://download.mcbbs.net/maven/net/minecraftforge/forge/1.7.10-10.13.0.1151/forge-1.7.10-10.13.0.1151-installer.jar');
|
||||
}else{
|
||||
download_file('https://download.mcbbs.net/'.$_GET['path'],$_GET['path'],'');
|
||||
header('Content-Disposition: attachment; filename="'.basename($_GET['path']).'"');
|
||||
echo file_get_contents($_GET['path']);
|
||||
}
|
||||
}else{
|
||||
echo '{"wikis":"https://gitee.com/ghink/gemcapi/wikis","code":404,"server_time":'.time().'}';
|
||||
header('HTTP/1.1 404 Not Found');
|
||||
}
|
||||
}elseif(strstr($_GET['path'],'optifine/')!=False){//Optifine同步
|
||||
if($_GET['path']=='optifine'){
|
||||
echo '{"wikis":"https://gitee.com/ghink/gemcapi/wikis","code":404,"server_time":'.time().'}';
|
||||
header('HTTP/1.1 404 Not Found');
|
||||
}elseif(strstr($_GET['path'],'optifine/versionlist')!=False){
|
||||
check_file_update_adv(str_replace('?','/',$_GET['path']).'/index.json','https://download.mcbbs.net/'.$_GET['path'],'https://download.mcbbs.net/maven/net/minecraftforge/forge/1.7.10-10.13.0.1151/forge-1.7.10-10.13.0.1151-installer.jar');
|
||||
}else{
|
||||
if(@file_get_contents(get_online_url($_GET['path'],$id)=="")){
|
||||
check_file_update_adv($_GET['path'].'/index.jar','https://download.mcbbs.net/'.$_GET['path'],'https://download.mcbbs.net/maven/net/minecraftforge/forge/1.7.10-10.13.0.1151/forge-1.7.10-10.13.0.1151-installer.jar');
|
||||
}else{
|
||||
if(strstr($_GET['path'],'HD_U')!=False){
|
||||
check_file_update_adv($_GET['path'].'/index.jar','https://download.mcbbs.net/'.$_GET['path'],'https://download.mcbbs.net/maven/net/minecraftforge/forge/1.7.10-10.13.0.1151/forge-1.7.10-10.13.0.1151-installer.jar');
|
||||
}else{
|
||||
check_file_update_adv($_GET['path'].'/index.json','https://download.mcbbs.net/'.$_GET['path'],'https://download.mcbbs.net/maven/net/minecraftforge/forge/1.7.10-10.13.0.1151/forge-1.7.10-10.13.0.1151-installer.jar');
|
||||
}
|
||||
}
|
||||
}
|
||||
}elseif(strstr($_GET['path'],'liteloader/')!=False){//Liteloader同步
|
||||
if(strstr($_GET['path'],'liteloader/list')!=False){
|
||||
check_file_update_adv(str_replace('?','/',$_GET['path']).'/index.json','https://download.mcbbs.net/'.$_GET['path'],'https://download.mcbbs.net/maven/net/minecraftforge/forge/1.7.10-10.13.0.1151/forge-1.7.10-10.13.0.1151-installer.jar');
|
||||
}elseif(strstr($_GET['path'],'liteloader/download')!=False){
|
||||
check_file_update_adv(str_replace('?','/',$_GET['path']).'/index.jar','https://download.mcbbs.net/'.$_GET['path'],'https://download.mcbbs.net/maven/net/minecraftforge/forge/1.7.10-10.13.0.1151/forge-1.7.10-10.13.0.1151-installer.jar');
|
||||
}else{
|
||||
check_file_update_adv($_GET['path'],get_online_url($_GET['path'],$id),'http://dl.liteloader.com/versions/versions.json');
|
||||
}
|
||||
if(strstr($get_path,'forge/list')!=False){//其他特殊同步文件
|
||||
check_file_update($get_path.'/index.json','https://bmclapi2.bangbang93.com/'.$get_path,'https://bmclapi2.bangbang93.com/forge/list/1',86400);
|
||||
}elseif(empty($result)){//普通文件
|
||||
//数据库中没有记录该文件
|
||||
download_file(get_online_url($get_path),$get_path,get_main_domain($get_path),'common');
|
||||
header("refresh: 0");
|
||||
}else{
|
||||
if(url_exists(get_online_url($_GET['path'],$id))){
|
||||
if(@file_get_contents(get_online_url($_GET['path'],$id)=="")){
|
||||
download_file(get_online_url($_GET['path'],$id),$_GET['path'],'');
|
||||
header('Content-Disposition: attachment; filename="'.basename($_GET['path']).'"');
|
||||
echo file_get_contents($_GET['path']);
|
||||
}else{
|
||||
download_file(get_online_url($_GET['path'],$id),$_GET['path'].'/index.json','');
|
||||
header('Content-Disposition: attachment; filename="'.basename($_GET['path']).'"');
|
||||
echo file_get_contents($_GET['path'].'/index.json');
|
||||
}
|
||||
}elseif(get_main_domain($_GET['path'])=='yushi'){
|
||||
//暂不明确为何authlib-injector的服务器即使存活文件存在也会被判定为不存在
|
||||
download_file(get_online_url($_GET['path'],$id),$_GET['path'].'/list.json','');
|
||||
header('Content-Disposition: attachment; filename="'.basename($_GET['path']).'"');
|
||||
echo file_get_contents($_GET['path'].'/list.json');
|
||||
//数据库中记录了该文件
|
||||
if(is_file($result['file'])){//判断本地文件是否存在
|
||||
//文件存在
|
||||
output_file($result);
|
||||
}else{
|
||||
echo '{"wikis":"https://gitee.com/ghink/gemcapi/wikis","code":404,"server_time":'.time().'}';
|
||||
header('HTTP/1.1 404 Not Found');
|
||||
//文件不存在
|
||||
mysqli_query($link,"DELETE FROM `common` WHERE `path`='".$get_path."'");
|
||||
header("refresh: 0");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
5
logs/2020-08-25-18-23-56.txt
Normal file
5
logs/2020-08-25-18-23-56.txt
Normal file
@ -0,0 +1,5 @@
|
||||
|
||||
[2020-08-25 18:23:53][INFO]We are downloading the file file/mojang/launchermeta/mc/game/version_manifest.json.
|
||||
[2020-08-25 18:23:55][INFO]The dir file/mojang/launchermeta/mc/game has already existed.Nothing to do.
|
||||
[2020-08-25 18:23:56][INFO]The file file/mojang/launchermeta/mc/game/version_manifest.json has been downloaded successfully.
|
||||
[2020-08-25 18:23:56][INFO]The dir logs does not exist.We will create one.
|
5
logs/2020-08-25-18-24-59.txt
Normal file
5
logs/2020-08-25-18-24-59.txt
Normal file
@ -0,0 +1,5 @@
|
||||
|
||||
[2020-08-25 18:24:56][INFO]We are downloading the file file/mojang/launchermeta/mc/game/version_manifest.json.
|
||||
[2020-08-25 18:24:58][INFO]The dir file/mojang/launchermeta/mc/game has already existed.Nothing to do.
|
||||
[2020-08-25 18:24:59][INFO]The file file/mojang/launchermeta/mc/game/version_manifest.json has been downloaded successfully.
|
||||
[2020-08-25 18:24:59][INFO]The dir logs has already existed.Nothing to do.
|
5
logs/2020-08-25-18-52-34.txt
Normal file
5
logs/2020-08-25-18-52-34.txt
Normal file
@ -0,0 +1,5 @@
|
||||
|
||||
[2020-08-25 18:52:32][INFO]We are downloading the file file/mojang/launchermeta/mc/game/version_manifest.json.
|
||||
[2020-08-25 18:52:33][INFO]The dir file/mojang/launchermeta/mc/game does not exist.We will create one.
|
||||
[2020-08-25 18:52:34][INFO]The file file/mojang/launchermeta/mc/game/version_manifest.json has been downloaded successfully.
|
||||
[2020-08-25 18:52:34][INFO]The dir logs has already existed.Nothing to do.
|
5
logs/2020-08-25-18-52-56.txt
Normal file
5
logs/2020-08-25-18-52-56.txt
Normal file
@ -0,0 +1,5 @@
|
||||
|
||||
[2020-08-25 18:52:53][INFO]We are downloading the file file/mojang/launchermeta/mc/game/version_manifest.json.
|
||||
[2020-08-25 18:52:55][INFO]The dir file/mojang/launchermeta/mc/game has already existed.Nothing to do.
|
||||
[2020-08-25 18:52:56][INFO]The file file/mojang/launchermeta/mc/game/version_manifest.json has been downloaded successfully.
|
||||
[2020-08-25 18:52:56][INFO]The dir logs has already existed.Nothing to do.
|
5
logs/2020-08-25-18-53-06.txt
Normal file
5
logs/2020-08-25-18-53-06.txt
Normal file
@ -0,0 +1,5 @@
|
||||
|
||||
[2020-08-25 18:53:04][INFO]We are downloading the file file/liteloader/dl/versions/versions.json.
|
||||
[2020-08-25 18:53:05][INFO]The dir file/liteloader/dl/versions does not exist.We will create one.
|
||||
[2020-08-25 18:53:06][INFO]The file file/liteloader/dl/versions/versions.json has been downloaded successfully.
|
||||
[2020-08-25 18:53:06][INFO]The dir logs has already existed.Nothing to do.
|
6
logs/2020-08-25-22-09-47.txt
Normal file
6
logs/2020-08-25-22-09-47.txt
Normal file
@ -0,0 +1,6 @@
|
||||
|
||||
[2020-08-25 22:09:46][INFO]We are downloading the file file/forge/list/10.
|
||||
[2020-08-25 22:09:47][INFO]The dir file/forge/list does not exist.We will create one.
|
||||
[2020-08-25 22:09:47][INFO]The dir file/forge/list/10 does not exist.We will create one.
|
||||
[2020-08-25 22:09:47][INFO]The file file/forge/list/10 has been downloaded successfully.
|
||||
[2020-08-25 22:09:47][INFO]The dir logs has already existed.Nothing to do.
|
39
old/5.0.0/download.py
Normal file
39
old/5.0.0/download.py
Normal file
@ -0,0 +1,39 @@
|
||||
import os,requests,json,time,sys,argparse,psutil
|
||||
Log=""
|
||||
UA={'User-Agent':'GeMCAPI/5.0.0 (GeMC API Sync 5.0.0;Release)'}
|
||||
parser=argparse.ArgumentParser()
|
||||
parser.add_argument("--url", help="The online url of the file which need to download.")
|
||||
parser.add_argument("--file", help="The file path of the file which need to download.")
|
||||
parser.add_argument("--other", help="Other parameter which help some special file to download correctly.")
|
||||
parser=parser.parse_args()
|
||||
proxies={'http':'http://127.0.0.1:4780'}
|
||||
def log(log_type,logvar):
|
||||
global Log
|
||||
if(log_type=="info"):
|
||||
log_type="INFO"
|
||||
elif(log_type=="warn"):
|
||||
log_type="WARN"
|
||||
elif(log_type=="error"):
|
||||
log_type="ERROR"
|
||||
Log=Log + '\n' + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[' + log_type + ']' + logvar
|
||||
def download(url, dirpath):
|
||||
global Log
|
||||
global UA
|
||||
log("info",'We are downloading the file ' + dirpath + '.')
|
||||
try:
|
||||
download=requests.get(url, headers=UA, proxies=proxies)
|
||||
with open(dirpath,"wb") as code:
|
||||
code.write(download.content)
|
||||
except:
|
||||
log("error",'There has a error in task while downloading the file ' + dirpath + '.')
|
||||
else:
|
||||
log("info",'The file ' + dirpath + ' has been downloaded successfully.')
|
||||
def make_dir_exist(dirpath):
|
||||
global Log
|
||||
if os.path.exists(dirpath):
|
||||
log("info",'The dir ' + dirpath + ' has already existed.Nothing to do.')
|
||||
else:
|
||||
log("info",'The dir ' + dirpath + ' does not exist.We will create one.')
|
||||
os.makedirs(dirpath)
|
||||
make_dir_exist(parser.file[::-1].split('/', 1)[-1][::-1])
|
||||
download(parser.url,parser.file)
|
270
old/5.0.0/index.php
Normal file
270
old/5.0.0/index.php
Normal file
@ -0,0 +1,270 @@
|
||||
<?php
|
||||
error_reporting(0);
|
||||
ini_set('user_agent', 'GeMCAPI/5.0.0 (GeMC API Sync 5.0.0;Release)');
|
||||
$server_id=1;//服务器的ID
|
||||
$active=array('mojang/launchermeta/mc/game/version_manifest.json','forge/last','optifine/versionlist','liteloader/dl/versions/versions.json');
|
||||
$type=array('.com','.net','.com','.moe','.net');
|
||||
//[0]:mojang,[1]:fabricmc,[2]:liteloader,[3]:authlib-injector,[4]:minecraft
|
||||
function url_exists($url){
|
||||
$opts = array(
|
||||
'http'=>array(
|
||||
'timeout'=>3,
|
||||
)
|
||||
);
|
||||
$context = stream_context_create($opts);
|
||||
return @file_get_contents($url, false, $context);
|
||||
}
|
||||
function download_file($url,$file,$other){//下载文件
|
||||
system('python download.py --url "'.$url.'" --file "'.$file.'" --other "'.$other.'"');
|
||||
}
|
||||
function get_main_domain($file){
|
||||
$str=preg_replace('/^[^\/]*\//is','',$file);
|
||||
$str2=str_replace('/'.$str,'',$file);
|
||||
return $str2;
|
||||
}
|
||||
function get_sub_domain($file){
|
||||
$str=preg_replace('/^[^\/]*\//is','',$file);
|
||||
$str2=preg_replace('/^[^\/]*\//is','',$str);
|
||||
$str3=str_replace('/'.$str2,'',$str);
|
||||
return $str3;
|
||||
}
|
||||
function get_file_path($file){
|
||||
$str=preg_replace('/^[^\/]*\//is','',$file);
|
||||
$str2=preg_replace('/^[^\/]*\//is','',$str);
|
||||
return $str2;
|
||||
}
|
||||
function get_online_url($file,$id){
|
||||
global $type;
|
||||
$str='https://'.get_sub_domain($file).'.'.get_main_domain($file).$type[$id].'/'.get_file_path($file);
|
||||
return $str;
|
||||
}
|
||||
function get_online_domain($file,$id){
|
||||
global $type;
|
||||
$str='https://'.get_sub_domain($file).'.'.get_main_domain($file).$type[$id].'/';
|
||||
return $str;
|
||||
}
|
||||
function check_file_update($file,$dir,$url,$time){
|
||||
global $replace_mode;
|
||||
if($replace_mode==true){
|
||||
$file=str_replace('?','/',$file);
|
||||
}
|
||||
header('Content-Disposition: attachment; filename="'.basename($file).'"');
|
||||
$time=time()-@filemtime($file);
|
||||
if($time<$time){//检查文件是否超出过期期限(1天,86400秒)
|
||||
echo file_get_contents($file);
|
||||
}else{
|
||||
if(url_exists($url.'/'.str_replace($dir,'',$file))){//防止源无法访问而损坏文件
|
||||
if(file_get_contents($url.'/'.str_replace($dir,'',$file))==@file_get_contents($file)){
|
||||
echo file_get_contents($file);
|
||||
}else{
|
||||
echo file_get_contents($url.'/'.str_replace($dir,'',$file));
|
||||
download_file($url.'/'.str_replace($dir,'',$file),$file,'');
|
||||
}
|
||||
}else{
|
||||
echo file_get_contents($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
function check_file_update_json($file,$dir,$url,$time){
|
||||
global $replace_mode;
|
||||
if($replace_mode==true){
|
||||
$file=str_replace('?','/',$file);
|
||||
}
|
||||
header('Content-Disposition: attachment; filename="'.basename($file).'.json"');
|
||||
$time=time()-@filemtime($file.'/index.json');
|
||||
if($time<$time){//检查文件是否超出过期期限(1天,86400秒)
|
||||
echo file_get_contents($file.'/index.json');
|
||||
}else{
|
||||
if(url_exists($url.'/'.str_replace($dir,'',$file))){//防止源无法访问而损坏文件
|
||||
if(file_get_contents($url.'/'.str_replace($dir,'',$file))==@file_get_contents($file.'/index.json')){
|
||||
echo file_get_contents($file);
|
||||
}else{
|
||||
echo file_get_contents($url.'/'.str_replace($dir,'',$file));
|
||||
download_file($url.'/'.str_replace($dir,'',$file),$file.'/index.json','');
|
||||
}
|
||||
}else{
|
||||
echo file_get_contents($file.'/index.json');
|
||||
}
|
||||
}
|
||||
}
|
||||
function check_file_update_jar($file,$dir,$url,$time){
|
||||
global $replace_mode;
|
||||
if($replace_mode==true){
|
||||
$file=str_replace('?','/',$file);
|
||||
}
|
||||
header('Content-Disposition: attachment; filename="'.basename($file).'.jar"');
|
||||
$time=time()-@filemtime($file.'/index.jar');
|
||||
if($time<$time){//检查文件是否超出过期期限(1天,86400秒)
|
||||
echo file_get_contents($file.'/index.jar');
|
||||
}else{
|
||||
if(url_exists($url.'/'.str_replace($dir,'',$file))){//防止源无法访问而损坏文件
|
||||
if(file_get_contents($url.'/'.str_replace($dir,'',$file))==@file_get_contents($file.'/index.jar')){
|
||||
echo file_get_contents($file);
|
||||
}else{
|
||||
echo file_get_contents($url.'/'.str_replace($dir,'',$file));
|
||||
download_file($url.'/'.str_replace($dir,'',$file),$file.'/index.jar','');
|
||||
}
|
||||
}else{
|
||||
echo file_get_contents($file.'/index.jar');
|
||||
}
|
||||
}
|
||||
}
|
||||
function check_file_update_adv($file,$url,$check_url){
|
||||
global $replace_mode;
|
||||
if($replace_mode==true){
|
||||
$file=str_replace('?','/',$file);
|
||||
}
|
||||
header('Content-Disposition: attachment; filename="'.basename($file).'"');
|
||||
$time=time()-@filemtime($file);
|
||||
if($time<86400){//检查文件是否超出过期期限(1天,86400秒)
|
||||
echo file_get_contents($file);
|
||||
}else{
|
||||
if(url_exists($check_url)){//防止源无法访问而损坏文件
|
||||
if(file_get_contents($url)==@file_get_contents($file)){
|
||||
echo file_get_contents($file);
|
||||
}else{
|
||||
echo @file_get_contents($url);
|
||||
download_file($url,$file,'');
|
||||
}
|
||||
}else{
|
||||
echo file_get_contents($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(strstr($_GET['path'],'liteloader')!=False){//替换掉Literloader源中的特殊字符
|
||||
$replace_mode=true;
|
||||
}
|
||||
if(get_main_domain($_GET['path'])=='mojang'){//分配顶级域名尾
|
||||
$id=0;
|
||||
}elseif(get_main_domain($_GET['path'])=='fabricmc'){
|
||||
$id=1;
|
||||
}elseif(get_main_domain($_GET['path'])=='liteloader'){
|
||||
$id=2;
|
||||
}elseif(get_main_domain($_GET['path'])=='yushi'){
|
||||
$id=3;
|
||||
}elseif(get_main_domain($_GET['path'])=='minecraft'){
|
||||
$id=4;
|
||||
}
|
||||
if($_GET['error']!=""){
|
||||
echo '{"wikis":"https://gitee.com/ghink/gemcapi/wikis","code":'.$_GET['error'].',"server_time":'.time().',"server_id":'.$server_id.'}';
|
||||
}elseif($_GET['path']==""){
|
||||
echo '{"wikis":"https://gitee.com/ghink/gemcapi/wikis","code":200,"server_time":'.time().',"server_id":'.$server_id.'}';
|
||||
}else{
|
||||
if(is_file($_GET['path'])){
|
||||
//文件存在
|
||||
if(in_array($_GET['path'],$active)){//判断是否为需要保持最新的文件
|
||||
if(strstr($_GET['path'],'mojang/')!=False){//目录分组
|
||||
if(strstr($_GET['path'],'mojang/launchermeta/')!=False){
|
||||
check_file_update('mojang/launchermeta/mc/game/version_manifest.json',get_main_domain($_GET['path']).'/'.get_sub_domain($_GET['path']).'/','http://launchermeta.mojang.com',86400);
|
||||
}
|
||||
}elseif(strstr($_GET['path'],'forge/')!=False){//目录分组
|
||||
if(strstr($_GET['path'],'forge/last')!=False){
|
||||
check_file_update_adv('forge/last/index.json','https://download.mcbbs.net/forge/last','https://download.mcbbs.net/maven/net/minecraftforge/forge/1.7.10-10.13.0.1151/forge-1.7.10-10.13.0.1151-installer.jar');
|
||||
}
|
||||
}elseif(strstr($_GET['path'],'optifine/')!=False){//目录分组
|
||||
if(strstr($_GET['path'],'optifine/versionlist')!=False){
|
||||
check_file_update_adv('optifine/versionlist/index.json','https://download.mcbbs.net/optifine/versionlist','https://download.mcbbs.net/maven/net/minecraftforge/forge/1.7.10-10.13.0.1151/forge-1.7.10-10.13.0.1151-installer.jar');
|
||||
}
|
||||
}elseif(strstr($_GET['path'],'liteloader/')!=False){//目录分组
|
||||
if(strstr($_GET['path'],'liteloader/dl/versions')!=False){
|
||||
check_file_update_adv('liteloader/dl/versions/versions.json','http://dl.liteloader.com/versions/versions.json','http://dl.liteloader.com/versions/versions.json');
|
||||
}
|
||||
}
|
||||
}else{//无需频繁更新的文件
|
||||
if(@file_get_contents(get_online_url($_GET['path'],$id)=="")){
|
||||
check_file_update($_GET['path'],get_main_domain($_GET['path']).'/'.get_sub_domain($_GET['path']).'/',get_online_domain($_GET['path'],$id),2592000);
|
||||
}else{
|
||||
check_file_update_json($_GET['path'],get_main_domain($_GET['path']).'/'.get_sub_domain($_GET['path']).'/',get_online_domain($_GET['path'],$id),2592000);
|
||||
}
|
||||
}
|
||||
}elseif(is_dir($_GET['path'])){
|
||||
//目录存在
|
||||
if(strstr($_GET['path'],'forge/minecraft')!=False){//特殊目录返回
|
||||
check_file_update_adv('forge/minecraft/minecraft.json','https://download.mcbbs.net/forge/minecraft','https://download.mcbbs.net/maven/net/minecraftforge/forge/1.7.10-10.13.0.1151/forge-1.7.10-10.13.0.1151-installer.jar');
|
||||
}elseif(strstr($_GET['path'],'yushi/authlib-injector')!=False){
|
||||
check_file_update_adv('yushi/authlib-injector/list.json','https://authlib-injector.yushi.moe','https://download.mcbbs.net/maven/net/minecraftforge/forge/1.7.10-10.13.0.1151/forge-1.7.10-10.13.0.1151-installer.jar');
|
||||
//此处暂时使用bmclapi源检测文件欺骗检测authlib-injector,原因见底部注释
|
||||
}elseif(is_file($_GET['path'].'/index.json')){
|
||||
check_file_update_json($_GET['path'],get_main_domain($_GET['path']).'/'.get_sub_domain($_GET['path']).'/',get_online_domain($_GET['path'],$id),86400);
|
||||
}elseif(is_file($_GET['path'].'/index.jar')){
|
||||
check_file_update_jar($_GET['path'],get_main_domain($_GET['path']).'/'.get_sub_domain($_GET['path']).'/',get_online_domain($_GET['path'],$id),31536000);
|
||||
}else{
|
||||
header('Content-Disposition: attachment; filename="'.basename($_GET['path']).'"');
|
||||
echo file_get_contents($_GET['path']);
|
||||
}
|
||||
}else{
|
||||
//目录或文件不存在
|
||||
if(strstr($_GET['path'],'forge/')!=False){//特殊Forge,采用二级源 BMCLAPI
|
||||
if(url_exists('https://download.mcbbs.net/maven/net/minecraftforge/forge/1.7.10-10.13.0.1151/forge-1.7.10-10.13.0.1151-installer.jar')){
|
||||
if(strstr($_GET['path'],'forge/minecraft')!=False){//forge/minecraft目录特殊同步
|
||||
if($_GET['path']=='forge/minecraft'){
|
||||
check_file_update_adv('forge/minecraft/minecraft.json','https://download.mcbbs.net/forge/minecraft','https://download.mcbbs.net/maven/net/minecraftforge/forge/1.7.10-10.13.0.1151/forge-1.7.10-10.13.0.1151-installer.jar');
|
||||
}else{
|
||||
check_file_update_adv($_GET['path'].'/index.json','https://download.mcbbs.net/'.$_GET['path'],'https://download.mcbbs.net/maven/net/minecraftforge/forge/1.7.10-10.13.0.1151/forge-1.7.10-10.13.0.1151-installer.jar');
|
||||
}
|
||||
}elseif(strstr($_GET['path'],'forge/last')!=False){
|
||||
check_file_update_adv($_GET['path'].'/index.json','https://download.mcbbs.net/'.$_GET['path'],'https://download.mcbbs.net/maven/net/minecraftforge/forge/1.7.10-10.13.0.1151/forge-1.7.10-10.13.0.1151-installer.jar');
|
||||
}elseif(strstr($_GET['path'],'forge/download')!=False){//forge/download目录特殊同步
|
||||
check_file_update_adv($_GET['path'].'/index.jar','https://download.mcbbs.net/'.$_GET['path'],'https://download.mcbbs.net/maven/net/minecraftforge/forge/1.7.10-10.13.0.1151/forge-1.7.10-10.13.0.1151-installer.jar');
|
||||
}else{
|
||||
download_file('https://download.mcbbs.net/'.$_GET['path'],$_GET['path'],'');
|
||||
header('Content-Disposition: attachment; filename="'.basename($_GET['path']).'"');
|
||||
echo file_get_contents($_GET['path']);
|
||||
}
|
||||
}else{
|
||||
echo '{"wikis":"https://gitee.com/ghink/gemcapi/wikis","code":404,"server_time":'.time().'}';
|
||||
header('HTTP/1.1 404 Not Found');
|
||||
}
|
||||
}elseif(strstr($_GET['path'],'optifine/')!=False){//Optifine同步
|
||||
if($_GET['path']=='optifine'){
|
||||
echo '{"wikis":"https://gitee.com/ghink/gemcapi/wikis","code":404,"server_time":'.time().'}';
|
||||
header('HTTP/1.1 404 Not Found');
|
||||
}elseif(strstr($_GET['path'],'optifine/versionlist')!=False){
|
||||
check_file_update_adv(str_replace('?','/',$_GET['path']).'/index.json','https://download.mcbbs.net/'.$_GET['path'],'https://download.mcbbs.net/maven/net/minecraftforge/forge/1.7.10-10.13.0.1151/forge-1.7.10-10.13.0.1151-installer.jar');
|
||||
}else{
|
||||
if(@file_get_contents(get_online_url($_GET['path'],$id)=="")){
|
||||
check_file_update_adv($_GET['path'].'/index.jar','https://download.mcbbs.net/'.$_GET['path'],'https://download.mcbbs.net/maven/net/minecraftforge/forge/1.7.10-10.13.0.1151/forge-1.7.10-10.13.0.1151-installer.jar');
|
||||
}else{
|
||||
if(strstr($_GET['path'],'HD_U')!=False){
|
||||
check_file_update_adv($_GET['path'].'/index.jar','https://download.mcbbs.net/'.$_GET['path'],'https://download.mcbbs.net/maven/net/minecraftforge/forge/1.7.10-10.13.0.1151/forge-1.7.10-10.13.0.1151-installer.jar');
|
||||
}else{
|
||||
check_file_update_adv($_GET['path'].'/index.json','https://download.mcbbs.net/'.$_GET['path'],'https://download.mcbbs.net/maven/net/minecraftforge/forge/1.7.10-10.13.0.1151/forge-1.7.10-10.13.0.1151-installer.jar');
|
||||
}
|
||||
}
|
||||
}
|
||||
}elseif(strstr($_GET['path'],'liteloader/')!=False){//Liteloader同步
|
||||
if(strstr($_GET['path'],'liteloader/list')!=False){
|
||||
check_file_update_adv(str_replace('?','/',$_GET['path']).'/index.json','https://download.mcbbs.net/'.$_GET['path'],'https://download.mcbbs.net/maven/net/minecraftforge/forge/1.7.10-10.13.0.1151/forge-1.7.10-10.13.0.1151-installer.jar');
|
||||
}elseif(strstr($_GET['path'],'liteloader/download')!=False){
|
||||
check_file_update_adv(str_replace('?','/',$_GET['path']).'/index.jar','https://download.mcbbs.net/'.$_GET['path'],'https://download.mcbbs.net/maven/net/minecraftforge/forge/1.7.10-10.13.0.1151/forge-1.7.10-10.13.0.1151-installer.jar');
|
||||
}else{
|
||||
check_file_update_adv($_GET['path'],get_online_url($_GET['path'],$id),'http://dl.liteloader.com/versions/versions.json');
|
||||
}
|
||||
}else{
|
||||
if(url_exists(get_online_url($_GET['path'],$id))){
|
||||
if(@file_get_contents(get_online_url($_GET['path'],$id)=="")){
|
||||
download_file(get_online_url($_GET['path'],$id),$_GET['path'],'');
|
||||
header('Content-Disposition: attachment; filename="'.basename($_GET['path']).'"');
|
||||
echo file_get_contents($_GET['path']);
|
||||
}else{
|
||||
download_file(get_online_url($_GET['path'],$id),$_GET['path'].'/index.json','');
|
||||
header('Content-Disposition: attachment; filename="'.basename($_GET['path']).'"');
|
||||
echo file_get_contents($_GET['path'].'/index.json');
|
||||
}
|
||||
}elseif(get_main_domain($_GET['path'])=='yushi'){
|
||||
//暂不明确为何authlib-injector的服务器即使存活文件存在也会被判定为不存在
|
||||
download_file(get_online_url($_GET['path'],$id),$_GET['path'].'/list.json','');
|
||||
header('Content-Disposition: attachment; filename="'.basename($_GET['path']).'"');
|
||||
echo file_get_contents($_GET['path'].'/list.json');
|
||||
}elseif(get_main_domain($_GET['path'])=='minecraft'){
|
||||
//暂不明确为何Minecraft的服务器即使存活文件存在也会被判定为不存在
|
||||
download_file(get_online_url($_GET['path'],$id),$_GET['path'].'/index.jar','');
|
||||
header('Content-Disposition: attachment; filename="'.basename($_GET['path']).'"');
|
||||
echo file_get_contents($_GET['path'].'/index.jar');
|
||||
}else{
|
||||
echo '{"wikis":"https://gitee.com/ghink/gemcapi/wikis","code":404,"server_time":'.time().',"server_id":'.$server_id.'}';
|
||||
header('HTTP/1.1 404 Not Found');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
38
test.py
Normal file
38
test.py
Normal file
@ -0,0 +1,38 @@
|
||||
import os,requests,json,time,sys,argparse,psutil
|
||||
Log=""
|
||||
UA={'User-Agent':'GeMCAPI/6.0.0 (GeMC API Sync 6.0.0;Release)'}
|
||||
parser=argparse.ArgumentParser()
|
||||
parser.add_argument("--url", help="The online url of the file which need to download.")
|
||||
parser.add_argument("--file", help="The file path of the file which need to download.")
|
||||
parser.add_argument("--other", help="Other parameter which help some special file to download correctly.")
|
||||
parser=parser.parse_args()
|
||||
proxies={'http':'http://127.0.0.1:4780'}#Proxy Setting
|
||||
def log(log_type,logvar):
|
||||
global Log
|
||||
if(log_type=="info"):
|
||||
log_type="INFO"
|
||||
elif(log_type=="warn"):
|
||||
log_type="WARN"
|
||||
elif(log_type=="error"):
|
||||
log_type="ERROR"
|
||||
Log=Log + '\n' + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[' + log_type + ']' + logvar
|
||||
def download(url, dirpath):
|
||||
global Log
|
||||
global UA
|
||||
log("info",'We are downloading the file ' + dirpath + '.')
|
||||
try:
|
||||
download=requests.get(url, headers=UA, proxies=proxies)
|
||||
with open(dirpath,"wb") as code:
|
||||
code.write(download.content)
|
||||
except:
|
||||
log("error",'There has a error in task while downloading the file ' + dirpath + '.')
|
||||
else:
|
||||
log("info",'The file ' + dirpath + ' has been downloaded successfully.')
|
||||
def make_dir_exist(dirpath):
|
||||
global Log
|
||||
if os.path.exists(dirpath):
|
||||
log("info",'The dir ' + dirpath + ' has already existed.Nothing to do.')
|
||||
else:
|
||||
log("info",'The dir ' + dirpath + ' does not exist.We will create one.')
|
||||
os.makedirs(dirpath)
|
||||
print(round(float(time.time())))
|
Reference in New Issue
Block a user