diff --git a/download.py b/download.py index 1407ad9..1db41dd 100644 --- a/download.py +++ b/download.py @@ -1,12 +1,13 @@ import os,requests,json,time,sys,argparse,psutil Log="" -UA={'User-Agent':'GeMCAPI/5.0.0 (GeMC API Sync 5.0.0;Release)'} +UA={'User-Agent':'GeMCAPI/6.0.0 (GeMC API Sync 6.0.0;Release)'} parser=argparse.ArgumentParser() -parser.add_argument("--url", help="The online url of the file which need to download.") -parser.add_argument("--file", help="The file path of the file which need to download.") -parser.add_argument("--other", help="Other parameter which help some special file to download correctly.") +parser.add_argument("--url") +parser.add_argument("--file") +parser.add_argument("--type") +parser.add_argument("--type_sub") parser=parser.parse_args() -proxies={'http':'http://127.0.0.1:4780'} +proxies={'http':'http://127.0.0.1:4780'}#Proxy Setting def log(log_type,logvar): global Log if(log_type=="info"): @@ -16,14 +17,69 @@ def log(log_type,logvar): elif(log_type=="error"): log_type="ERROR" Log=Log + '\n' + '[' + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ']' + '[' + log_type + ']' + logvar +def is_json(url): + global Log + global UA + global proxies + online_return=requests.get(url, headers=UA, proxies=proxies).text + try: + json.loads(online_return) + return True + except: + return False def download(url, dirpath): global Log global UA + global proxies + global last_dirpath + global return_format + global return_headers log("info",'We are downloading the file ' + dirpath + '.') + return_headers=requests.get(url, headers=UA, proxies=proxies).headers['content-type'] + last_dirpath='' + make_dir_exist('file/' + parser.file[::-1].split('/', 1)[-1][::-1]) try: - download=requests.get(url, headers=UA, proxies=proxies) - with open(dirpath,"wb") as code: - code.write(download.content) + if(return_headers=="application/json"): + return_format="json" + if('.json' in dirpath): + download=requests.get(url, headers=UA, proxies=proxies) + with open(dirpath,"wb") as code: + code.write(download.content) + else: + make_dir_exist(dirpath) + download=requests.get(url, headers=UA, proxies=proxies) + with open(dirpath + '/index.json',"wb") as code: + code.write(download.content) + last_dirpath='/index.json' + elif(return_headers=="application/json; charset=utf-8"): + return_format="json" + if('.json' in dirpath): + download=requests.get(url, headers=UA, proxies=proxies) + with open(dirpath,"wb") as code: + code.write(download.content) + else: + make_dir_exist(dirpath) + download=requests.get(url, headers=UA, proxies=proxies) + with open(dirpath + '/index.json',"wb") as code: + code.write(download.content) + last_dirpath='/index.json' + elif(return_headers=="application/java-archive"): + return_format="jar" + if('.jar' in dirpath): + download=requests.get(url, headers=UA, proxies=proxies) + with open(dirpath,"wb") as code: + code.write(download.content) + else: + make_dir_exist(dirpath) + download=requests.get(url, headers=UA, proxies=proxies) + with open(dirpath + '/index.jar',"wb") as code: + code.write(download.content) + last_dirpath='/index.jar' + else: + return_format="" + download=requests.get(url, headers=UA, proxies=proxies) + with open(dirpath,"wb") as code: + code.write(download.content) except: log("error",'There has a error in task while downloading the file ' + dirpath + '.') else: @@ -35,5 +91,9 @@ def make_dir_exist(dirpath): else: log("info",'The dir ' + dirpath + ' does not exist.We will create one.') os.makedirs(dirpath) -make_dir_exist(parser.file[::-1].split('/', 1)[-1][::-1]) -download(parser.url,parser.file) \ No newline at end of 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() \ No newline at end of file diff --git a/file/forge/list/10/index.json b/file/forge/list/10/index.json new file mode 100644 index 0000000..19f0074 --- /dev/null +++ b/file/forge/list/10/index.json @@ -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}] \ No newline at end of file diff --git a/file/liteloader/dl/versions/versions.json b/file/liteloader/dl/versions/versions.json new file mode 100644 index 0000000..03e5c12 --- /dev/null +++ b/file/liteloader/dl/versions/versions.json @@ -0,0 +1,1149 @@ +{ + "meta":{ + "description":"LiteLoader is a lightweight mod bootstrap designed to provide basic loader functionality for mods which don't need to modify game mechanics.", + "authors":"Mumfrey", + "url":"http:\/\/dl.liteloader.com", + "updated":"2017-11-29T16:31:41+00:00", + "updatedTime":1511973101 + }, + "versions":{ + "1.10":{ + "repo":{ + "stream":"SNAPSHOT", + "type":"m2", + "url":"http:\/\/repo.mumfrey.com\/content\/repositories\/snapshots\/", + "classifier":"" + }, + "snapshots":{ + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.12" + }, + { + "name":"org.spongepowered:mixin:0.5.10-SNAPSHOT", + "url":"https:\/\/repo.spongepowered.org\/maven\/" + } + ], + "com.mumfrey:liteloader":{ + "5e732dc446f9fe2abe5f9decaec40cde":{ + "tweakClass":"com.mumfrey.liteloader.launch.LiteLoaderTweaker", + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.12" + }, + { + "name":"org.ow2.asm:asm-all:5.0.3" + } + ], + "stream":"SNAPSHOT", + "file":"liteloader-1.10-SNAPSHOT.jar", + "version":"1.10-SNAPSHOT", + "build":"1.10-SNAPSHOT-rB840010-b4-4", + "md5":"5e732dc446f9fe2abe5f9decaec40cde", + "timestamp":"1469695346", + "lastSuccessfulBuild":4 + }, + "latest":{ + "tweakClass":"com.mumfrey.liteloader.launch.LiteLoaderTweaker", + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.12" + }, + { + "name":"org.ow2.asm:asm-all:5.0.3" + } + ], + "stream":"SNAPSHOT", + "file":"liteloader-1.10-SNAPSHOT.jar", + "version":"1.10-SNAPSHOT", + "build":"1.10-SNAPSHOT-rB840010-b4-4", + "md5":"5e732dc446f9fe2abe5f9decaec40cde", + "timestamp":"1469695346", + "lastSuccessfulBuild":4 + } + } + }, + "dev":{ + "fgVersion":"2.2", + "mappings":"snapshot_custom" + } + }, + "1.10.2":{ + "repo":{ + "stream":"RELEASE", + "type":"m2", + "url":"http:\/\/dl.liteloader.com\/repo\/", + "classifier":"" + }, + "artefacts":{ + "com.mumfrey:liteloader":{ + "8a7c21f32d77ee08b393dd3921ced8eb":{ + "tweakClass":"com.mumfrey.liteloader.launch.LiteLoaderTweaker", + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.12" + }, + { + "name":"org.ow2.asm:asm-all:5.0.3" + } + ], + "stream":"RELEASE", + "file":"liteloader-1.10.2.jar", + "version":"1.10.2", + "md5":"8a7c21f32d77ee08b393dd3921ced8eb", + "timestamp":"1479473570" + }, + "latest":{ + "tweakClass":"com.mumfrey.liteloader.launch.LiteLoaderTweaker", + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.12" + }, + { + "name":"org.ow2.asm:asm-all:5.0.3" + } + ], + "stream":"RELEASE", + "file":"liteloader-1.10.2.jar", + "version":"1.10.2", + "md5":"8a7c21f32d77ee08b393dd3921ced8eb", + "timestamp":"1479473570" + } + } + }, + "snapshots":{ + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.12" + }, + { + "name":"org.spongepowered:mixin:0.5.17-SNAPSHOT", + "url":"https:\/\/repo.spongepowered.org\/maven\/" + } + ], + "com.mumfrey:liteloader":{ + "1cdd72f7232e45551f16cc8ffd27ccf3":{ + "tweakClass":"com.mumfrey.liteloader.launch.LiteLoaderTweaker", + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.12" + }, + { + "name":"org.ow2.asm:asm-all:5.0.3" + } + ], + "stream":"SNAPSHOT", + "file":"liteloader-1.10.2-SNAPSHOT.jar", + "version":"1.10.2-SNAPSHOT", + "build":"1.10.2-SNAPSHOT-rE85C8AE-b11-11", + "md5":"1cdd72f7232e45551f16cc8ffd27ccf3", + "timestamp":"1485987183", + "lastSuccessfulBuild":11 + }, + "latest":{ + "tweakClass":"com.mumfrey.liteloader.launch.LiteLoaderTweaker", + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.12" + }, + { + "name":"org.ow2.asm:asm-all:5.0.3" + } + ], + "stream":"SNAPSHOT", + "file":"liteloader-1.10.2-SNAPSHOT.jar", + "version":"1.10.2-SNAPSHOT", + "build":"1.10.2-SNAPSHOT-rE85C8AE-b11-11", + "md5":"1cdd72f7232e45551f16cc8ffd27ccf3", + "timestamp":"1485987183", + "lastSuccessfulBuild":11 + } + } + }, + "dev":{ + "fgVersion":"2.2", + "mappings":"snapshot_20160628" + } + }, + "1.11":{ + "repo":{ + "stream":"SNAPSHOT", + "type":"m2", + "url":"http:\/\/repo.mumfrey.com\/content\/repositories\/snapshots\/", + "classifier":"" + }, + "snapshots":{ + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.12" + }, + { + "name":"org.spongepowered:mixin:0.6.8-SNAPSHOT", + "url":"https:\/\/repo.spongepowered.org\/maven\/" + } + ], + "com.mumfrey:liteloader":{ + "8524af3ac3325a82444cc75ae6e9112f":{ + "tweakClass":"com.mumfrey.liteloader.launch.LiteLoaderTweaker", + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.12" + }, + { + "name":"org.ow2.asm:asm-all:5.0.3" + } + ], + "stream":"SNAPSHOT", + "file":"liteloader-1.11-SNAPSHOT.jar", + "version":"1.11-SNAPSHOT", + "build":"1.11-SNAPSHOT-rC121D7D-b13-13", + "md5":"8524af3ac3325a82444cc75ae6e9112f", + "timestamp":"1502705321", + "lastSuccessfulBuild":13 + }, + "latest":{ + "tweakClass":"com.mumfrey.liteloader.launch.LiteLoaderTweaker", + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.12" + }, + { + "name":"org.ow2.asm:asm-all:5.0.3" + } + ], + "stream":"SNAPSHOT", + "file":"liteloader-1.11-SNAPSHOT.jar", + "version":"1.11-SNAPSHOT", + "build":"1.11-SNAPSHOT-rC121D7D-b13-13", + "md5":"8524af3ac3325a82444cc75ae6e9112f", + "timestamp":"1502705321", + "lastSuccessfulBuild":13 + } + } + }, + "dev":{ + "fgVersion":"2.2", + "mappings":"snapshot_20161124" + } + }, + "1.11.2":{ + "repo":{ + "stream":"SNAPSHOT", + "type":"m2", + "url":"http:\/\/repo.mumfrey.com\/content\/repositories\/snapshots\/", + "classifier":"" + }, + "snapshots":{ + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.12" + }, + { + "name":"org.spongepowered:mixin:0.7.3-SNAPSHOT", + "url":"https:\/\/repo.spongepowered.org\/maven\/" + } + ], + "com.mumfrey:liteloader":{ + "3a98b5ed95810bf164e71c1a53be568d":{ + "tweakClass":"com.mumfrey.liteloader.launch.LiteLoaderTweaker", + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.12" + }, + { + "name":"org.ow2.asm:asm-all:5.0.3" + } + ], + "stream":"SNAPSHOT", + "file":"liteloader-1.11.2-SNAPSHOT.jar", + "version":"1.11.2-SNAPSHOT", + "build":"1.11.2-SNAPSHOT-r09AB166-b13-13", + "md5":"3a98b5ed95810bf164e71c1a53be568d", + "timestamp":"1504543390", + "lastSuccessfulBuild":13 + }, + "latest":{ + "tweakClass":"com.mumfrey.liteloader.launch.LiteLoaderTweaker", + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.12" + }, + { + "name":"org.ow2.asm:asm-all:5.0.3" + } + ], + "stream":"SNAPSHOT", + "file":"liteloader-1.11.2-SNAPSHOT.jar", + "version":"1.11.2-SNAPSHOT", + "build":"1.11.2-SNAPSHOT-r09AB166-b13-13", + "md5":"3a98b5ed95810bf164e71c1a53be568d", + "timestamp":"1504543390", + "lastSuccessfulBuild":13 + } + } + }, + "dev":{ + "fgVersion":"2.2", + "mappings":"snapshot_20161224" + } + }, + "1.12":{ + "repo":{ + "stream":"SNAPSHOT", + "type":"m2", + "url":"http:\/\/repo.mumfrey.com\/content\/repositories\/snapshots\/", + "classifier":"" + }, + "snapshots":{ + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.12" + }, + { + "name":"org.spongepowered:mixin:0.7.3-SNAPSHOT", + "url":"https:\/\/repo.spongepowered.org\/maven\/" + } + ], + "com.mumfrey:liteloader":{ + "61179803bcd5fb7790789b790908663d":{ + "tweakClass":"com.mumfrey.liteloader.launch.LiteLoaderTweaker", + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.12" + }, + { + "name":"org.ow2.asm:asm-all:5.0.3" + } + ], + "stream":"SNAPSHOT", + "file":"liteloader-1.12-SNAPSHOT.jar", + "version":"1.12-SNAPSHOT", + "build":"1.12-SNAPSHOT-r4CA9C4E-b9-9", + "md5":"61179803bcd5fb7790789b790908663d", + "timestamp":"1504543585", + "lastSuccessfulBuild":9 + }, + "latest":{ + "tweakClass":"com.mumfrey.liteloader.launch.LiteLoaderTweaker", + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.12" + }, + { + "name":"org.ow2.asm:asm-all:5.0.3" + } + ], + "stream":"SNAPSHOT", + "file":"liteloader-1.12-SNAPSHOT.jar", + "version":"1.12-SNAPSHOT", + "build":"1.12-SNAPSHOT-r4CA9C4E-b9-9", + "md5":"61179803bcd5fb7790789b790908663d", + "timestamp":"1504543585", + "lastSuccessfulBuild":9 + } + } + }, + "dev":{ + "fgVersion":"2.3", + "mappings":"snapshot_20170627" + } + }, + "1.12.1":{ + "repo":{ + "stream":"SNAPSHOT", + "type":"m2", + "url":"http:\/\/repo.mumfrey.com\/content\/repositories\/snapshots\/", + "classifier":"" + }, + "snapshots":{ + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.12" + }, + { + "name":"org.spongepowered:mixin:0.7.3-SNAPSHOT", + "url":"https:\/\/repo.spongepowered.org\/maven\/" + } + ], + "com.mumfrey:liteloader":{ + "b9bef8abc8dc309069aeba6fbbe58980":{ + "tweakClass":"com.mumfrey.liteloader.launch.LiteLoaderTweaker", + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.12" + }, + { + "name":"org.ow2.asm:asm-all:5.0.3" + } + ], + "stream":"SNAPSHOT", + "file":"liteloader-1.12.1-SNAPSHOT.jar", + "version":"1.12.1-SNAPSHOT", + "build":"1.12.1-SNAPSHOT-r98DC04C-b3-3", + "md5":"b9bef8abc8dc309069aeba6fbbe58980", + "timestamp":"1504543777", + "lastSuccessfulBuild":3 + }, + "latest":{ + "tweakClass":"com.mumfrey.liteloader.launch.LiteLoaderTweaker", + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.12" + }, + { + "name":"org.ow2.asm:asm-all:5.0.3" + } + ], + "stream":"SNAPSHOT", + "file":"liteloader-1.12.1-SNAPSHOT.jar", + "version":"1.12.1-SNAPSHOT", + "build":"1.12.1-SNAPSHOT-r98DC04C-b3-3", + "md5":"b9bef8abc8dc309069aeba6fbbe58980", + "timestamp":"1504543777", + "lastSuccessfulBuild":3 + } + } + }, + "dev":{ + "fgVersion":"2.3", + "mappings":"snapshot_20170804" + } + }, + "1.12.2":{ + "repo":{ + "stream":"SNAPSHOT", + "type":"m2", + "url":"http:\/\/repo.mumfrey.com\/content\/repositories\/snapshots\/", + "classifier":"" + }, + "snapshots":{ + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.12" + }, + { + "name":"org.spongepowered:mixin:0.7.4-SNAPSHOT", + "url":"https:\/\/repo.spongepowered.org\/maven\/" + } + ], + "com.mumfrey:liteloader":{ + "1420785ecbfed5aff4a586c5c9dd97eb":{ + "tweakClass":"com.mumfrey.liteloader.launch.LiteLoaderTweaker", + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.12" + }, + { + "name":"org.ow2.asm:asm-all:5.2" + } + ], + "stream":"SNAPSHOT", + "file":"liteloader-1.12.2-SNAPSHOT.jar", + "version":"1.12.2-SNAPSHOT", + "build":"1.12.2-SNAPSHOT-r4CC2BB0-b4-4", + "md5":"1420785ecbfed5aff4a586c5c9dd97eb", + "timestamp":"1511880271", + "lastSuccessfulBuild":4 + }, + "latest":{ + "tweakClass":"com.mumfrey.liteloader.launch.LiteLoaderTweaker", + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.12" + }, + { + "name":"org.ow2.asm:asm-all:5.2" + } + ], + "stream":"SNAPSHOT", + "file":"liteloader-1.12.2-SNAPSHOT.jar", + "version":"1.12.2-SNAPSHOT", + "build":"1.12.2-SNAPSHOT-r4CC2BB0-b4-4", + "md5":"1420785ecbfed5aff4a586c5c9dd97eb", + "timestamp":"1511880271", + "lastSuccessfulBuild":4 + } + } + }, + "dev":{ + "fgVersion":"2.3", + "mappings":"snapshot_20170919" + } + }, + "1.5.2":{ + "repo":{ + "stream":"RELEASE", + "type":"ivy", + "url":"http:\/\/dl.liteloader.com\/versions\/", + "classifier":"mcpnames" + }, + "artefacts":{ + "com.mumfrey:liteloader":{ + "53639d52340479ccf206a04f5e16606f":{ + "tweakClass":"com.mumfrey.liteloader.launch.LiteLoaderTweaker", + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.5" + }, + { + "name":"net.sf.jopt-simple:jopt-simple:4.5" + }, + { + "name":"org.ow2.asm:asm-all:4.1" + } + ], + "stream":"RELEASE", + "file":"liteloader-1.5.2_01.jar", + "version":"1.5.2_01", + "md5":"53639d52340479ccf206a04f5e16606f", + "timestamp":"1367366420" + }, + "latest":{ + "tweakClass":"com.mumfrey.liteloader.launch.LiteLoaderTweaker", + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.5" + }, + { + "name":"net.sf.jopt-simple:jopt-simple:4.5" + }, + { + "name":"org.ow2.asm:asm-all:4.1" + } + ], + "stream":"RELEASE", + "file":"liteloader-1.5.2.jar", + "version":"1.5.2_01", + "md5":"53639d52340479ccf206a04f5e16606f", + "timestamp":"1367366420" + } + } + }, + "dev":{ + "mcp":"true" + } + }, + "1.6.2":{ + "repo":{ + "stream":"RELEASE", + "type":"ivy", + "url":"http:\/\/dl.liteloader.com\/versions\/", + "classifier":"mcpnames" + }, + "artefacts":{ + "com.mumfrey:liteloader":{ + "b52f90f08303edd3d4c374e268a5acf1":{ + "tweakClass":"com.mumfrey.liteloader.launch.LiteLoaderTweaker", + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.3" + } + ], + "stream":"RELEASE", + "file":"liteloader-1.6.2_04.jar", + "version":"1.6.2_04", + "md5":"b52f90f08303edd3d4c374e268a5acf1", + "timestamp":"1375662298" + }, + "ea747e24e03e24b7cad5bc8a246e0319":{ + "tweakClass":"com.mumfrey.liteloader.launch.LiteLoaderTweaker", + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.3" + } + ], + "stream":"RELEASE", + "file":"liteloader-1.6.2_01.jar", + "version":"1.6.2_01", + "md5":"ea747e24e03e24b7cad5bc8a246e0319", + "timestamp":"1374025480" + }, + "10a15b52fc59b1bfb9c05b56de1097d6":{ + "tweakClass":"com.mumfrey.liteloader.launch.LiteLoaderTweaker", + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.3" + } + ], + "stream":"RELEASE", + "file":"liteloader-1.6.2_02.jar", + "version":"1.6.2_02", + "md5":"10a15b52fc59b1bfb9c05b56de1097d6", + "timestamp":"1374709543" + }, + "073f68e2fcb518b91fd0d99462441714":{ + "tweakClass":"com.mumfrey.liteloader.launch.LiteLoaderTweaker", + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.3" + } + ], + "stream":"RELEASE", + "file":"liteloader-1.6.2_03.jar", + "version":"1.6.2_03", + "md5":"073f68e2fcb518b91fd0d99462441714", + "timestamp":"1375228794" + }, + "latest":{ + "tweakClass":"com.mumfrey.liteloader.launch.LiteLoaderTweaker", + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.3" + } + ], + "stream":"RELEASE", + "file":"liteloader-1.6.2.jar", + "version":"1.6.2_04", + "md5":"b52f90f08303edd3d4c374e268a5acf1", + "timestamp":"1375662298" + } + } + }, + "dev":{ + "mcp":"true" + } + }, + "1.6.4":{ + "repo":{ + "stream":"RELEASE", + "type":"ivy", + "url":"http:\/\/dl.liteloader.com\/versions\/", + "classifier":"mcpnames" + }, + "artefacts":{ + "com.mumfrey:liteloader":{ + "531c116f71ae2b11033f9a11a0f8e668":{ + "tweakClass":"com.mumfrey.liteloader.launch.LiteLoaderTweaker", + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.8" + } + ], + "stream":"RELEASE", + "file":"liteloader-1.6.4_01.jar", + "version":"1.6.4_01", + "md5":"531c116f71ae2b11033f9a11a0f8e668", + "timestamp":"1380796916" + }, + "1fcdcf66ce0a0806b7ad8686afdce3f7":{ + "tweakClass":"com.mumfrey.liteloader.launch.LiteLoaderTweaker", + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.8" + } + ], + "stream":"RELEASE", + "file":"liteloader-1.6.4_00.jar", + "version":"1.6.4_00", + "md5":"1fcdcf66ce0a0806b7ad8686afdce3f7", + "timestamp":"1380279938" + }, + "latest":{ + "tweakClass":"com.mumfrey.liteloader.launch.LiteLoaderTweaker", + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.8" + } + ], + "stream":"RELEASE", + "file":"liteloader-1.6.4.jar", + "version":"1.6.4_01", + "md5":"531c116f71ae2b11033f9a11a0f8e668", + "timestamp":"1380796916" + } + } + }, + "dev":{ + "mcp":"true" + } + }, + "1.7.10":{ + "repo":{ + "stream":"RELEASE", + "type":"ivy", + "url":"http:\/\/dl.liteloader.com\/versions\/", + "classifier":"mcpnames" + }, + "artefacts":{ + "com.mumfrey:liteloader":{ + "63ada46e033d0cb6782bada09ad5ca4e":{ + "tweakClass":"com.mumfrey.liteloader.launch.LiteLoaderTweaker", + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.11" + }, + { + "name":"org.ow2.asm:asm-all:5.0.3" + } + ], + "srcJar":"liteloader-1.7.10_04-mcpnames-sources.jar", + "mcpJar":"liteloader-1.7.10_04-mcpnames.jar", + "stream":"RELEASE", + "file":"liteloader-1.7.10_04.jar", + "version":"1.7.10_04", + "md5":"63ada46e033d0cb6782bada09ad5ca4e", + "timestamp":"1414368553" + }, + "db7235aefd407ac1fde09a7baba50839":{ + "tweakClass":"com.mumfrey.liteloader.launch.LiteLoaderTweaker", + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.9" + }, + { + "name":"org.ow2.asm:asm-all:5.0.3", + "url":"http:\/\/repo.maven.apache.org\/maven2\/" + } + ], + "stream":"RELEASE", + "file":"liteloader-1.7.10_00.jar", + "version":"1.7.10_00", + "md5":"db7235aefd407ac1fde09a7baba50839", + "timestamp":"1404330030" + }, + "55785ccc82c07ff0ba038fe24be63ea2":{ + "tweakClass":"com.mumfrey.liteloader.launch.LiteLoaderTweaker", + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.9" + }, + { + "name":"org.ow2.asm:asm-all:4.1" + } + ], + "stream":"RELEASE", + "file":"liteloader-1.7.10_01.jar", + "version":"1.7.10_01", + "md5":"55785ccc82c07ff0ba038fe24be63ea2", + "timestamp":"1404673785" + }, + "c09882458d74fe0697c7681b8993097e":{ + "tweakClass":"com.mumfrey.liteloader.launch.LiteLoaderTweaker", + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.9" + }, + { + "name":"org.ow2.asm:asm-all:4.1" + } + ], + "srcJar":"liteloader-1.7.10_02-mcpnames-sources.jar", + "mcpJar":"liteloader-1.7.10_02-mcpnames.jar", + "stream":"RELEASE", + "file":"liteloader-1.7.10_02.jar", + "version":"1.7.10_02", + "md5":"c09882458d74fe0697c7681b8993097e", + "timestamp":"1405369406" + }, + "7983e4b28217c9ae8569074388409c86":{ + "tweakClass":"com.mumfrey.liteloader.launch.LiteLoaderTweaker", + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.9" + }, + { + "name":"org.ow2.asm:asm-all:4.1" + } + ], + "srcJar":"liteloader-1.7.10_03-mcpnames-sources.jar", + "mcpJar":"liteloader-1.7.10_03-mcpnames.jar", + "stream":"RELEASE", + "file":"liteloader-1.7.10_03.jar", + "version":"1.7.10_03", + "md5":"7983e4b28217c9ae8569074388409c86", + "timestamp":"1407687918" + }, + "latest":{ + "tweakClass":"com.mumfrey.liteloader.launch.LiteLoaderTweaker", + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.11" + }, + { + "name":"org.ow2.asm:asm-all:5.0.3" + } + ], + "stream":"RELEASE", + "file":"liteloader-1.7.10.jar", + "version":"1.7.10_04", + "md5":"63ada46e033d0cb6782bada09ad5ca4e", + "timestamp":"1414368553", + "srcJar":"liteloader-1.7.10_04-mcpnames-sources.jar", + "mcpJar":"liteloader-1.7.10_04-mcpnames.jar" + } + } + }, + "dev":{ + "mcp":"true" + } + }, + "1.7.2":{ + "repo":{ + "stream":"RELEASE", + "type":"ivy", + "url":"http:\/\/dl.liteloader.com\/versions\/", + "classifier":"mcpnames" + }, + "artefacts":{ + "com.mumfrey:liteloader":{ + "ab554c21f28fbc4ae9b098bcb5f4cceb":{ + "tweakClass":"com.mumfrey.liteloader.launch.LiteLoaderTweaker", + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.9" + }, + { + "name":"org.ow2.asm:asm-all:4.1" + } + ], + "stream":"RELEASE", + "file":"liteloader-1.7.2_05.jar", + "version":"1.7.2_05", + "md5":"ab554c21f28fbc4ae9b098bcb5f4cceb", + "timestamp":"1405369406" + }, + "e1d76a05a3723920e2f80a5e66c45f16":{ + "tweakClass":"com.mumfrey.liteloader.launch.LiteLoaderTweaker", + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.9" + }, + { + "name":"org.ow2.asm:asm-all:4.1" + } + ], + "stream":"RELEASE", + "file":"liteloader-1.7.2_02.jar", + "version":"1.7.2_02", + "md5":"e1d76a05a3723920e2f80a5e66c45f16", + "timestamp":"1391815963" + }, + "4009eeb99c9068f608d3483a6439af88":{ + "tweakClass":"com.mumfrey.liteloader.launch.LiteLoaderTweaker", + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.9" + }, + { + "name":"org.ow2.asm:asm-all:4.1" + } + ], + "stream":"RELEASE", + "file":"liteloader-1.7.2_03.jar", + "version":"1.7.2_03", + "md5":"4009eeb99c9068f608d3483a6439af88", + "timestamp":"1391890695" + }, + "66f343354b8417abce1a10d557d2c6e9":{ + "tweakClass":"com.mumfrey.liteloader.launch.LiteLoaderTweaker", + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.9" + }, + { + "name":"org.ow2.asm:asm-all:4.1" + } + ], + "srcJar":"liteloader-1.7.2_04-mcpnames-sources.jar", + "mcpJar":"liteloader-1.7.2_04-mcpnames.jar", + "stream":"RELEASE", + "file":"liteloader-1.7.2_04.jar", + "version":"1.7.2_04", + "md5":"66f343354b8417abce1a10d557d2c6e9", + "timestamp":"1392487926" + }, + "latest":{ + "tweakClass":"com.mumfrey.liteloader.launch.LiteLoaderTweaker", + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.9" + }, + { + "name":"org.ow2.asm:asm-all:4.1" + } + ], + "stream":"RELEASE", + "file":"liteloader-1.7.2.jar", + "version":"1.7.2_05", + "md5":"ab554c21f28fbc4ae9b098bcb5f4cceb", + "timestamp":"1405369406" + } + } + }, + "dev":{ + "mcp":"true" + } + }, + "1.8":{ + "repo":{ + "stream":"RELEASE", + "type":"ivy", + "url":"http:\/\/dl.liteloader.com\/versions\/", + "classifier":"mcpnames" + }, + "artefacts":{ + "com.mumfrey:liteloader":{ + "6e9028816027f53957bd8fcdfabae064":{ + "tweakClass":"com.mumfrey.liteloader.launch.LiteLoaderTweaker", + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.11" + }, + { + "name":"org.ow2.asm:asm-all:5.0.3" + } + ], + "srcJar":"liteloader-1.8-mcpnames-sources.jar", + "mcpJar":"liteloader-1.8-mcpnames.jar", + "stream":"RELEASE", + "file":"liteloader-1.8.jar", + "version":"1.8", + "md5":"6e9028816027f53957bd8fcdfabae064", + "timestamp":"1463585254" + }, + "latest":{ + "tweakClass":"com.mumfrey.liteloader.launch.LiteLoaderTweaker", + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.11" + }, + { + "name":"org.ow2.asm:asm-all:5.0.3" + } + ], + "srcJar":"liteloader-1.8-mcpnames-sources.jar", + "mcpJar":"liteloader-1.8-mcpnames.jar", + "stream":"RELEASE", + "file":"liteloader-1.8.jar", + "version":"1.8", + "md5":"6e9028816027f53957bd8fcdfabae064", + "timestamp":"1463585254" + } + } + }, + "dev":{ + "fgVersion":"2.1", + "mappings":"snapshot_20151124" + } + }, + "1.8.9":{ + "repo":{ + "stream":"SNAPSHOT", + "type":"m2", + "url":"http:\/\/repo.mumfrey.com\/content\/repositories\/snapshots\/", + "classifier":"" + }, + "snapshots":{ + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.11" + }, + { + "name":"org.spongepowered:mixin:0.5.3-SNAPSHOT", + "url":"https:\/\/repo.spongepowered.org\/maven\/" + } + ], + "com.mumfrey:liteloader":{ + "ba8e6285966d7d988a96496f48cbddaa":{ + "tweakClass":"com.mumfrey.liteloader.launch.LiteLoaderTweaker", + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.11" + }, + { + "name":"org.ow2.asm:asm-all:5.0.3" + } + ], + "stream":"SNAPSHOT", + "file":"liteloader-1.8.9-SNAPSHOT.jar", + "version":"1.8.9-SNAPSHOT", + "build":"1.8.9-SNAPSHOT-r08134E7-b8-2016-04-14_16-33-58", + "md5":"ba8e6285966d7d988a96496f48cbddaa", + "timestamp":"1460644538", + "lastSuccessfulBuild":8 + }, + "latest":{ + "tweakClass":"com.mumfrey.liteloader.launch.LiteLoaderTweaker", + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.11" + }, + { + "name":"org.ow2.asm:asm-all:5.0.3" + } + ], + "stream":"SNAPSHOT", + "file":"liteloader-1.8.9-SNAPSHOT.jar", + "version":"1.8.9-SNAPSHOT", + "build":"1.8.9-SNAPSHOT-r08134E7-b8-2016-04-14_16-33-58", + "md5":"ba8e6285966d7d988a96496f48cbddaa", + "timestamp":"1460644538", + "lastSuccessfulBuild":8 + } + } + }, + "dev":{ + "fgVersion":"2.1", + "mappings":"snapshot_20160204" + } + }, + "1.9":{ + "repo":{ + "stream":"SNAPSHOT", + "type":"m2", + "url":"http:\/\/repo.mumfrey.com\/content\/repositories\/snapshots\/", + "classifier":"" + }, + "snapshots":{ + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.11" + }, + { + "name":"org.spongepowered:mixin:0.5.5-SNAPSHOT", + "url":"https:\/\/repo.spongepowered.org\/maven\/" + } + ], + "com.mumfrey:liteloader":{ + "00318cb0c787934d523f63cdfe8ddde4":{ + "tweakClass":"com.mumfrey.liteloader.launch.LiteLoaderTweaker", + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.11" + }, + { + "name":"org.ow2.asm:asm-all:5.0.3" + } + ], + "stream":"SNAPSHOT", + "file":"liteloader-1.9-SNAPSHOT.jar", + "version":"1.9-SNAPSHOT", + "build":"1.9-SNAPSHOT-r089CAB5-b23-23", + "md5":"00318cb0c787934d523f63cdfe8ddde4", + "timestamp":"1463945095", + "lastSuccessfulBuild":23 + }, + "latest":{ + "tweakClass":"com.mumfrey.liteloader.launch.LiteLoaderTweaker", + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.11" + }, + { + "name":"org.ow2.asm:asm-all:5.0.3" + } + ], + "stream":"SNAPSHOT", + "file":"liteloader-1.9-SNAPSHOT.jar", + "version":"1.9-SNAPSHOT", + "build":"1.9-SNAPSHOT-r089CAB5-b23-23", + "md5":"00318cb0c787934d523f63cdfe8ddde4", + "timestamp":"1463945095", + "lastSuccessfulBuild":23 + } + } + }, + "dev":{ + "fgVersion":"2.1", + "mappings":"snapshot_20160411" + } + }, + "1.9.4":{ + "repo":{ + "stream":"RELEASE", + "type":"m2", + "url":"http:\/\/dl.liteloader.com\/repo\/", + "classifier":"" + }, + "artefacts":{ + "com.mumfrey:liteloader":{ + "571ad5e6edd5ff40259570c9be588bb5":{ + "tweakClass":"com.mumfrey.liteloader.launch.LiteLoaderTweaker", + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.12" + }, + { + "name":"org.ow2.asm:asm-all:5.0.3" + } + ], + "stream":"RELEASE", + "file":"liteloader-1.9.4.jar", + "version":"1.9.4", + "md5":"571ad5e6edd5ff40259570c9be588bb5", + "timestamp":"1479472002" + }, + "latest":{ + "tweakClass":"com.mumfrey.liteloader.launch.LiteLoaderTweaker", + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.12" + }, + { + "name":"org.ow2.asm:asm-all:5.0.3" + } + ], + "stream":"RELEASE", + "file":"liteloader-1.9.4.jar", + "version":"1.9.4", + "md5":"571ad5e6edd5ff40259570c9be588bb5", + "timestamp":"1479472002" + } + } + }, + "snapshots":{ + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.12" + }, + { + "name":"org.spongepowered:mixin:0.5.6-SNAPSHOT", + "url":"https:\/\/repo.spongepowered.org\/maven\/" + } + ], + "com.mumfrey:liteloader":{ + "986fd1ee9525cb0dcab7609401cef754":{ + "tweakClass":"com.mumfrey.liteloader.launch.LiteLoaderTweaker", + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.12" + }, + { + "name":"org.ow2.asm:asm-all:5.0.3" + } + ], + "stream":"SNAPSHOT", + "file":"liteloader-1.9.4-SNAPSHOT.jar", + "version":"1.9.4-SNAPSHOT", + "build":"1.9.4-SNAPSHOT-r84EA1AB-b18-18", + "md5":"986fd1ee9525cb0dcab7609401cef754", + "timestamp":"1465835329", + "lastSuccessfulBuild":18 + }, + "latest":{ + "tweakClass":"com.mumfrey.liteloader.launch.LiteLoaderTweaker", + "libraries":[ + { + "name":"net.minecraft:launchwrapper:1.12" + }, + { + "name":"org.ow2.asm:asm-all:5.0.3" + } + ], + "stream":"SNAPSHOT", + "file":"liteloader-1.9.4-SNAPSHOT.jar", + "version":"1.9.4-SNAPSHOT", + "build":"1.9.4-SNAPSHOT-r84EA1AB-b18-18", + "md5":"986fd1ee9525cb0dcab7609401cef754", + "timestamp":"1465835329", + "lastSuccessfulBuild":18 + } + } + }, + "dev":{ + "fgVersion":"2.1", + "mappings":"snapshot_20160517" + } + } + } +} \ No newline at end of file diff --git a/index.php b/index.php index 0a7399e..69a5318 100644 --- a/index.php +++ b/index.php @@ -1,262 +1,195 @@ 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"); } } } -} \ No newline at end of file +} diff --git a/logs/2020-08-25-18-23-56.txt b/logs/2020-08-25-18-23-56.txt new file mode 100644 index 0000000..fe33f54 --- /dev/null +++ b/logs/2020-08-25-18-23-56.txt @@ -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. \ No newline at end of file diff --git a/logs/2020-08-25-18-24-59.txt b/logs/2020-08-25-18-24-59.txt new file mode 100644 index 0000000..00b0199 --- /dev/null +++ b/logs/2020-08-25-18-24-59.txt @@ -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. \ No newline at end of file diff --git a/logs/2020-08-25-18-52-34.txt b/logs/2020-08-25-18-52-34.txt new file mode 100644 index 0000000..e933ce6 --- /dev/null +++ b/logs/2020-08-25-18-52-34.txt @@ -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. \ No newline at end of file diff --git a/logs/2020-08-25-18-52-56.txt b/logs/2020-08-25-18-52-56.txt new file mode 100644 index 0000000..9b0ba86 --- /dev/null +++ b/logs/2020-08-25-18-52-56.txt @@ -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. \ No newline at end of file diff --git a/logs/2020-08-25-18-53-06.txt b/logs/2020-08-25-18-53-06.txt new file mode 100644 index 0000000..fca0518 --- /dev/null +++ b/logs/2020-08-25-18-53-06.txt @@ -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. \ No newline at end of file diff --git a/logs/2020-08-25-22-09-47.txt b/logs/2020-08-25-22-09-47.txt new file mode 100644 index 0000000..5aa9516 --- /dev/null +++ b/logs/2020-08-25-22-09-47.txt @@ -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. \ No newline at end of file diff --git a/synchronize/v2.3.0/synchronize.py b/old/2.3.0/synchronize.py similarity index 98% rename from synchronize/v2.3.0/synchronize.py rename to old/2.3.0/synchronize.py index d8bb2a9..c24a0f6 100644 --- a/synchronize/v2.3.0/synchronize.py +++ b/old/2.3.0/synchronize.py @@ -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() diff --git a/rqdeal/index.php b/old/3.2.0/rqdeal/index.php similarity index 100% rename from rqdeal/index.php rename to old/3.2.0/rqdeal/index.php diff --git a/rqdeal/logs/.keep b/old/3.2.0/rqdeal/logs/.keep similarity index 100% rename from rqdeal/logs/.keep rename to old/3.2.0/rqdeal/logs/.keep diff --git a/rqdeal/文件跳转功能已经废弃 b/old/3.2.0/rqdeal/文件跳转功能已经废弃 similarity index 100% rename from rqdeal/文件跳转功能已经废弃 rename to old/3.2.0/rqdeal/文件跳转功能已经废弃 diff --git a/rqdeal/请自行修改文件内数据库设置 b/old/3.2.0/rqdeal/请自行修改文件内数据库设置 similarity index 100% rename from rqdeal/请自行修改文件内数据库设置 rename to old/3.2.0/rqdeal/请自行修改文件内数据库设置 diff --git a/rqdeal/配套数据库.gz b/old/3.2.0/rqdeal/配套数据库.gz similarity index 100% rename from rqdeal/配套数据库.gz rename to old/3.2.0/rqdeal/配套数据库.gz diff --git a/synchronize/synchronize.py b/old/3.2.0/synchronize/synchronize.py similarity index 98% rename from synchronize/synchronize.py rename to old/3.2.0/synchronize/synchronize.py index 7f6940d..9e8bdb2 100644 --- a/synchronize/synchronize.py +++ b/old/3.2.0/synchronize/synchronize.py @@ -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() diff --git a/synchronize/synchronize/config.json b/old/3.2.0/synchronize/synchronize/config.json similarity index 96% rename from synchronize/synchronize/config.json rename to old/3.2.0/synchronize/synchronize/config.json index 19042e4..7d32816 100644 --- a/synchronize/synchronize/config.json +++ b/old/3.2.0/synchronize/synchronize/config.json @@ -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/" } \ No newline at end of file diff --git a/synchronize/synchronize/part1.py b/old/3.2.0/synchronize/synchronize/part1.py similarity index 98% rename from synchronize/synchronize/part1.py rename to old/3.2.0/synchronize/synchronize/part1.py index aa3ab39..16999fa 100644 --- a/synchronize/synchronize/part1.py +++ b/old/3.2.0/synchronize/synchronize/part1.py @@ -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() diff --git a/synchronize/synchronize/part2.py b/old/3.2.0/synchronize/synchronize/part2.py similarity index 98% rename from synchronize/synchronize/part2.py rename to old/3.2.0/synchronize/synchronize/part2.py index 520cfe0..85d6e54 100644 --- a/synchronize/synchronize/part2.py +++ b/old/3.2.0/synchronize/synchronize/part2.py @@ -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() diff --git a/synchronize/synchronize/part3.py b/old/3.2.0/synchronize/synchronize/part3.py similarity index 98% rename from synchronize/synchronize/part3.py rename to old/3.2.0/synchronize/synchronize/part3.py index 53d8863..f33e05c 100644 --- a/synchronize/synchronize/part3.py +++ b/old/3.2.0/synchronize/synchronize/part3.py @@ -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() diff --git a/synchronize/传统文件定时同步已被废弃 b/old/3.2.0/synchronize/传统文件定时同步已被废弃 similarity index 100% rename from synchronize/传统文件定时同步已被废弃 rename to old/3.2.0/synchronize/传统文件定时同步已被废弃 diff --git a/old/5.0.0/download.py b/old/5.0.0/download.py new file mode 100644 index 0000000..1407ad9 --- /dev/null +++ b/old/5.0.0/download.py @@ -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) \ No newline at end of file diff --git a/old/5.0.0/index.php b/old/5.0.0/index.php new file mode 100644 index 0000000..836175e --- /dev/null +++ b/old/5.0.0/index.php @@ -0,0 +1,270 @@ +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'); + } + } + } +} \ No newline at end of file diff --git a/test.py b/test.py new file mode 100644 index 0000000..ce20777 --- /dev/null +++ b/test.py @@ -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()))) \ No newline at end of file