“6.0.0”

This commit is contained in:
Bigsk 2020-08-25 22:40:22 +08:00
parent 0e0cf3c96f
commit 8036b261ad
25 changed files with 2689 additions and 1168 deletions

View File

@ -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()

View 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}]

File diff suppressed because it is too large Load Diff

347
index.php
View File

@ -1,262 +1,195 @@
<?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");
}
}
}
}
}

View 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.

View 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.

View 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.

View 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.

View 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.

View 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.

View File

@ -1,274 +1,274 @@
import requests
import os
import time
import json
print('[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting the synchronizing system.')
#------------------------------------------------------------------------#
print('------------------------------------------------------------------------')
#Part Of All Kinds Of Global Variables
print('[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting to specify global variables.')
SystemName='GeMC API Synchronize Tool'
SavePath='gemcapi/'
Version='2.3.0'
UserAgent={'User-Agent':'GeMCAPI/2.3.0 (GeMC Sync Release 2.3.0;Release)'}
Proxies = {
"http": "http://127.0.0.1:10809", #HTTP Proxies Setting
#"https": "", #HTTPS Proxies Setting
}
Log='[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting the synchronizing system.\n' + '------------------------------------------------------------------------\n' + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting to specify global variables.\n' + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Specifying global variables successful.\n'
print('[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Specifying global variables successful.')
#------------------------------------------------------------------------#
print('------------------------------------------------------------------------')
Log=Log + '------------------------------------------------------------------------' + '\n'
#The Part Of All Kinds Of Modules.
print('[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting to load all kinds of modules.')
Log=Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting to load all kinds of modules.' + '\n'
#Module Which Be Used To Print And Save Logs.
def log(logvar):
global Log
print('[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + logvar)
Log=Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + logvar + '\n'
#Module Which Be Used To Synchronize Single File.
def synchronize(url, filepath):
global Log
global UserAgent
log('[INFO]:The ' + SystemName + ' is synchronizing the file ' + SavePath + filepath + '.')
try:
#synchronize=requests.get(url, headers=UserAgent)#Without Proxies
synchronize=requests.get(url, headers=UserAgent,proxies=Proxies)
with open(SavePath + filepath,"wb") as code:
code.write(synchronize.content)
except:
log('[ERROR]:There has a error in task of synchronizing the file ' + SavePath + filepath + '.')
else:
log('[INFO]:The file ' + SavePath + filepath + ' has been synchronized successfully.')
#Module Which Be Used To Determine Whether The Dir Exists.
def make_sure_dir_exists(dirpath):
global Log
if os.path.exists(SavePath + dirpath):
log('[INFO]:The dir ' + SavePath + dirpath + ' has already existed.Nothing to do.')
else:
log('[INFO]:The dir ' + SavePath + dirpath + ' does not exist.The ' + SystemName + ' will create one.')
os.makedirs(SavePath + dirpath)
log('[INFO]:Loading all kinds of modules successfully.')
#------------------------------------------------------------------------#
print('------------------------------------------------------------------------')
Log=Log + '------------------------------------------------------------------------' + '\n'
#Save JSON In Global Variables
log('[INFO]:Starting to get the json of MC versions list.')
Log=Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting to get the json of MC versions list.' + '\n'
#Save MC Versions List Json In Global Variables
mcversionsjson=requests.get(url='http://launchermeta.mojang.com/mc/game/version_manifest.json')
log('[INFO]:Get json of MC versions successfully.')
Log=Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Get json of MC versions successfully.' + '\n'
#------------------------------------------------------------------------#
print('------------------------------------------------------------------------')
Log=Log + '------------------------------------------------------------------------' + '\n'
#The Part of Determining Whether The Dir Exists.
#Determining Whether The Log Dir Exists.
log('[INFO]:Starting to determine whether the log dir exists.')
dirpath='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.The ' + SystemName + ' will create one.')
os.makedirs(dirpath)
log('[INFO]:Determining whether the log dir exists successfully.')
log('[INFO]:Starting to determine whether all of dirs exists.')
#Determining Whether The MC Versions Dir Exists.
log('[INFO]:Starting to determine whether the MC versions dir exists.')
make_sure_dir_exists('mojang/launchermeta/mc/game')
log('[INFO]:Determining whether the MC versions dir exists successfully.')
#Determining Whether The Liteloader Versions Dir Exists.
log('[INFO]:Starting to determine whether the Liteloader versions dir exists.')
make_sure_dir_exists('liteloader/dl/versions')
log('[INFO]:Determining whether the Liteloader versions dir exists successfully.')
log('[INFO]:Determining whether all of dirs exists successfully.')
#------------------------------------------------------------------------#
print('------------------------------------------------------------------------')
Log=Log + '------------------------------------------------------------------------' + '\n'
#The Part of Synchronizing Single Files.
log('[INFO]:Starting to synchronize single files.')
#Synchronizing The Minecraft Versions List File.
log('[INFO]:Starting to synchronize MC versions files.')
synchronize('http://launchermeta.mojang.com/mc/game/version_manifest.json', 'mojang/launchermeta/mc/game/version_manifest.json')
log('[INFO]:Synchronizing MC versions files successfully.')
#Synchronizing The Liteloader Versions List File.
log('[INFO]:Starting to synchronize Liteloader versions files.')
synchronize('http://dl.liteloader.com/versions/versions.json', 'liteloader/dl/versions/versions.json')
log('[INFO]:Synchronizing Liteloader versions files successfully.')
#------------------------------------------------------------------------#
print('------------------------------------------------------------------------')
Log=Log + '------------------------------------------------------------------------' + '\n'
#MC Versions Synchronizing Part.
log('[INFO]:Starting synchronize all of MC versions.')
log('[INFO]:Starting to count how many MC versions in total.')
#Count How Many MC Versions in total.
mcversionsjsontext=mcversionsjson.text
mcversionsnumber=mcversionsjsontext.count('"url":')
log('[INFO]:There has ' + str(mcversionsnumber) + ' MC versions in total .')
log('[INFO]:Counting how many MC versions in total successfully.')
#Starting To Synchronize More Files And Dirs.
#Auto Synchronize Files And Dirs on https://launchermeta.mojang.com/.
log('[INFO]:Starting to synchronize files and dirs on https://launchermeta.mojang.com/.')
whiletimes=0#Set Var whiletimes To Avoid Error.
while(whiletimes < mcversionsnumber):
#Count While Times.
whiletimes=whiletimes + 1
#Read Json Of MC Versions List.
downloadurlload=json.loads(mcversionsjsontext)
whiletimesload=whiletimes - 1
onlineurl=downloadurlload['versions'][whiletimesload]['url']
onlineurlwithouthttps=onlineurl.replace('https://', 'http://')#Avoid Https Connetion Errors
fileurl='mojang/launchermeta/' + onlineurl.replace('https://launchermeta.mojang.com/','')
filetosync=fileurl[::-1].split('/', 1)[-1][::-1]
#Synchronize.
make_sure_dir_exists(filetosync)
synchronize(onlineurlwithouthttps, fileurl)
log('[INFO]:Synchronizing files and dirs on https://launchermeta.mojang.com/ successfully.')
#Auto Synchronize Files And Dirs on https://libraries.minecraft.net/.
log('[INFO]:Starting to synchronize files and dirs on https://libraries.minecraft.net/.')
#Part Of 'downloads'.
whiletimes=0#Set Var whiletimes To Avoid Error.
while(whiletimes < mcversionsnumber):
#Count While Times.
whiletimes=whiletimes + 1
#Read Json Of MC Versions List.
downloadurlload=json.loads(mcversionsjsontext)
whiletimesload=whiletimes - 1
onlineurl=downloadurlload['versions'][whiletimesload]['url']
onlineurlwithouthttps=onlineurl.replace('https://', 'http://')#Avoid Https Connetion Errors
log('[INFO]:Starting to get the json of MC libraries ' + onlineurl +' list.')
#Save MC Libraries Json In Global Variables
try:#Avoid Http/Https Connection Errors Making Whole Synchronize Stop.
mclibrariesjson=requests.get(url=onlineurlwithouthttps)
except:
log('[ERROR]:There has a error in task of getting json of MC libraries ' + onlineurl + '.')
else:
log('[INFO]:Get json of MC libraries ' + onlineurl + ' successfully.')
#Read Json Of MC Libraries.
mclibrariesload=json.loads(mclibrariesjson.text)
#Synchronize Files In "downloads".
log('[INFO]:Starting to synchronize files in ”downloads".')
try:#Avoid Http/Https Connection Errors Or Synchronize Module Download Failed Errors Making Whole Synchronize Stop.
onlineurl2=mclibrariesload['downloads']['client']['url']
fileurl2='mojang/launcher/' + onlineurl2.replace('https://launcher.mojang.com/','')
filetosync2=fileurl2[::-1].split('/', 1)[-1][::-1]
make_sure_dir_exists(filetosync2)
synchronize(onlineurl2, fileurl2)
onlineurl2=mclibrariesload['downloads']['client_mappings']['url']
fileurl2='mojang/launcher/' + onlineurl2.replace('https://launcher.mojang.com/','')
filetosync2=fileurl2[::-1].split('/', 1)[-1][::-1]
make_sure_dir_exists(filetosync2)
synchronize(onlineurl2, fileurl2)
onlineurl2=mclibrariesload['downloads']['server']['url']
fileurl2='mojang/launcher/' + onlineurl2.replace('https://launcher.mojang.com/','')
filetosync2=fileurl2[::-1].split('/', 1)[-1][::-1]
make_sure_dir_exists(filetosync2)
synchronize(onlineurl2, fileurl2)
onlineurl2=mclibrariesload['downloads']['server_mappings']['url']
fileurl2='mojang/launcher/' + onlineurl2.replace('https://launcher.mojang.com/','')
filetosync2=fileurl2[::-1].split('/', 1)[-1][::-1]
make_sure_dir_exists(filetosync2)
synchronize(onlineurl2, fileurl2)
#Synchronize Files In "loggin".
onlineurl2=mclibrariesload['loggin']['client']['file']['url']
fileurl2='mojang/launcher/' + onlineurl2.replace('https://launcher.mojang.com/','')
filetosync2=fileurl2[::-1].split('/', 1)[-1][::-1]
make_sure_dir_exists(filetosync2)
synchronize(onlineurl2, fileurl2)
except:
log('[ERROR]:There has a error in task of synchronizing files in "downloads".')
else:
log('[INFO]:Synchronizing files in "downloads" successfully.')
log('[INFO]:Starting to count how many MC libraries files in ' + onlineurl + ' in total.')
#Count How Many MC Libraries Files in total.
mclibrariesjsontext=mclibrariesjson.text
mclibrariesnumber=mclibrariesjsontext.count('"url":') - 6
log('[INFO]:There has ' + str(mclibrariesnumber) + ' MC libraries files in ' + onlineurl + ' in total.')
log('[INFO]:Counting how many MC libraries files in ' + onlineurl + ' in total successfully.')
whiletimes3=0#Set Var whiletimes To Avoid Error.
while(whiletimes3 < mclibrariesnumber):
#Count While Times.
whiletimes3=whiletimes3 + 1
whiletimesload3=whiletimes3 - 1
#Synchronize Files In "libraries".
log('[INFO]:Starting to synchronize Files In "libraries".')
try:#Avoid Http/Https Connection Errors Or Synchronize Module Download Failed Errors Making Whole Synchronize Stop.
#Synchronize Files In "libraries/.../downloads/artifact".
onlineurl3=mclibrariesload['libraries'][whiletimesload3]['downloads']['artifact']['url']
onlineurlwithouthttps3=onlineurl3.replace('https://', 'http://')
fileurl3='mojang/libraries/' + onlineurl3.replace('https://libraries.minecraft.net/','')
filetosync3=fileurl3[::-1].split('/', 1)[-1][::-1]
make_sure_dir_exists(filetosync3)
synchronize(onlineurlwithouthttps3, fileurl3)
#Synchronize Files In "libraries/.../downloads/classifiers/javadoc".
onlineurl3=mclibrariesload['libraries'][whiletimesload3]['downloads']['classifiers']['javadoc']['url']
onlineurlwithouthttps3=onlineurl3.replace('https://', 'http://')
fileurl3='mojang/libraries/' + onlineurl3.replace('https://libraries.minecraft.net/','')
filetosync3=fileurl3[::-1].split('/', 1)[-1][::-1]
make_sure_dir_exists(filetosync3)
synchronize(onlineurlwithouthttps3, fileurl3)
#Synchronize Files In "libraries/.../downloads/classifiers/natives-linux".
onlineurl3=mclibrariesload['libraries'][whiletimesload3]['downloads']['classifiers']['natives-linux']['url']
onlineurlwithouthttps3=onlineurl3.replace('https://', 'http://')
fileurl3='mojang/libraries/' + onlineurl3.replace('https://libraries.minecraft.net/','')
filetosync3=fileurl3[::-1].split('/', 1)[-1][::-1]
make_sure_dir_exists(filetosync3)
synchronize(onlineurlwithouthttps3, fileurl3)
#Synchronize Files In "libraries/.../downloads/classifiers/natives-macos".
onlineurl3=mclibrariesload['libraries'][whiletimesload3]['downloads']['classifiers']['natives-macos']['url']
onlineurlwithouthttps3=onlineurl3.replace('https://', 'http://')
fileurl3='mojang/libraries/' + onlineurl3.replace('https://libraries.minecraft.net/','')
filetosync3=fileurl3[::-1].split('/', 1)[-1][::-1]
make_sure_dir_exists(filetosync3)
synchronize(onlineurlwithouthttps3, fileurl3)
#Synchronize Files In "libraries/.../downloads/classifiers/natives-windows".
onlineurl3=mclibrariesload['libraries'][whiletimesload3]['downloads']['classifiers']['natives-windows']['url']
onlineurlwithouthttps3=onlineurl3.replace('https://', 'http://')
fileurl3='mojang/libraries/' + onlineurl3.replace('https://libraries.minecraft.net/','')
filetosync3=fileurl3[::-1].split('/', 1)[-1][::-1]
make_sure_dir_exists(filetosync3)
synchronize(onlineurlwithouthttps3, fileurl3)
#Synchronize Files In "libraries/.../downloads/artifact/classifiers/sources".
onlineurl3=mclibrariesload['libraries'][whiletimesload3]['downloads']['classifiers']['sources']['url']
onlineurlwithouthttps3=onlineurl3.replace('https://', 'http://')
fileurl3='mojang/libraries/' + onlineurl3.replace('https://libraries.minecraft.net/','')
filetosync3=fileurl3[::-1].split('/', 1)[-1][::-1]
make_sure_dir_exists(filetosync3)
synchronize(onlineurlwithouthttps3, fileurl3)
except:
log('[ERROR]:There has a error in task of synchronizing files in ”libraries".')
else:
log('[INFO]:Synchronizing files in "libraries" successfully.')
log('[INFO]:Synchronizing files and dirs on https://libraries.minecraft.net/ successfully.')
#------------------------------------------------------------------------#
print('------------------------------------------------------------------------')
Log=Log + '------------------------------------------------------------------------' + '\n'
#Starting To Save Logs.
log('[INFO]:Starting to save logs.')
logwrite=open('log/' + str(time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime()) + '.txt'),mode='w')
logwrite.write(Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Save logs successfully.' + '\n' + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:All tasks of synchronizing have done successfully.')
print('[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Save logs successfully.' + '\n' + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:All tasks of synchronizing have done successfully.')
logwrite.close()
import requests
import os
import time
import json
print('[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting the synchronizing system.')
#------------------------------------------------------------------------#
print('------------------------------------------------------------------------')
#Part Of All Kinds Of Global Variables
print('[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting to specify global variables.')
SystemName='GeMC API Synchronize Tool'
SavePath='gemcapi/'
Version='2.3.0'
UserAgent={'User-Agent':'GeMCAPI/2.3.0 (GeMC Sync Release 2.3.0;Release)'}
Proxies = {
"http": "http://127.0.0.1:10809", #HTTP Proxies Setting
#"https": "", #HTTPS Proxies Setting
}
Log='[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting the synchronizing system.\n' + '------------------------------------------------------------------------\n' + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting to specify global variables.\n' + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Specifying global variables successful.\n'
print('[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Specifying global variables successful.')
#------------------------------------------------------------------------#
print('------------------------------------------------------------------------')
Log=Log + '------------------------------------------------------------------------' + '\n'
#The Part Of All Kinds Of Modules.
print('[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting to load all kinds of modules.')
Log=Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting to load all kinds of modules.' + '\n'
#Module Which Be Used To Print And Save Logs.
def log(logvar):
global Log
print('[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + logvar)
Log=Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + logvar + '\n'
#Module Which Be Used To Synchronize Single File.
def synchronize(url, filepath):
global Log
global UserAgent
log('[INFO]:The ' + SystemName + ' is synchronizing the file ' + SavePath + filepath + '.')
try:
#synchronize=requests.get(url, headers=UserAgent)#Without Proxies
synchronize=requests.get(url, headers=UserAgent,proxies=Proxies)
with open(SavePath + filepath,"wb") as code:
code.write(synchronize.content)
except:
log('[ERROR]:There has a error in task of synchronizing the file ' + SavePath + filepath + '.')
else:
log('[INFO]:The file ' + SavePath + filepath + ' has been synchronized successfully.')
#Module Which Be Used To Determine Whether The Dir Exists.
def make_sure_dir_exists(dirpath):
global Log
if os.path.exists(SavePath + dirpath):
log('[INFO]:The dir ' + SavePath + dirpath + ' has already existed.Nothing to do.')
else:
log('[INFO]:The dir ' + SavePath + dirpath + ' does not exist.The ' + SystemName + ' will create one.')
os.makedirs(SavePath + dirpath)
log('[INFO]:Loading all kinds of modules successfully.')
#------------------------------------------------------------------------#
print('------------------------------------------------------------------------')
Log=Log + '------------------------------------------------------------------------' + '\n'
#Save JSON In Global Variables
log('[INFO]:Starting to get the json of MC versions list.')
Log=Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting to get the json of MC versions list.' + '\n'
#Save MC Versions List Json In Global Variables
mcversionsjson=requests.get(url='http://launchermeta.mojang.com/mc/game/version_manifest.json')
log('[INFO]:Get json of MC versions successfully.')
Log=Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Get json of MC versions successfully.' + '\n'
#------------------------------------------------------------------------#
print('------------------------------------------------------------------------')
Log=Log + '------------------------------------------------------------------------' + '\n'
#The Part of Determining Whether The Dir Exists.
#Determining Whether The Log Dir Exists.
log('[INFO]:Starting to determine whether the log dir exists.')
dirpath='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.The ' + SystemName + ' will create one.')
os.makedirs(dirpath)
log('[INFO]:Determining whether the log dir exists successfully.')
log('[INFO]:Starting to determine whether all of dirs exists.')
#Determining Whether The MC Versions Dir Exists.
log('[INFO]:Starting to determine whether the MC versions dir exists.')
make_sure_dir_exists('mojang/launchermeta/mc/game')
log('[INFO]:Determining whether the MC versions dir exists successfully.')
#Determining Whether The Liteloader Versions Dir Exists.
log('[INFO]:Starting to determine whether the Liteloader versions dir exists.')
make_sure_dir_exists('liteloader/dl/versions')
log('[INFO]:Determining whether the Liteloader versions dir exists successfully.')
log('[INFO]:Determining whether all of dirs exists successfully.')
#------------------------------------------------------------------------#
print('------------------------------------------------------------------------')
Log=Log + '------------------------------------------------------------------------' + '\n'
#The Part of Synchronizing Single Files.
log('[INFO]:Starting to synchronize single files.')
#Synchronizing The Minecraft Versions List File.
log('[INFO]:Starting to synchronize MC versions files.')
synchronize('http://launchermeta.mojang.com/mc/game/version_manifest.json', 'mojang/launchermeta/mc/game/version_manifest.json')
log('[INFO]:Synchronizing MC versions files successfully.')
#Synchronizing The Liteloader Versions List File.
log('[INFO]:Starting to synchronize Liteloader versions files.')
synchronize('http://dl.liteloader.com/versions/versions.json', 'liteloader/dl/versions/versions.json')
log('[INFO]:Synchronizing Liteloader versions files successfully.')
#------------------------------------------------------------------------#
print('------------------------------------------------------------------------')
Log=Log + '------------------------------------------------------------------------' + '\n'
#MC Versions Synchronizing Part.
log('[INFO]:Starting synchronize all of MC versions.')
log('[INFO]:Starting to count how many MC versions in total.')
#Count How Many MC Versions in total.
mcversionsjsontext=mcversionsjson.text
mcversionsnumber=mcversionsjsontext.count('"url":')
log('[INFO]:There has ' + str(mcversionsnumber) + ' MC versions in total .')
log('[INFO]:Counting how many MC versions in total successfully.')
#Starting To Synchronize More Files And Dirs.
#Auto Synchronize Files And Dirs on https://launchermeta.mojang.com/.
log('[INFO]:Starting to synchronize files and dirs on https://launchermeta.mojang.com/.')
whiletimes=0#Set Var whiletimes To Avoid Error.
while(whiletimes < mcversionsnumber):
#Count While Times.
whiletimes=whiletimes + 1
#Read Json Of MC Versions List.
downloadurlload=json.loads(mcversionsjsontext)
whiletimesload=whiletimes - 1
onlineurl=downloadurlload['versions'][whiletimesload]['url']
onlineurlwithouthttps=onlineurl.replace('https://', 'http://')#Avoid Https Connetion Errors
fileurl='mojang/launchermeta/' + onlineurl.replace('https://launchermeta.mojang.com/','')
filetosync=fileurl[::-1].split('/', 1)[-1][::-1]
#Synchronize.
make_sure_dir_exists(filetosync)
synchronize(onlineurlwithouthttps, fileurl)
log('[INFO]:Synchronizing files and dirs on https://launchermeta.mojang.com/ successfully.')
#Auto Synchronize Files And Dirs on https://libraries.minecraft.net/.
log('[INFO]:Starting to synchronize files and dirs on https://libraries.minecraft.net/.')
#Part Of 'downloads'.
whiletimes=0#Set Var whiletimes To Avoid Error.
while(whiletimes < mcversionsnumber):
#Count While Times.
whiletimes=whiletimes + 1
#Read Json Of MC Versions List.
downloadurlload=json.loads(mcversionsjsontext)
whiletimesload=whiletimes - 1
onlineurl=downloadurlload['versions'][whiletimesload]['url']
onlineurlwithouthttps=onlineurl.replace('https://', 'http://')#Avoid Https Connetion Errors
log('[INFO]:Starting to get the json of MC libraries ' + onlineurl +' list.')
#Save MC Libraries Json In Global Variables
try:#Avoid Http/Https Connection Errors Making Whole Synchronize Stop.
mclibrariesjson=requests.get(url=onlineurlwithouthttps)
except:
log('[ERROR]:There has a error in task of getting json of MC libraries ' + onlineurl + '.')
else:
log('[INFO]:Get json of MC libraries ' + onlineurl + ' successfully.')
#Read Json Of MC Libraries.
mclibrariesload=json.loads(mclibrariesjson.text)
#Synchronize Files In "downloads".
log('[INFO]:Starting to synchronize files in ”downloads".')
try:#Avoid Http/Https Connection Errors Or Synchronize Module Download Failed Errors Making Whole Synchronize Stop.
onlineurl2=mclibrariesload['downloads']['client']['url']
fileurl2='mojang/launcher/' + onlineurl2.replace('https://launcher.mojang.com/','')
filetosync2=fileurl2[::-1].split('/', 1)[-1][::-1]
make_sure_dir_exists(filetosync2)
synchronize(onlineurl2, fileurl2)
onlineurl2=mclibrariesload['downloads']['client_mappings']['url']
fileurl2='mojang/launcher/' + onlineurl2.replace('https://launcher.mojang.com/','')
filetosync2=fileurl2[::-1].split('/', 1)[-1][::-1]
make_sure_dir_exists(filetosync2)
synchronize(onlineurl2, fileurl2)
onlineurl2=mclibrariesload['downloads']['server']['url']
fileurl2='mojang/launcher/' + onlineurl2.replace('https://launcher.mojang.com/','')
filetosync2=fileurl2[::-1].split('/', 1)[-1][::-1]
make_sure_dir_exists(filetosync2)
synchronize(onlineurl2, fileurl2)
onlineurl2=mclibrariesload['downloads']['server_mappings']['url']
fileurl2='mojang/launcher/' + onlineurl2.replace('https://launcher.mojang.com/','')
filetosync2=fileurl2[::-1].split('/', 1)[-1][::-1]
make_sure_dir_exists(filetosync2)
synchronize(onlineurl2, fileurl2)
#Synchronize Files In "loggin".
onlineurl2=mclibrariesload['loggin']['client']['file']['url']
fileurl2='mojang/launcher/' + onlineurl2.replace('https://launcher.mojang.com/','')
filetosync2=fileurl2[::-1].split('/', 1)[-1][::-1]
make_sure_dir_exists(filetosync2)
synchronize(onlineurl2, fileurl2)
except:
log('[ERROR]:There has a error in task of synchronizing files in "downloads".')
else:
log('[INFO]:Synchronizing files in "downloads" successfully.')
log('[INFO]:Starting to count how many MC libraries files in ' + onlineurl + ' in total.')
#Count How Many MC Libraries Files in total.
mclibrariesjsontext=mclibrariesjson.text
mclibrariesnumber=mclibrariesjsontext.count('"url":') - 6
log('[INFO]:There has ' + str(mclibrariesnumber) + ' MC libraries files in ' + onlineurl + ' in total.')
log('[INFO]:Counting how many MC libraries files in ' + onlineurl + ' in total successfully.')
whiletimes3=0#Set Var whiletimes To Avoid Error.
while(whiletimes3 < mclibrariesnumber):
#Count While Times.
whiletimes3=whiletimes3 + 1
whiletimesload3=whiletimes3 - 1
#Synchronize Files In "libraries".
log('[INFO]:Starting to synchronize Files In "libraries".')
try:#Avoid Http/Https Connection Errors Or Synchronize Module Download Failed Errors Making Whole Synchronize Stop.
#Synchronize Files In "libraries/.../downloads/artifact".
onlineurl3=mclibrariesload['libraries'][whiletimesload3]['downloads']['artifact']['url']
onlineurlwithouthttps3=onlineurl3.replace('https://', 'http://')
fileurl3='mojang/libraries/' + onlineurl3.replace('https://libraries.minecraft.net/','')
filetosync3=fileurl3[::-1].split('/', 1)[-1][::-1]
make_sure_dir_exists(filetosync3)
synchronize(onlineurlwithouthttps3, fileurl3)
#Synchronize Files In "libraries/.../downloads/classifiers/javadoc".
onlineurl3=mclibrariesload['libraries'][whiletimesload3]['downloads']['classifiers']['javadoc']['url']
onlineurlwithouthttps3=onlineurl3.replace('https://', 'http://')
fileurl3='mojang/libraries/' + onlineurl3.replace('https://libraries.minecraft.net/','')
filetosync3=fileurl3[::-1].split('/', 1)[-1][::-1]
make_sure_dir_exists(filetosync3)
synchronize(onlineurlwithouthttps3, fileurl3)
#Synchronize Files In "libraries/.../downloads/classifiers/natives-linux".
onlineurl3=mclibrariesload['libraries'][whiletimesload3]['downloads']['classifiers']['natives-linux']['url']
onlineurlwithouthttps3=onlineurl3.replace('https://', 'http://')
fileurl3='mojang/libraries/' + onlineurl3.replace('https://libraries.minecraft.net/','')
filetosync3=fileurl3[::-1].split('/', 1)[-1][::-1]
make_sure_dir_exists(filetosync3)
synchronize(onlineurlwithouthttps3, fileurl3)
#Synchronize Files In "libraries/.../downloads/classifiers/natives-macos".
onlineurl3=mclibrariesload['libraries'][whiletimesload3]['downloads']['classifiers']['natives-macos']['url']
onlineurlwithouthttps3=onlineurl3.replace('https://', 'http://')
fileurl3='mojang/libraries/' + onlineurl3.replace('https://libraries.minecraft.net/','')
filetosync3=fileurl3[::-1].split('/', 1)[-1][::-1]
make_sure_dir_exists(filetosync3)
synchronize(onlineurlwithouthttps3, fileurl3)
#Synchronize Files In "libraries/.../downloads/classifiers/natives-windows".
onlineurl3=mclibrariesload['libraries'][whiletimesload3]['downloads']['classifiers']['natives-windows']['url']
onlineurlwithouthttps3=onlineurl3.replace('https://', 'http://')
fileurl3='mojang/libraries/' + onlineurl3.replace('https://libraries.minecraft.net/','')
filetosync3=fileurl3[::-1].split('/', 1)[-1][::-1]
make_sure_dir_exists(filetosync3)
synchronize(onlineurlwithouthttps3, fileurl3)
#Synchronize Files In "libraries/.../downloads/artifact/classifiers/sources".
onlineurl3=mclibrariesload['libraries'][whiletimesload3]['downloads']['classifiers']['sources']['url']
onlineurlwithouthttps3=onlineurl3.replace('https://', 'http://')
fileurl3='mojang/libraries/' + onlineurl3.replace('https://libraries.minecraft.net/','')
filetosync3=fileurl3[::-1].split('/', 1)[-1][::-1]
make_sure_dir_exists(filetosync3)
synchronize(onlineurlwithouthttps3, fileurl3)
except:
log('[ERROR]:There has a error in task of synchronizing files in ”libraries".')
else:
log('[INFO]:Synchronizing files in "libraries" successfully.')
log('[INFO]:Synchronizing files and dirs on https://libraries.minecraft.net/ successfully.')
#------------------------------------------------------------------------#
print('------------------------------------------------------------------------')
Log=Log + '------------------------------------------------------------------------' + '\n'
#Starting To Save Logs.
log('[INFO]:Starting to save logs.')
logwrite=open('log/' + str(time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime()) + '.txt'),mode='w')
logwrite.write(Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Save logs successfully.' + '\n' + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:All tasks of synchronizing have done successfully.')
print('[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Save logs successfully.' + '\n' + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:All tasks of synchronizing have done successfully.')
logwrite.close()

View File

@ -1,151 +1,151 @@
import requests
import os
import time
import json
print('[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting the synchronizing system.')
#------------------------------------------------------------------------#
print('------------------------------------------------------------------------')
#Part Of Load All Kinds Of Global Variables From Json File.
print('[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting to specify global variables from json file.')
configopen=open("synchronize/config.json", mode='r')
configjson = configopen.read()
configopen.close()
config = json.loads(configjson)
SystemName=config['systemname']
SavePath='synchronize/' + config['savepath']
Version=config['version']
UserAgent={'User-Agent':config['useragent']}
Log='[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting the synchronizing system.\n' + '------------------------------------------------------------------------\n' + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting to specify global variables.\n' + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Specifying global variables successful.\n'
print('[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Specifying global variables successful.')
#------------------------------------------------------------------------#
Log=Log + '------------------------------------------------------------------------' + '\n'
#The Part Of All Kinds Of Functions.
Log=Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting to load all kinds of functions.' + '\n'
#Function Which Be Used To Save Logs.
def log(logvar):
global Log
Log=Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + logvar + '\n'
#Function Which Be Used To Synchronize Single File.
def download(url, filepath):
global Log
global UserAgent
log('[INFO]:The ' + SystemName + ' is synchronizing the file ' + SavePath + filepath + '.')
try:
download=requests.get(url, headers=UserAgent)
with open(SavePath + filepath,"wb") as code:
code.write(download.content)
except:
log('[ERROR]:There has a error in task of synchronizing the file ' + SavePath + filepath + '.')
else:
log('[INFO]:The file ' + SavePath + filepath + ' has been synchronized successfully.')
#Function Which Be Used To Make Sure The Dir Exists.
def make_sure_dir_exists(dirpath):
global Log
if os.path.exists(SavePath + dirpath):
log('[INFO]:The dir ' + SavePath + dirpath + ' has already existed.Nothing to do.')
else:
log('[INFO]:The dir ' + SavePath + dirpath + ' does not exist.The ' + SystemName + ' will create one.')
os.makedirs(SavePath + dirpath)
#Function Which Be Used To Both Synchronize Single File And Make Sure The Dir Exists.
def sychronize(url, filepath):
global Log
global UserAgent
dirpath= filepath[::-1].split('/', 1)[-1][::-1]
if os.path.exists(SavePath + dirpath):
log('[INFO]:The dir ' + SavePath + dirpath + ' has already existed.Nothing to do.')
else:
log('[INFO]:The dir ' + SavePath + dirpath + ' does not exist.The ' + SystemName + ' will create one.')
os.makedirs(SavePath + dirpath)
log('[INFO]:The ' + SystemName + ' is synchronizing the file ' + SavePath + filepath + '.')
try:
download=requests.get(url, headers=UserAgent)
with open(SavePath + filepath,"wb") as code:
code.write(download.content)
except:
log('[ERROR]:There has a error in task of synchronizing the file ' + SavePath + filepath + '.')
else:
log('[INFO]:The file ' + SavePath + filepath + ' has been synchronized successfully.')
#Function Which Be Used To Get HTTP Site With Requests Avoid Error.
def httpget(url):
try:
return requests.get(url=url, headers=UserAgent).text
except:
return 'error'
log('[INFO]:Loading all kinds of functions successfully.')
#------------------------------------------------------------------------#
Log=Log + '------------------------------------------------------------------------' + '\n'
#Save JSON In Global Variables
log('[INFO]:Starting to get the json of MC versions list.')
Log=Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting to get the json of MC versions list.' + '\n'
#Save MC Versions List Json In Global Variables
mcversionsjson=requests.get(url='http://launchermeta.mojang.com/mc/game/version_manifest.json')
log('[INFO]:Get json of MC versions successfully.')
Log=Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Get json of MC versions successfully.' + '\n'
#------------------------------------------------------------------------#
print('------------------------------------------------------------------------')
Log=Log + '------------------------------------------------------------------------' + '\n'
#Make Sure The Log Dir Exists.
log('[INFO]:Starting to determine whether the log dir exists.')
dirpath='synchronize/' + config['logspath']
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.The ' + SystemName + ' will create one.')
os.makedirs(dirpath)
log('[INFO]:Make sure the log dir exists successfully.')
#------------------------------------------------------------------------#
print('------------------------------------------------------------------------')
Log=Log + '------------------------------------------------------------------------' + '\n'
#The Part of Synchronizing Single Important Files.
log('[INFO]:Starting to synchronize single files.')
#Synchronizing The Liteloader Versions List File.
log('[INFO]:Starting to synchronize Liteloader versions files.')
synchronize('http://dl.liteloader.com/versions/versions.json', 'liteloader/dl/versions/versions.json')
log('[INFO]:Synchronizing Liteloader versions files successfully.')
#------------------------------------------------------------------------#
print('------------------------------------------------------------------------')
Log=Log + '------------------------------------------------------------------------' + '\n'
log('[INFO]:Starting to synchronize more files.')
log('[WARN]:Attention!In the version new than 2.3.0,the synchronize tools will synchronize files in the background to improve the speed of synchronizing,that means you will not see the log output in the shell/cmd/powershell.If you want to see all logs and not care about the speed,you can download the old version on gitee,but we will not provide update for it.')
#MC Versions Synchronizing Part.
log('[INFO]:Starting synchronize all of MC versions.')
#Part 1.
log('[INFO]:Starting synchronize part 1.')
os.popen('python synchronize/part1.py','r')
#Part 2.
log('[INFO]:Starting synchronize part 2.')
os.popen('python synchronize/part2.py','r')
#Part 3.
log('[INFO]:Starting synchronize part 3.')
os.popen('python synchronize/part3.py','r')
#------------------------------------------------------------------------#
print('------------------------------------------------------------------------')
Log=Log + '------------------------------------------------------------------------' + '\n'
#Starting To Save Logs.
log('[INFO]:Starting to save logs.')
logwrite=open('synchronize/' + config['logspath'] + "main-" + str(time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime()) + '.txt'),mode='w')
logwrite.write(Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Save logs successfully.' + '\n' + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:All tasks of synchronizing have done successfully.')
print('[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Save logs successfully.' + '\n' + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:All tasks of synchronizing have done successfully.')
logwrite.close()
import requests
import os
import time
import json
print('[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting the synchronizing system.')
#------------------------------------------------------------------------#
print('------------------------------------------------------------------------')
#Part Of Load All Kinds Of Global Variables From Json File.
print('[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting to specify global variables from json file.')
configopen=open("synchronize/config.json", mode='r')
configjson = configopen.read()
configopen.close()
config = json.loads(configjson)
SystemName=config['systemname']
SavePath='synchronize/' + config['savepath']
Version=config['version']
UserAgent={'User-Agent':config['useragent']}
Log='[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting the synchronizing system.\n' + '------------------------------------------------------------------------\n' + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting to specify global variables.\n' + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Specifying global variables successful.\n'
print('[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Specifying global variables successful.')
#------------------------------------------------------------------------#
Log=Log + '------------------------------------------------------------------------' + '\n'
#The Part Of All Kinds Of Functions.
Log=Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting to load all kinds of functions.' + '\n'
#Function Which Be Used To Save Logs.
def log(logvar):
global Log
Log=Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + logvar + '\n'
#Function Which Be Used To Synchronize Single File.
def download(url, filepath):
global Log
global UserAgent
log('[INFO]:The ' + SystemName + ' is synchronizing the file ' + SavePath + filepath + '.')
try:
download=requests.get(url, headers=UserAgent)
with open(SavePath + filepath,"wb") as code:
code.write(download.content)
except:
log('[ERROR]:There has a error in task of synchronizing the file ' + SavePath + filepath + '.')
else:
log('[INFO]:The file ' + SavePath + filepath + ' has been synchronized successfully.')
#Function Which Be Used To Make Sure The Dir Exists.
def make_sure_dir_exists(dirpath):
global Log
if os.path.exists(SavePath + dirpath):
log('[INFO]:The dir ' + SavePath + dirpath + ' has already existed.Nothing to do.')
else:
log('[INFO]:The dir ' + SavePath + dirpath + ' does not exist.The ' + SystemName + ' will create one.')
os.makedirs(SavePath + dirpath)
#Function Which Be Used To Both Synchronize Single File And Make Sure The Dir Exists.
def sychronize(url, filepath):
global Log
global UserAgent
dirpath= filepath[::-1].split('/', 1)[-1][::-1]
if os.path.exists(SavePath + dirpath):
log('[INFO]:The dir ' + SavePath + dirpath + ' has already existed.Nothing to do.')
else:
log('[INFO]:The dir ' + SavePath + dirpath + ' does not exist.The ' + SystemName + ' will create one.')
os.makedirs(SavePath + dirpath)
log('[INFO]:The ' + SystemName + ' is synchronizing the file ' + SavePath + filepath + '.')
try:
download=requests.get(url, headers=UserAgent)
with open(SavePath + filepath,"wb") as code:
code.write(download.content)
except:
log('[ERROR]:There has a error in task of synchronizing the file ' + SavePath + filepath + '.')
else:
log('[INFO]:The file ' + SavePath + filepath + ' has been synchronized successfully.')
#Function Which Be Used To Get HTTP Site With Requests Avoid Error.
def httpget(url):
try:
return requests.get(url=url, headers=UserAgent).text
except:
return 'error'
log('[INFO]:Loading all kinds of functions successfully.')
#------------------------------------------------------------------------#
Log=Log + '------------------------------------------------------------------------' + '\n'
#Save JSON In Global Variables
log('[INFO]:Starting to get the json of MC versions list.')
Log=Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting to get the json of MC versions list.' + '\n'
#Save MC Versions List Json In Global Variables
mcversionsjson=requests.get(url='http://launchermeta.mojang.com/mc/game/version_manifest.json')
log('[INFO]:Get json of MC versions successfully.')
Log=Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Get json of MC versions successfully.' + '\n'
#------------------------------------------------------------------------#
print('------------------------------------------------------------------------')
Log=Log + '------------------------------------------------------------------------' + '\n'
#Make Sure The Log Dir Exists.
log('[INFO]:Starting to determine whether the log dir exists.')
dirpath='synchronize/' + config['logspath']
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.The ' + SystemName + ' will create one.')
os.makedirs(dirpath)
log('[INFO]:Make sure the log dir exists successfully.')
#------------------------------------------------------------------------#
print('------------------------------------------------------------------------')
Log=Log + '------------------------------------------------------------------------' + '\n'
#The Part of Synchronizing Single Important Files.
log('[INFO]:Starting to synchronize single files.')
#Synchronizing The Liteloader Versions List File.
log('[INFO]:Starting to synchronize Liteloader versions files.')
synchronize('http://dl.liteloader.com/versions/versions.json', 'liteloader/dl/versions/versions.json')
log('[INFO]:Synchronizing Liteloader versions files successfully.')
#------------------------------------------------------------------------#
print('------------------------------------------------------------------------')
Log=Log + '------------------------------------------------------------------------' + '\n'
log('[INFO]:Starting to synchronize more files.')
log('[WARN]:Attention!In the version new than 2.3.0,the synchronize tools will synchronize files in the background to improve the speed of synchronizing,that means you will not see the log output in the shell/cmd/powershell.If you want to see all logs and not care about the speed,you can download the old version on gitee,but we will not provide update for it.')
#MC Versions Synchronizing Part.
log('[INFO]:Starting synchronize all of MC versions.')
#Part 1.
log('[INFO]:Starting synchronize part 1.')
os.popen('python synchronize/part1.py','r')
#Part 2.
log('[INFO]:Starting synchronize part 2.')
os.popen('python synchronize/part2.py','r')
#Part 3.
log('[INFO]:Starting synchronize part 3.')
os.popen('python synchronize/part3.py','r')
#------------------------------------------------------------------------#
print('------------------------------------------------------------------------')
Log=Log + '------------------------------------------------------------------------' + '\n'
#Starting To Save Logs.
log('[INFO]:Starting to save logs.')
logwrite=open('synchronize/' + config['logspath'] + "main-" + str(time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime()) + '.txt'),mode='w')
logwrite.write(Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Save logs successfully.' + '\n' + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:All tasks of synchronizing have done successfully.')
print('[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Save logs successfully.' + '\n' + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:All tasks of synchronizing have done successfully.')
logwrite.close()

View File

@ -1,7 +1,7 @@
{
"savepath":"gemcapi/",
"version":"3.2.0",
"useragent":"GeMCAPI/3.1.0 (GeMC Sync Release 3.1.0;Release)",
"systemname":"GeMC API Synchronize Tool",
"logspath":"logs/"
{
"savepath":"gemcapi/",
"version":"3.2.0",
"useragent":"GeMCAPI/3.1.0 (GeMC Sync Release 3.1.0;Release)",
"systemname":"GeMC API Synchronize Tool",
"logspath":"logs/"
}

View File

@ -1,130 +1,130 @@
import requests
import os
import time
import json
import sys
#------------------------------------------------------------------------#
#Part Of Load All Kinds Of Global Variables From Json File.
configopen=open(os.path.dirname(os.path.abspath(sys.argv[0])) + "/config.json", mode='r')
configjson=configopen.read()
configopen.close()
config=json.loads(configjson)
SystemName=config['systemname']
SavePath=os.path.dirname(os.path.abspath(sys.argv[0])) + "/" + config['savepath']
Version=config['version']
UserAgent={'User-Agent':config['useragent']}
Log='[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting the synchronizing system.\n' + '------------------------------------------------------------------------\n' + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting to specify global variables.\n' + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Specifying global variables successful.\n'
#------------------------------------------------------------------------#
Log=Log + '------------------------------------------------------------------------' + '\n'
#The Part Of All Kinds Of Functions.
Log=Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting to load all kinds of functions.' + '\n'
#Function Which Be Used To Save Logs.
def log(logvar):
global Log
Log=Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + logvar + '\n'
#Function Which Be Used To Synchronize Single File.
def download(url, filepath):
global Log
global UserAgent
log('[INFO]:The ' + SystemName + ' is synchronizing the file ' + SavePath + filepath + '.')
try:
download=requests.get(url, headers=UserAgent)
with open(SavePath + filepath,"wb") as code:
code.write(download.content)
except:
log('[ERROR]:There has a error in task of synchronizing the file ' + SavePath + filepath + '.')
else:
log('[INFO]:The file ' + SavePath + filepath + ' has been synchronized successfully.')
#Function Which Be Used To Make Sure The Dir Exists.
def make_sure_dir_exists(dirpath):
global Log
if os.path.exists(SavePath + dirpath):
log('[INFO]:The dir ' + SavePath + dirpath + ' has already existed.Nothing to do.')
else:
log('[INFO]:The dir ' + SavePath + dirpath + ' does not exist.The ' + SystemName + ' will create one.')
os.makedirs(SavePath + dirpath)
#Function Which Be Used To Both Synchronize Single File And Make Sure The Dir Exists.
def synchronize(url, filepath):
global Log
global UserAgent
dirpath= filepath[::-1].split('/', 1)[-1][::-1]
if os.path.exists(SavePath + dirpath):
log('[INFO]:The dir ' + SavePath + dirpath + ' has already existed.Nothing to do.')
else:
log('[INFO]:The dir ' + SavePath + dirpath + ' does not exist.The ' + SystemName + ' will create one.')
os.makedirs(SavePath + dirpath)
log('[INFO]:The ' + SystemName + ' is synchronizing the file ' + SavePath + filepath + '.')
try:
download=requests.get(url, headers=UserAgent)
with open(SavePath + filepath,"wb") as code:
code.write(download.content)
except:
log('[ERROR]:There has a error in task of synchronizing the file ' + SavePath + filepath + '.')
else:
log('[INFO]:The file ' + SavePath + filepath + ' has been synchronized successfully.')
#Function Which Be Used To Get HTTP Site With Requests Avoid Error.
def httpget(url):
try:
return requests.get(url=url, headers=UserAgent).text
except:
return 'error'
log('[INFO]:Loading all kinds of functions successfully.')
#------------------------------------------------------------------------#
Log=Log + '------------------------------------------------------------------------' + '\n'
#Save JSON In Global Variables
log('[INFO]:Starting to get the json of MC versions list.')
Log=Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting to get the json of MC versions list.' + '\n'
#Save MC Versions List Json In Global Variables
mcversionsjson=requests.get(url='http://launchermeta.mojang.com/mc/game/version_manifest.json', headers=UserAgent)
log('[INFO]:Get json of MC versions successfully.')
Log=Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Get json of MC versions successfully.' + '\n'
#------------------------------------------------------------------------#
Log=Log + '------------------------------------------------------------------------' + '\n'
#Synchronize Part.
log('[INFO]:Starting to count how many MC versions in total.')
#Count How Many MC Versions in total.
mcversionsjsontext=mcversionsjson.text
mcversionsnumber=mcversionsjsontext.count('"url":')
log('[INFO]:There has ' + str(mcversionsnumber) + ' MC versions in total .')
log('[INFO]:Counting how many MC versions in total successfully.')
#Synchronizing The Minecraft Versions List File.
log('[INFO]:Starting to synchronize MC versions files.')
synchronize('http://launchermeta.mojang.com/mc/game/version_manifest.json', 'mojang/launchermeta/mc/game/version_manifest.json')
log('[INFO]:Synchronizing MC versions files successfully.')
#Auto Synchronize Files And Dirs on https://launchermeta.mojang.com/.
log('[INFO]:Starting to synchronize files and dirs on https://launchermeta.mojang.com/.')
whiletimes=0#Set Var whiletimes To Avoid Error.
while(whiletimes < mcversionsnumber):
#Count While Times.
whiletimes=whiletimes + 1
#Read Json Of MC Versions List.
downloadurlload=json.loads(mcversionsjsontext)
whiletimesload=whiletimes - 1
onlineurl=downloadurlload['versions'][whiletimesload]['url']
onlineurlwithouthttps=onlineurl.replace('https://', 'http://')#Avoid Https Connetion Errors
fileurl='mojang/launchermeta/' + onlineurl.replace('https://launchermeta.mojang.com/','')
synchronize(onlineurlwithouthttps, fileurl)
log('[INFO]:Synchronizing files and dirs on https://launchermeta.mojang.com/ successfully.')
#------------------------------------------------------------------------#
Log=Log + '------------------------------------------------------------------------' + '\n'
#Starting To Save Logs.
log('[INFO]:Starting to save logs.')
logwrite=open(os.path.dirname(os.path.abspath(sys.argv[0])) + '/' + config['logspath'] + 'part1-' + str(time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime()) + '.txt'),mode='w')
logwrite.write(Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Save logs successfully.' + '\n' + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:All tasks of synchronizing have done successfully.')
logwrite.close()
import requests
import os
import time
import json
import sys
#------------------------------------------------------------------------#
#Part Of Load All Kinds Of Global Variables From Json File.
configopen=open(os.path.dirname(os.path.abspath(sys.argv[0])) + "/config.json", mode='r')
configjson=configopen.read()
configopen.close()
config=json.loads(configjson)
SystemName=config['systemname']
SavePath=os.path.dirname(os.path.abspath(sys.argv[0])) + "/" + config['savepath']
Version=config['version']
UserAgent={'User-Agent':config['useragent']}
Log='[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting the synchronizing system.\n' + '------------------------------------------------------------------------\n' + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting to specify global variables.\n' + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Specifying global variables successful.\n'
#------------------------------------------------------------------------#
Log=Log + '------------------------------------------------------------------------' + '\n'
#The Part Of All Kinds Of Functions.
Log=Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting to load all kinds of functions.' + '\n'
#Function Which Be Used To Save Logs.
def log(logvar):
global Log
Log=Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + logvar + '\n'
#Function Which Be Used To Synchronize Single File.
def download(url, filepath):
global Log
global UserAgent
log('[INFO]:The ' + SystemName + ' is synchronizing the file ' + SavePath + filepath + '.')
try:
download=requests.get(url, headers=UserAgent)
with open(SavePath + filepath,"wb") as code:
code.write(download.content)
except:
log('[ERROR]:There has a error in task of synchronizing the file ' + SavePath + filepath + '.')
else:
log('[INFO]:The file ' + SavePath + filepath + ' has been synchronized successfully.')
#Function Which Be Used To Make Sure The Dir Exists.
def make_sure_dir_exists(dirpath):
global Log
if os.path.exists(SavePath + dirpath):
log('[INFO]:The dir ' + SavePath + dirpath + ' has already existed.Nothing to do.')
else:
log('[INFO]:The dir ' + SavePath + dirpath + ' does not exist.The ' + SystemName + ' will create one.')
os.makedirs(SavePath + dirpath)
#Function Which Be Used To Both Synchronize Single File And Make Sure The Dir Exists.
def synchronize(url, filepath):
global Log
global UserAgent
dirpath= filepath[::-1].split('/', 1)[-1][::-1]
if os.path.exists(SavePath + dirpath):
log('[INFO]:The dir ' + SavePath + dirpath + ' has already existed.Nothing to do.')
else:
log('[INFO]:The dir ' + SavePath + dirpath + ' does not exist.The ' + SystemName + ' will create one.')
os.makedirs(SavePath + dirpath)
log('[INFO]:The ' + SystemName + ' is synchronizing the file ' + SavePath + filepath + '.')
try:
download=requests.get(url, headers=UserAgent)
with open(SavePath + filepath,"wb") as code:
code.write(download.content)
except:
log('[ERROR]:There has a error in task of synchronizing the file ' + SavePath + filepath + '.')
else:
log('[INFO]:The file ' + SavePath + filepath + ' has been synchronized successfully.')
#Function Which Be Used To Get HTTP Site With Requests Avoid Error.
def httpget(url):
try:
return requests.get(url=url, headers=UserAgent).text
except:
return 'error'
log('[INFO]:Loading all kinds of functions successfully.')
#------------------------------------------------------------------------#
Log=Log + '------------------------------------------------------------------------' + '\n'
#Save JSON In Global Variables
log('[INFO]:Starting to get the json of MC versions list.')
Log=Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting to get the json of MC versions list.' + '\n'
#Save MC Versions List Json In Global Variables
mcversionsjson=requests.get(url='http://launchermeta.mojang.com/mc/game/version_manifest.json', headers=UserAgent)
log('[INFO]:Get json of MC versions successfully.')
Log=Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Get json of MC versions successfully.' + '\n'
#------------------------------------------------------------------------#
Log=Log + '------------------------------------------------------------------------' + '\n'
#Synchronize Part.
log('[INFO]:Starting to count how many MC versions in total.')
#Count How Many MC Versions in total.
mcversionsjsontext=mcversionsjson.text
mcversionsnumber=mcversionsjsontext.count('"url":')
log('[INFO]:There has ' + str(mcversionsnumber) + ' MC versions in total .')
log('[INFO]:Counting how many MC versions in total successfully.')
#Synchronizing The Minecraft Versions List File.
log('[INFO]:Starting to synchronize MC versions files.')
synchronize('http://launchermeta.mojang.com/mc/game/version_manifest.json', 'mojang/launchermeta/mc/game/version_manifest.json')
log('[INFO]:Synchronizing MC versions files successfully.')
#Auto Synchronize Files And Dirs on https://launchermeta.mojang.com/.
log('[INFO]:Starting to synchronize files and dirs on https://launchermeta.mojang.com/.')
whiletimes=0#Set Var whiletimes To Avoid Error.
while(whiletimes < mcversionsnumber):
#Count While Times.
whiletimes=whiletimes + 1
#Read Json Of MC Versions List.
downloadurlload=json.loads(mcversionsjsontext)
whiletimesload=whiletimes - 1
onlineurl=downloadurlload['versions'][whiletimesload]['url']
onlineurlwithouthttps=onlineurl.replace('https://', 'http://')#Avoid Https Connetion Errors
fileurl='mojang/launchermeta/' + onlineurl.replace('https://launchermeta.mojang.com/','')
synchronize(onlineurlwithouthttps, fileurl)
log('[INFO]:Synchronizing files and dirs on https://launchermeta.mojang.com/ successfully.')
#------------------------------------------------------------------------#
Log=Log + '------------------------------------------------------------------------' + '\n'
#Starting To Save Logs.
log('[INFO]:Starting to save logs.')
logwrite=open(os.path.dirname(os.path.abspath(sys.argv[0])) + '/' + config['logspath'] + 'part1-' + str(time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime()) + '.txt'),mode='w')
logwrite.write(Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Save logs successfully.' + '\n' + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:All tasks of synchronizing have done successfully.')
logwrite.close()

View File

@ -1,206 +1,206 @@
import requests
import os
import time
import json
import sys
#------------------------------------------------------------------------#
#Part Of Load All Kinds Of Global Variables From Json File.
configopen=open(os.path.dirname(os.path.abspath(sys.argv[0])) + "/config.json", mode='r')
configjson=configopen.read()
configopen.close()
config=json.loads(configjson)
SystemName=config['systemname']
SavePath=os.path.dirname(os.path.abspath(sys.argv[0])) + "/" + config['savepath']
Version=config['version']
UserAgent={'User-Agent':config['useragent']}
Log='[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting the synchronizing system.\n' + '------------------------------------------------------------------------\n' + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting to specify global variables.\n' + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Specifying global variables successful.\n'
#------------------------------------------------------------------------#
Log=Log + '------------------------------------------------------------------------' + '\n'
#The Part Of All Kinds Of Functions.
Log=Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting to load all kinds of functions.' + '\n'
#Function Which Be Used To Save Logs.
def log(logvar):
global Log
Log=Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + logvar + '\n'
#Function Which Be Used To Synchronize Single File.
def download(url, filepath):
global Log
global UserAgent
log('[INFO]:The ' + SystemName + ' is synchronizing the file ' + SavePath + filepath + '.')
try:
download=requests.get(url, headers=UserAgent)
with open(SavePath + filepath,"wb") as code:
code.write(download.content)
except:
log('[ERROR]:There has a error in task of synchronizing the file ' + SavePath + filepath + '.')
else:
log('[INFO]:The file ' + SavePath + filepath + ' has been synchronized successfully.')
#Function Which Be Used To Make Sure The Dir Exists.
def make_sure_dir_exists(dirpath):
global Log
if os.path.exists(SavePath + dirpath):
log('[INFO]:The dir ' + SavePath + dirpath + ' has already existed.Nothing to do.')
else:
log('[INFO]:The dir ' + SavePath + dirpath + ' does not exist.The ' + SystemName + ' will create one.')
os.makedirs(SavePath + dirpath)
#Function Which Be Used To Both Synchronize Single File And Make Sure The Dir Exists.
def synchronize(url, filepath):
global Log
global UserAgent
dirpath= filepath[::-1].split('/', 1)[-1][::-1]
if os.path.exists(SavePath + dirpath):
log('[INFO]:The dir ' + SavePath + dirpath + ' has already existed.Nothing to do.')
else:
log('[INFO]:The dir ' + SavePath + dirpath + ' does not exist.The ' + SystemName + ' will create one.')
os.makedirs(SavePath + dirpath)
log('[INFO]:The ' + SystemName + ' is synchronizing the file ' + SavePath + filepath + '.')
try:
download=requests.get(url, headers=UserAgent)
with open(SavePath + filepath,"wb") as code:
code.write(download.content)
except:
log('[ERROR]:There has a error in task of synchronizing the file ' + SavePath + filepath + '.')
else:
log('[INFO]:The file ' + SavePath + filepath + ' has been synchronized successfully.')
#Function Which Be Used To Get HTTP Site With Requests Avoid Error.
def httpget(url):
try:
return requests.get(url=url, headers=UserAgent).text
except:
return 'error'
log('[INFO]:Loading all kinds of functions successfully.')
#------------------------------------------------------------------------#
Log=Log + '------------------------------------------------------------------------' + '\n'
#Save JSON In Global Variables
log('[INFO]:Starting to get the json of MC versions list.')
Log=Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting to get the json of MC versions list.' + '\n'
#Save MC Versions List Json In Global Variables
mcversionsjson=requests.get(url='http://launchermeta.mojang.com/mc/game/version_manifest.json', headers=UserAgent)
log('[INFO]:Get json of MC versions successfully.')
Log=Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Get json of MC versions successfully.' + '\n'
#------------------------------------------------------------------------#
Log=Log + '------------------------------------------------------------------------' + '\n'
#Synchronize Part.
log('[INFO]:Starting to count how many MC versions in total.')
#Count How Many MC Versions in total.
mcversionsjsontext=mcversionsjson.text
mcversionsnumber=mcversionsjsontext.count('"url":')
log('[INFO]:There has ' + str(mcversionsnumber) + ' MC versions in total .')
log('[INFO]:Counting how many MC versions in total successfully.')
#Auto Synchronize Files And Dirs on https://libraries.minecraft.net/.
log('[INFO]:Starting to synchronize files and dirs on https://libraries.minecraft.net/.')
#Part Of 'downloads'.
whiletimes=0#Set Var whiletimes To Avoid Error.
while(whiletimes < mcversionsnumber):
#Count While Times.
whiletimes=whiletimes + 1
#Read Json Of MC Versions List.
downloadurlload=json.loads(mcversionsjsontext)
whiletimesload=whiletimes - 1
onlineurl=downloadurlload['versions'][whiletimesload]['url']
onlineurlwithouthttps=onlineurl.replace('https://', 'http://')#Avoid Https Connetion Errors
log('[INFO]:Starting to get the json of MC libraries ' + onlineurl +' list.')
#Save MC Libraries Json In Global Variables
try:#Avoid Http/Https Connection Errors Making Whole Synchronize Stop.
mclibrariesjson=requests.get(url=onlineurlwithouthttps, headers=UserAgent)
except:
log('[ERROR]:There has a error in task of getting json of MC libraries ' + onlineurl + '.')
else:
log('[INFO]:Get json of MC libraries ' + onlineurl + ' successfully.')
#Read Json Of MC Libraries.
mclibrariesload=json.loads(mclibrariesjson.text)
#Synchronize Files In "downloads".
log('[INFO]:Starting to synchronize files in ”downloads".')
try:#Avoid Http/Https Connection Errors Or Synchronize Module Download Failed Errors Making Whole Synchronize Stop.
onlineurl2=mclibrariesload['downloads']['client']['url']
fileurl2='mojang/launcher/' + onlineurl2.replace('https://launcher.mojang.com/','')
synchronize(onlineurl2, fileurl2)
onlineurl2=mclibrariesload['downloads']['client_mappings']['url']
fileurl2='mojang/launcher/' + onlineurl2.replace('https://launcher.mojang.com/','')
synchronize(onlineurl2, fileurl2)
onlineurl2=mclibrariesload['downloads']['server']['url']
fileurl2='mojang/launcher/' + onlineurl2.replace('https://launcher.mojang.com/','')
synchronize(onlineurl2, fileurl2)
onlineurl2=mclibrariesload['downloads']['server_mappings']['url']
fileurl2='mojang/launcher/' + onlineurl2.replace('https://launcher.mojang.com/','')
synchronize(onlineurl2, fileurl2)
#Synchronize Files In "loggin".
onlineurl2=mclibrariesload['loggin']['client']['file']['url']
fileurl2='mojang/launcher/' + onlineurl2.replace('https://launcher.mojang.com/','')
synchronize(onlineurl2, fileurl2)
except:
log('[ERROR]:There has a error in task of synchronizing files in "downloads".')
else:
log('[INFO]:Synchronizing files in "downloads" successfully.')
log('[INFO]:Starting to count how many MC libraries files in ' + onlineurl + ' in total.')
#Count How Many MC Libraries Files in total.
mclibrariesjsontext=mclibrariesjson.text
mclibrariesnumber=mclibrariesjsontext.count('"url":') - 6
log('[INFO]:There has ' + str(mclibrariesnumber) + ' MC libraries files in ' + onlineurl + ' in total.')
log('[INFO]:Counting how many MC libraries files in ' + onlineurl + ' in total successfully.')
whiletimes3=0#Set Var whiletimes To Avoid Error.
while(whiletimes3 < mclibrariesnumber):
#Count While Times.
whiletimes3=whiletimes3 + 1
whiletimesload3=whiletimes3 - 1
#Synchronize Files In "libraries".
log('[INFO]:Starting to synchronize Files In "libraries".')
try:#Avoid Http/Https Connection Errors Or Synchronize Module Download Failed Errors Making Whole Synchronize Stop.
#Synchronize Files In "libraries/.../downloads/artifact".
onlineurl3=mclibrariesload['libraries'][whiletimesload3]['downloads']['artifact']['url']
onlineurlwithouthttps3=onlineurl3.replace('https://', 'http://')
fileurl3='mojang/libraries/' + onlineurl3.replace('https://libraries.minecraft.net/','')
synchronize(onlineurlwithouthttps3, fileurl3)
#Synchronize Files In "libraries/.../downloads/classifiers/javadoc".
onlineurl3=mclibrariesload['libraries'][whiletimesload3]['downloads']['classifiers']['javadoc']['url']
onlineurlwithouthttps3=onlineurl3.replace('https://', 'http://')
fileurl3='mojang/libraries/' + onlineurl3.replace('https://libraries.minecraft.net/','')
synchronize(onlineurlwithouthttps3, fileurl3)
#Synchronize Files In "libraries/.../downloads/classifiers/natives-linux".
onlineurl3=mclibrariesload['libraries'][whiletimesload3]['downloads']['classifiers']['natives-linux']['url']
onlineurlwithouthttps3=onlineurl3.replace('https://', 'http://')
fileurl3='mojang/libraries/' + onlineurl3.replace('https://libraries.minecraft.net/','')
synchronize(onlineurlwithouthttps3, fileurl3)
#Synchronize Files In "libraries/.../downloads/classifiers/natives-macos".
onlineurl3=mclibrariesload['libraries'][whiletimesload3]['downloads']['classifiers']['natives-macos']['url']
onlineurlwithouthttps3=onlineurl3.replace('https://', 'http://')
fileurl3='mojang/libraries/' + onlineurl3.replace('https://libraries.minecraft.net/','')
synchronize(onlineurlwithouthttps3, fileurl3)
#Synchronize Files In "libraries/.../downloads/classifiers/natives-windows".
onlineurl3=mclibrariesload['libraries'][whiletimesload3]['downloads']['classifiers']['natives-windows']['url']
onlineurlwithouthttps3=onlineurl3.replace('https://', 'http://')
fileurl3='mojang/libraries/' + onlineurl3.replace('https://libraries.minecraft.net/','')
synchronize(onlineurlwithouthttps3, fileurl3)
#Synchronize Files In "libraries/.../downloads/artifact/classifiers/sources".
onlineurl3=mclibrariesload['libraries'][whiletimesload3]['downloads']['classifiers']['sources']['url']
onlineurlwithouthttps3=onlineurl3.replace('https://', 'http://')
fileurl3='mojang/libraries/' + onlineurl3.replace('https://libraries.minecraft.net/','')
synchronize(onlineurlwithouthttps3, fileurl3)
except:
log('[ERROR]:There has a error in task of synchronizing files in ”libraries".')
else:
log('[INFO]:Synchronizing files in "libraries" successfully.')
log('[INFO]:Synchronizing files and dirs on https://libraries.minecraft.net/ successfully.')
#------------------------------------------------------------------------#
Log=Log + '------------------------------------------------------------------------' + '\n'
#Starting To Save Logs.
log('[INFO]:Starting to save logs.')
logwrite=open(os.path.dirname(os.path.abspath(sys.argv[0])) + '/' + config['logspath'] + 'part1-' + str(time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime()) + '.txt'),mode='w')
logwrite.write(Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Save logs successfully.' + '\n' + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:All tasks of synchronizing have done successfully.')
logwrite.close()
import requests
import os
import time
import json
import sys
#------------------------------------------------------------------------#
#Part Of Load All Kinds Of Global Variables From Json File.
configopen=open(os.path.dirname(os.path.abspath(sys.argv[0])) + "/config.json", mode='r')
configjson=configopen.read()
configopen.close()
config=json.loads(configjson)
SystemName=config['systemname']
SavePath=os.path.dirname(os.path.abspath(sys.argv[0])) + "/" + config['savepath']
Version=config['version']
UserAgent={'User-Agent':config['useragent']}
Log='[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting the synchronizing system.\n' + '------------------------------------------------------------------------\n' + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting to specify global variables.\n' + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Specifying global variables successful.\n'
#------------------------------------------------------------------------#
Log=Log + '------------------------------------------------------------------------' + '\n'
#The Part Of All Kinds Of Functions.
Log=Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting to load all kinds of functions.' + '\n'
#Function Which Be Used To Save Logs.
def log(logvar):
global Log
Log=Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + logvar + '\n'
#Function Which Be Used To Synchronize Single File.
def download(url, filepath):
global Log
global UserAgent
log('[INFO]:The ' + SystemName + ' is synchronizing the file ' + SavePath + filepath + '.')
try:
download=requests.get(url, headers=UserAgent)
with open(SavePath + filepath,"wb") as code:
code.write(download.content)
except:
log('[ERROR]:There has a error in task of synchronizing the file ' + SavePath + filepath + '.')
else:
log('[INFO]:The file ' + SavePath + filepath + ' has been synchronized successfully.')
#Function Which Be Used To Make Sure The Dir Exists.
def make_sure_dir_exists(dirpath):
global Log
if os.path.exists(SavePath + dirpath):
log('[INFO]:The dir ' + SavePath + dirpath + ' has already existed.Nothing to do.')
else:
log('[INFO]:The dir ' + SavePath + dirpath + ' does not exist.The ' + SystemName + ' will create one.')
os.makedirs(SavePath + dirpath)
#Function Which Be Used To Both Synchronize Single File And Make Sure The Dir Exists.
def synchronize(url, filepath):
global Log
global UserAgent
dirpath= filepath[::-1].split('/', 1)[-1][::-1]
if os.path.exists(SavePath + dirpath):
log('[INFO]:The dir ' + SavePath + dirpath + ' has already existed.Nothing to do.')
else:
log('[INFO]:The dir ' + SavePath + dirpath + ' does not exist.The ' + SystemName + ' will create one.')
os.makedirs(SavePath + dirpath)
log('[INFO]:The ' + SystemName + ' is synchronizing the file ' + SavePath + filepath + '.')
try:
download=requests.get(url, headers=UserAgent)
with open(SavePath + filepath,"wb") as code:
code.write(download.content)
except:
log('[ERROR]:There has a error in task of synchronizing the file ' + SavePath + filepath + '.')
else:
log('[INFO]:The file ' + SavePath + filepath + ' has been synchronized successfully.')
#Function Which Be Used To Get HTTP Site With Requests Avoid Error.
def httpget(url):
try:
return requests.get(url=url, headers=UserAgent).text
except:
return 'error'
log('[INFO]:Loading all kinds of functions successfully.')
#------------------------------------------------------------------------#
Log=Log + '------------------------------------------------------------------------' + '\n'
#Save JSON In Global Variables
log('[INFO]:Starting to get the json of MC versions list.')
Log=Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting to get the json of MC versions list.' + '\n'
#Save MC Versions List Json In Global Variables
mcversionsjson=requests.get(url='http://launchermeta.mojang.com/mc/game/version_manifest.json', headers=UserAgent)
log('[INFO]:Get json of MC versions successfully.')
Log=Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Get json of MC versions successfully.' + '\n'
#------------------------------------------------------------------------#
Log=Log + '------------------------------------------------------------------------' + '\n'
#Synchronize Part.
log('[INFO]:Starting to count how many MC versions in total.')
#Count How Many MC Versions in total.
mcversionsjsontext=mcversionsjson.text
mcversionsnumber=mcversionsjsontext.count('"url":')
log('[INFO]:There has ' + str(mcversionsnumber) + ' MC versions in total .')
log('[INFO]:Counting how many MC versions in total successfully.')
#Auto Synchronize Files And Dirs on https://libraries.minecraft.net/.
log('[INFO]:Starting to synchronize files and dirs on https://libraries.minecraft.net/.')
#Part Of 'downloads'.
whiletimes=0#Set Var whiletimes To Avoid Error.
while(whiletimes < mcversionsnumber):
#Count While Times.
whiletimes=whiletimes + 1
#Read Json Of MC Versions List.
downloadurlload=json.loads(mcversionsjsontext)
whiletimesload=whiletimes - 1
onlineurl=downloadurlload['versions'][whiletimesload]['url']
onlineurlwithouthttps=onlineurl.replace('https://', 'http://')#Avoid Https Connetion Errors
log('[INFO]:Starting to get the json of MC libraries ' + onlineurl +' list.')
#Save MC Libraries Json In Global Variables
try:#Avoid Http/Https Connection Errors Making Whole Synchronize Stop.
mclibrariesjson=requests.get(url=onlineurlwithouthttps, headers=UserAgent)
except:
log('[ERROR]:There has a error in task of getting json of MC libraries ' + onlineurl + '.')
else:
log('[INFO]:Get json of MC libraries ' + onlineurl + ' successfully.')
#Read Json Of MC Libraries.
mclibrariesload=json.loads(mclibrariesjson.text)
#Synchronize Files In "downloads".
log('[INFO]:Starting to synchronize files in ”downloads".')
try:#Avoid Http/Https Connection Errors Or Synchronize Module Download Failed Errors Making Whole Synchronize Stop.
onlineurl2=mclibrariesload['downloads']['client']['url']
fileurl2='mojang/launcher/' + onlineurl2.replace('https://launcher.mojang.com/','')
synchronize(onlineurl2, fileurl2)
onlineurl2=mclibrariesload['downloads']['client_mappings']['url']
fileurl2='mojang/launcher/' + onlineurl2.replace('https://launcher.mojang.com/','')
synchronize(onlineurl2, fileurl2)
onlineurl2=mclibrariesload['downloads']['server']['url']
fileurl2='mojang/launcher/' + onlineurl2.replace('https://launcher.mojang.com/','')
synchronize(onlineurl2, fileurl2)
onlineurl2=mclibrariesload['downloads']['server_mappings']['url']
fileurl2='mojang/launcher/' + onlineurl2.replace('https://launcher.mojang.com/','')
synchronize(onlineurl2, fileurl2)
#Synchronize Files In "loggin".
onlineurl2=mclibrariesload['loggin']['client']['file']['url']
fileurl2='mojang/launcher/' + onlineurl2.replace('https://launcher.mojang.com/','')
synchronize(onlineurl2, fileurl2)
except:
log('[ERROR]:There has a error in task of synchronizing files in "downloads".')
else:
log('[INFO]:Synchronizing files in "downloads" successfully.')
log('[INFO]:Starting to count how many MC libraries files in ' + onlineurl + ' in total.')
#Count How Many MC Libraries Files in total.
mclibrariesjsontext=mclibrariesjson.text
mclibrariesnumber=mclibrariesjsontext.count('"url":') - 6
log('[INFO]:There has ' + str(mclibrariesnumber) + ' MC libraries files in ' + onlineurl + ' in total.')
log('[INFO]:Counting how many MC libraries files in ' + onlineurl + ' in total successfully.')
whiletimes3=0#Set Var whiletimes To Avoid Error.
while(whiletimes3 < mclibrariesnumber):
#Count While Times.
whiletimes3=whiletimes3 + 1
whiletimesload3=whiletimes3 - 1
#Synchronize Files In "libraries".
log('[INFO]:Starting to synchronize Files In "libraries".')
try:#Avoid Http/Https Connection Errors Or Synchronize Module Download Failed Errors Making Whole Synchronize Stop.
#Synchronize Files In "libraries/.../downloads/artifact".
onlineurl3=mclibrariesload['libraries'][whiletimesload3]['downloads']['artifact']['url']
onlineurlwithouthttps3=onlineurl3.replace('https://', 'http://')
fileurl3='mojang/libraries/' + onlineurl3.replace('https://libraries.minecraft.net/','')
synchronize(onlineurlwithouthttps3, fileurl3)
#Synchronize Files In "libraries/.../downloads/classifiers/javadoc".
onlineurl3=mclibrariesload['libraries'][whiletimesload3]['downloads']['classifiers']['javadoc']['url']
onlineurlwithouthttps3=onlineurl3.replace('https://', 'http://')
fileurl3='mojang/libraries/' + onlineurl3.replace('https://libraries.minecraft.net/','')
synchronize(onlineurlwithouthttps3, fileurl3)
#Synchronize Files In "libraries/.../downloads/classifiers/natives-linux".
onlineurl3=mclibrariesload['libraries'][whiletimesload3]['downloads']['classifiers']['natives-linux']['url']
onlineurlwithouthttps3=onlineurl3.replace('https://', 'http://')
fileurl3='mojang/libraries/' + onlineurl3.replace('https://libraries.minecraft.net/','')
synchronize(onlineurlwithouthttps3, fileurl3)
#Synchronize Files In "libraries/.../downloads/classifiers/natives-macos".
onlineurl3=mclibrariesload['libraries'][whiletimesload3]['downloads']['classifiers']['natives-macos']['url']
onlineurlwithouthttps3=onlineurl3.replace('https://', 'http://')
fileurl3='mojang/libraries/' + onlineurl3.replace('https://libraries.minecraft.net/','')
synchronize(onlineurlwithouthttps3, fileurl3)
#Synchronize Files In "libraries/.../downloads/classifiers/natives-windows".
onlineurl3=mclibrariesload['libraries'][whiletimesload3]['downloads']['classifiers']['natives-windows']['url']
onlineurlwithouthttps3=onlineurl3.replace('https://', 'http://')
fileurl3='mojang/libraries/' + onlineurl3.replace('https://libraries.minecraft.net/','')
synchronize(onlineurlwithouthttps3, fileurl3)
#Synchronize Files In "libraries/.../downloads/artifact/classifiers/sources".
onlineurl3=mclibrariesload['libraries'][whiletimesload3]['downloads']['classifiers']['sources']['url']
onlineurlwithouthttps3=onlineurl3.replace('https://', 'http://')
fileurl3='mojang/libraries/' + onlineurl3.replace('https://libraries.minecraft.net/','')
synchronize(onlineurlwithouthttps3, fileurl3)
except:
log('[ERROR]:There has a error in task of synchronizing files in ”libraries".')
else:
log('[INFO]:Synchronizing files in "libraries" successfully.')
log('[INFO]:Synchronizing files and dirs on https://libraries.minecraft.net/ successfully.')
#------------------------------------------------------------------------#
Log=Log + '------------------------------------------------------------------------' + '\n'
#Starting To Save Logs.
log('[INFO]:Starting to save logs.')
logwrite=open(os.path.dirname(os.path.abspath(sys.argv[0])) + '/' + config['logspath'] + 'part1-' + str(time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime()) + '.txt'),mode='w')
logwrite.write(Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Save logs successfully.' + '\n' + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:All tasks of synchronizing have done successfully.')
logwrite.close()

View File

@ -1,184 +1,184 @@
import requests
import os
import time
import json
import sys
#------------------------------------------------------------------------#
#Part Of Load All Kinds Of Global Variables From Json File.
configopen=open(os.path.dirname(os.path.abspath(sys.argv[0])) + "/config.json", mode='r')
configjson=configopen.read()
configopen.close()
config=json.loads(configjson)
SystemName=config['systemname']
SavePath=os.path.dirname(os.path.abspath(sys.argv[0])) + "/" + config['savepath']
Version=config['version']
UserAgent={'User-Agent':config['useragent']}
Log='[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting the synchronizing system.\n' + '------------------------------------------------------------------------\n' + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting to specify global variables.\n' + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Specifying global variables successful.\n'
#------------------------------------------------------------------------#
Log=Log + '------------------------------------------------------------------------' + '\n'
#The Part Of All Kinds Of Functions.
Log=Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting to load all kinds of functions.' + '\n'
#Function Which Be Used To Save Logs.
def log(logvar):
global Log
Log=Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + logvar + '\n'
#Function Which Be Used To Synchronize Single File.
def download(url, filepath):
global Log
global UserAgent
log('[INFO]:The ' + SystemName + ' is synchronizing the file ' + SavePath + filepath + '.')
try:
download=requests.get(url, headers=UserAgent)
with open(SavePath + filepath,"wb") as code:
code.write(download.content)
except:
log('[ERROR]:There has a error in task of synchronizing the file ' + SavePath + filepath + '.')
else:
log('[INFO]:The file ' + SavePath + filepath + ' has been synchronized successfully.')
#Function Which Be Used To Make Sure The Dir Exists.
def make_sure_dir_exists(dirpath):
global Log
if os.path.exists(SavePath + dirpath):
log('[INFO]:The dir ' + SavePath + dirpath + ' has already existed.Nothing to do.')
else:
log('[INFO]:The dir ' + SavePath + dirpath + ' does not exist.The ' + SystemName + ' will create one.')
os.makedirs(SavePath + dirpath)
#Function Which Be Used To Both Synchronize Single File And Make Sure The Dir Exists.
def synchronize(url, filepath):
global Log
global UserAgent
dirpath= filepath[::-1].split('/', 1)[-1][::-1]
if os.path.exists(SavePath + dirpath):
log('[INFO]:The dir ' + SavePath + dirpath + ' has already existed.Nothing to do.')
else:
log('[INFO]:The dir ' + SavePath + dirpath + ' does not exist.The ' + SystemName + ' will create one.')
os.makedirs(SavePath + dirpath)
log('[INFO]:The ' + SystemName + ' is synchronizing the file ' + SavePath + filepath + '.')
try:
download=requests.get(url, headers=UserAgent)
with open(SavePath + filepath,"wb") as code:
code.write(download.content)
except:
log('[ERROR]:There has a error in task of synchronizing the file ' + SavePath + filepath + '.')
else:
log('[INFO]:The file ' + SavePath + filepath + ' has been synchronized successfully.')
#Function Which Be Used To Get HTTP Site With Requests Avoid Error.
def httpget(url):
try:
return requests.get(url=url, headers=UserAgent).text
except:
return 'error'
log('[INFO]:Loading all kinds of functions successfully.')
#------------------------------------------------------------------------#
Log=Log + '------------------------------------------------------------------------' + '\n'
log('[INFO]:Starting to get forge builds list from BMCLAPI.')
log('[INFO]:Thanks the support from bangbang93.')
#Synchronize The Last Forge Builds.
log('[INFO]:Starting synchronize the last forge builds.')
synchronize('http://bmclapi2.bangbang93.com/forge/last','forge/last/index.html')
#Synchronize The Versions List Of Minecraft Which Were Supported By Forge.
log('[INFO]:Starting synchronize the versions list of minecraft which were supported by forfge.')
synchronize('http://bmclapi2.bangbang93.com/forge/minecraft','forge/minecraft/index.html')
#Synchronize The Different Number Of Builds List Of Forge.
log('[INFO]:Starting synchronize the different number of builds list of forge.')
count=0
for i in range(0,500):
count=count+1
synchronize('http://bmclapi2.bangbang93.com/forge/list/'+str(count), 'forge/list/'+str(count)+'/index.html')
#Synchronize The Forge Builds List With Different MC Versions.
log('[INFO]:Starting synchronize the forge builds list with different mc versions.')
supportlist=httpget('http://bmclapi2.bangbang93.com/forge/minecraft')
number=supportlist.count(',')
supportlistjson=json.loads(supportlist)
count=0
for i in range(0,number):
count=count+1
version=supportlistjson[count]
synchronize('http://bmclapi2.bangbang93.com/forge/minecraft/'+version, 'forge/minecraft/'+version+'/index.html')
#Synchronize The Forge Builds With Different MC Versions With Build ID.
log('[INFO]:Starting synchronize the forge builds with different mc versions with build ID.')
count=0
for i in range(0,number):
count=count+1
version=supportlistjson[count]
buildswithversion=httpget('http://bmclapi2.bangbang93.com/forge/minecraft/'+version)
buildswithversionjson=json.loads(buildswithversion)
number_sub=buildswithversion.count('build')
count_sub=0
for i in range(0,number_sub):
count_sub=count_sub+1
countforjson=count_sub-1
buildid=buildswithversionjson[countforjson]['build']
if httpget('http://bmclapi2.bangbang93.com/forge/download/'+str(buildid))=="Not Found":
log('[ERROR]:Can not find the file which is synchronizing on BMCLAPI.This may a bug of BMCLAPI,but in most times is not a bug and that is normal.')
elif httpget('http://bmclapi2.bangbang93.com/forge/download/'+str(buildid))=="error":
log('[ERROR]:Can not get the file from BMCLAPI,this may a Internet problem or the server of BMCLAPI is dead.')
else:
synchronize('http://bmclapi2.bangbang93.com/forge/download/'+str(buildid), 'forge/download/'+str(buildid)+'.jar')
#Synchronize The Forge Builds With Different MC Versions.
log('[INFO]:Starting synchronize the forge builds with different mc versions.')
count=0
for i in range(0,number):
count=count+1
version=supportlistjson[count]
versionswithversion=httpget('http://bmclapi2.bangbang93.com/forge/minecraft/'+version)
versionswithversionjson=json.loads(versionswithversion)
number_sub=versionswithversion.count('"version"')
count_sub=0
for i in range(0,number_sub):
count_sub=count_sub+1
countforjson=count_sub-1
versionid=versionswithversionjson[countforjson]['version']
#Installer Part.
if httpget('http://bmclapi2.bangbang93.com/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-installer.jar')=="Not Found":
log('[ERROR]:Can not find the file which is synchronizing on BMCLAPI.This may a bug of BMCLAPI,but in most times is not a bug and that is normal.')
elif httpget('http://bmclapi2.bangbang93.com/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-installer.jar')=="error":
log('[ERROR]:Can not get the file from BMCLAPI,this may a Internet problem or the server of BMCLAPI is dead.')
else:
synchronize('http://bmclapi2.bangbang93.com/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-installer.jar', 'forge/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-installer.jar')
#Launcher Part.
if httpget('http://bmclapi2.bangbang93.com/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-launcher.jar')=="Not Found":
log('[ERROR]:Can not find the file which is synchronizing on BMCLAPI.This may a bug of BMCLAPI,but in most times is not a bug and that is normal.')
elif httpget('http://bmclapi2.bangbang93.com/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-launcher.jar')=="error":
log('[ERROR]:Can not get the file from BMCLAPI,this may a Internet problem or the server of BMCLAPI is dead.')
else:
synchronize('http://bmclapi2.bangbang93.com/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-launcher.jar', 'forge/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-launcher.jar')
#Sources Part.
if httpget('http://bmclapi2.bangbang93.com/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-sources.jar')=="Not Found":
log('[ERROR]:Can not find the file which is synchronizing on BMCLAPI.This may a bug of BMCLAPI,but in most times is not a bug and that is normal.')
elif httpget('http://bmclapi2.bangbang93.com/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-sources.jar')=="error":
log('[ERROR]:Can not get the file from BMCLAPI,this may a Internet problem or the server of BMCLAPI is dead.')
else:
synchronize('http://bmclapi2.bangbang93.com/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-sources.jar', 'forge/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-sources.jar')
#Universal Part.
if httpget('http://bmclapi2.bangbang93.com/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-universal.jar')=="Not Found":
log('[ERROR]:Can not find the file which is synchronizing on BMCLAPI.This may a bug of BMCLAPI,but in most times is not a bug and that is normal.')
elif httpget('http://bmclapi2.bangbang93.com/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-universal.jar')=="error":
log('[ERROR]:Can not get the file from BMCLAPI,this may a Internet problem or the server of BMCLAPI is dead.')
else:
synchronize('http://bmclapi2.bangbang93.com/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-universal.jar', 'forge/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-universal.jar')
#MDK Part.
if httpget('http://bmclapi2.bangbang93.com/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-mdk.zip')=="Not Found":
log('[ERROR]:Can not find the file which is synchronizing on BMCLAPI.This may a bug of BMCLAPI,but in most times is not a bug and that is normal.')
elif httpget('http://bmclapi2.bangbang93.com/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-mdk.zip')=="error":
log('[ERROR]:Can not get the file from BMCLAPI,this may a Internet problem or the server of BMCLAPI is dead.')
else:
synchronize('http://bmclapi2.bangbang93.com/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-mdk.zip', 'forge/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-mdk.zip')
log('[INFO]:Synchronizing forge builds list from BMCLAPI successfully.')
#------------------------------------------------------------------------#
Log=Log + '------------------------------------------------------------------------' + '\n'
#Starting To Save Logs.
log('[INFO]:Starting to save logs.')
logwrite=open(os.path.dirname(os.path.abspath(sys.argv[0])) + '/' + config['logspath'] + 'part3-' + str(time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime()) + '.txt'),mode='w')
logwrite.write(Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Save logs successfully.' + '\n' + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:All tasks of synchronizing have done successfully.')
logwrite.close()
import requests
import os
import time
import json
import sys
#------------------------------------------------------------------------#
#Part Of Load All Kinds Of Global Variables From Json File.
configopen=open(os.path.dirname(os.path.abspath(sys.argv[0])) + "/config.json", mode='r')
configjson=configopen.read()
configopen.close()
config=json.loads(configjson)
SystemName=config['systemname']
SavePath=os.path.dirname(os.path.abspath(sys.argv[0])) + "/" + config['savepath']
Version=config['version']
UserAgent={'User-Agent':config['useragent']}
Log='[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting the synchronizing system.\n' + '------------------------------------------------------------------------\n' + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting to specify global variables.\n' + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Specifying global variables successful.\n'
#------------------------------------------------------------------------#
Log=Log + '------------------------------------------------------------------------' + '\n'
#The Part Of All Kinds Of Functions.
Log=Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Starting to load all kinds of functions.' + '\n'
#Function Which Be Used To Save Logs.
def log(logvar):
global Log
Log=Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + logvar + '\n'
#Function Which Be Used To Synchronize Single File.
def download(url, filepath):
global Log
global UserAgent
log('[INFO]:The ' + SystemName + ' is synchronizing the file ' + SavePath + filepath + '.')
try:
download=requests.get(url, headers=UserAgent)
with open(SavePath + filepath,"wb") as code:
code.write(download.content)
except:
log('[ERROR]:There has a error in task of synchronizing the file ' + SavePath + filepath + '.')
else:
log('[INFO]:The file ' + SavePath + filepath + ' has been synchronized successfully.')
#Function Which Be Used To Make Sure The Dir Exists.
def make_sure_dir_exists(dirpath):
global Log
if os.path.exists(SavePath + dirpath):
log('[INFO]:The dir ' + SavePath + dirpath + ' has already existed.Nothing to do.')
else:
log('[INFO]:The dir ' + SavePath + dirpath + ' does not exist.The ' + SystemName + ' will create one.')
os.makedirs(SavePath + dirpath)
#Function Which Be Used To Both Synchronize Single File And Make Sure The Dir Exists.
def synchronize(url, filepath):
global Log
global UserAgent
dirpath= filepath[::-1].split('/', 1)[-1][::-1]
if os.path.exists(SavePath + dirpath):
log('[INFO]:The dir ' + SavePath + dirpath + ' has already existed.Nothing to do.')
else:
log('[INFO]:The dir ' + SavePath + dirpath + ' does not exist.The ' + SystemName + ' will create one.')
os.makedirs(SavePath + dirpath)
log('[INFO]:The ' + SystemName + ' is synchronizing the file ' + SavePath + filepath + '.')
try:
download=requests.get(url, headers=UserAgent)
with open(SavePath + filepath,"wb") as code:
code.write(download.content)
except:
log('[ERROR]:There has a error in task of synchronizing the file ' + SavePath + filepath + '.')
else:
log('[INFO]:The file ' + SavePath + filepath + ' has been synchronized successfully.')
#Function Which Be Used To Get HTTP Site With Requests Avoid Error.
def httpget(url):
try:
return requests.get(url=url, headers=UserAgent).text
except:
return 'error'
log('[INFO]:Loading all kinds of functions successfully.')
#------------------------------------------------------------------------#
Log=Log + '------------------------------------------------------------------------' + '\n'
log('[INFO]:Starting to get forge builds list from BMCLAPI.')
log('[INFO]:Thanks the support from bangbang93.')
#Synchronize The Last Forge Builds.
log('[INFO]:Starting synchronize the last forge builds.')
synchronize('http://bmclapi2.bangbang93.com/forge/last','forge/last/index.html')
#Synchronize The Versions List Of Minecraft Which Were Supported By Forge.
log('[INFO]:Starting synchronize the versions list of minecraft which were supported by forfge.')
synchronize('http://bmclapi2.bangbang93.com/forge/minecraft','forge/minecraft/index.html')
#Synchronize The Different Number Of Builds List Of Forge.
log('[INFO]:Starting synchronize the different number of builds list of forge.')
count=0
for i in range(0,500):
count=count+1
synchronize('http://bmclapi2.bangbang93.com/forge/list/'+str(count), 'forge/list/'+str(count)+'/index.html')
#Synchronize The Forge Builds List With Different MC Versions.
log('[INFO]:Starting synchronize the forge builds list with different mc versions.')
supportlist=httpget('http://bmclapi2.bangbang93.com/forge/minecraft')
number=supportlist.count(',')
supportlistjson=json.loads(supportlist)
count=0
for i in range(0,number):
count=count+1
version=supportlistjson[count]
synchronize('http://bmclapi2.bangbang93.com/forge/minecraft/'+version, 'forge/minecraft/'+version+'/index.html')
#Synchronize The Forge Builds With Different MC Versions With Build ID.
log('[INFO]:Starting synchronize the forge builds with different mc versions with build ID.')
count=0
for i in range(0,number):
count=count+1
version=supportlistjson[count]
buildswithversion=httpget('http://bmclapi2.bangbang93.com/forge/minecraft/'+version)
buildswithversionjson=json.loads(buildswithversion)
number_sub=buildswithversion.count('build')
count_sub=0
for i in range(0,number_sub):
count_sub=count_sub+1
countforjson=count_sub-1
buildid=buildswithversionjson[countforjson]['build']
if httpget('http://bmclapi2.bangbang93.com/forge/download/'+str(buildid))=="Not Found":
log('[ERROR]:Can not find the file which is synchronizing on BMCLAPI.This may a bug of BMCLAPI,but in most times is not a bug and that is normal.')
elif httpget('http://bmclapi2.bangbang93.com/forge/download/'+str(buildid))=="error":
log('[ERROR]:Can not get the file from BMCLAPI,this may a Internet problem or the server of BMCLAPI is dead.')
else:
synchronize('http://bmclapi2.bangbang93.com/forge/download/'+str(buildid), 'forge/download/'+str(buildid)+'.jar')
#Synchronize The Forge Builds With Different MC Versions.
log('[INFO]:Starting synchronize the forge builds with different mc versions.')
count=0
for i in range(0,number):
count=count+1
version=supportlistjson[count]
versionswithversion=httpget('http://bmclapi2.bangbang93.com/forge/minecraft/'+version)
versionswithversionjson=json.loads(versionswithversion)
number_sub=versionswithversion.count('"version"')
count_sub=0
for i in range(0,number_sub):
count_sub=count_sub+1
countforjson=count_sub-1
versionid=versionswithversionjson[countforjson]['version']
#Installer Part.
if httpget('http://bmclapi2.bangbang93.com/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-installer.jar')=="Not Found":
log('[ERROR]:Can not find the file which is synchronizing on BMCLAPI.This may a bug of BMCLAPI,but in most times is not a bug and that is normal.')
elif httpget('http://bmclapi2.bangbang93.com/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-installer.jar')=="error":
log('[ERROR]:Can not get the file from BMCLAPI,this may a Internet problem or the server of BMCLAPI is dead.')
else:
synchronize('http://bmclapi2.bangbang93.com/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-installer.jar', 'forge/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-installer.jar')
#Launcher Part.
if httpget('http://bmclapi2.bangbang93.com/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-launcher.jar')=="Not Found":
log('[ERROR]:Can not find the file which is synchronizing on BMCLAPI.This may a bug of BMCLAPI,but in most times is not a bug and that is normal.')
elif httpget('http://bmclapi2.bangbang93.com/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-launcher.jar')=="error":
log('[ERROR]:Can not get the file from BMCLAPI,this may a Internet problem or the server of BMCLAPI is dead.')
else:
synchronize('http://bmclapi2.bangbang93.com/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-launcher.jar', 'forge/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-launcher.jar')
#Sources Part.
if httpget('http://bmclapi2.bangbang93.com/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-sources.jar')=="Not Found":
log('[ERROR]:Can not find the file which is synchronizing on BMCLAPI.This may a bug of BMCLAPI,but in most times is not a bug and that is normal.')
elif httpget('http://bmclapi2.bangbang93.com/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-sources.jar')=="error":
log('[ERROR]:Can not get the file from BMCLAPI,this may a Internet problem or the server of BMCLAPI is dead.')
else:
synchronize('http://bmclapi2.bangbang93.com/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-sources.jar', 'forge/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-sources.jar')
#Universal Part.
if httpget('http://bmclapi2.bangbang93.com/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-universal.jar')=="Not Found":
log('[ERROR]:Can not find the file which is synchronizing on BMCLAPI.This may a bug of BMCLAPI,but in most times is not a bug and that is normal.')
elif httpget('http://bmclapi2.bangbang93.com/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-universal.jar')=="error":
log('[ERROR]:Can not get the file from BMCLAPI,this may a Internet problem or the server of BMCLAPI is dead.')
else:
synchronize('http://bmclapi2.bangbang93.com/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-universal.jar', 'forge/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-universal.jar')
#MDK Part.
if httpget('http://bmclapi2.bangbang93.com/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-mdk.zip')=="Not Found":
log('[ERROR]:Can not find the file which is synchronizing on BMCLAPI.This may a bug of BMCLAPI,but in most times is not a bug and that is normal.')
elif httpget('http://bmclapi2.bangbang93.com/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-mdk.zip')=="error":
log('[ERROR]:Can not get the file from BMCLAPI,this may a Internet problem or the server of BMCLAPI is dead.')
else:
synchronize('http://bmclapi2.bangbang93.com/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-mdk.zip', 'forge/maven/net/minecraftforge/forge/'+version+'-'+str(versionid)+'/forge-'+version+'-'+str(versionid)+'-mdk.zip')
log('[INFO]:Synchronizing forge builds list from BMCLAPI successfully.')
#------------------------------------------------------------------------#
Log=Log + '------------------------------------------------------------------------' + '\n'
#Starting To Save Logs.
log('[INFO]:Starting to save logs.')
logwrite=open(os.path.dirname(os.path.abspath(sys.argv[0])) + '/' + config['logspath'] + 'part3-' + str(time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime()) + '.txt'),mode='w')
logwrite.write(Log + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:Save logs successfully.' + '\n' + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[INFO]:All tasks of synchronizing have done successfully.')
logwrite.close()

39
old/5.0.0/download.py Normal file
View 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
View 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
View 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())))