mirror of
https://github.com/Neocky/pluGET.git
synced 2024-04-29 16:12:30 +00:00
Code restructure, added latest version download & requirements for update checker
- Everything is now in functions - added download of latest update for plugin - added first things for an update checker
This commit is contained in:
parent
10a19122eb
commit
42732d1ea5
@ -9,6 +9,7 @@ def consoleTitle():
|
|||||||
def clearConsole():
|
def clearConsole():
|
||||||
system('cls' if name=='nt' else 'clear')
|
system('cls' if name=='nt' else 'clear')
|
||||||
|
|
||||||
|
|
||||||
class oColors:
|
class oColors:
|
||||||
standardWhite = "\033[0m"
|
standardWhite = "\033[0m"
|
||||||
brightYellow = "\033[93m"
|
brightYellow = "\033[93m"
|
||||||
@ -77,4 +78,7 @@ def printMainMenu():
|
|||||||
print(" ─────────────────────────────────────────────────────────────────────────────────")
|
print(" ─────────────────────────────────────────────────────────────────────────────────")
|
||||||
print(" [1] Download a specific package")
|
print(" [1] Download a specific package")
|
||||||
print(" [2] Get update info of package")
|
print(" [2] Get update info of package")
|
||||||
|
print(" [3] Search for a plugin")
|
||||||
|
print(" [4] Download latest version of package")
|
||||||
|
print(" [5] Check update for installed plugins")
|
||||||
print()
|
print()
|
@ -1,9 +1,10 @@
|
|||||||
import urllib.request
|
import urllib.request
|
||||||
from urllib.request import urlopen
|
|
||||||
from urllib.request import urlretrieve
|
|
||||||
import cgi
|
import cgi
|
||||||
from consoleoutput import consoleTitle, clearConsole, printMainMenu
|
|
||||||
import time
|
import time
|
||||||
|
import requests
|
||||||
|
import re
|
||||||
|
from consoleoutput import consoleTitle, clearConsole, printMainMenu
|
||||||
|
from plugin_updatechecker import getInstalledPackages
|
||||||
|
|
||||||
|
|
||||||
def calculateFileSize(downloadFileSize):
|
def calculateFileSize(downloadFileSize):
|
||||||
@ -12,56 +13,172 @@ def calculateFileSize(downloadFileSize):
|
|||||||
roundedFileSize = round(fileSizeMb, 2)
|
roundedFileSize = round(fileSizeMb, 2)
|
||||||
return roundedFileSize
|
return roundedFileSize
|
||||||
|
|
||||||
consoleTitle()
|
|
||||||
|
def handleInput(inputString):
|
||||||
|
if inputString == "1":
|
||||||
|
downloadPackageManual()
|
||||||
|
if inputString == "2":
|
||||||
|
apiCallTest()
|
||||||
|
if inputString == "3":
|
||||||
|
searchPackage()
|
||||||
|
if inputString == "4":
|
||||||
|
getLatestPackageVersion()
|
||||||
|
if inputString == "5":
|
||||||
|
getInstalledPackages('C:\\Users\\Jan-Luca\\Desktop\\plugins')
|
||||||
|
|
||||||
|
|
||||||
print("if you see this clearConsole dont work")
|
|
||||||
clearConsole()
|
def inputMainMenu():
|
||||||
printMainMenu()
|
clearConsole()
|
||||||
choice = input(" pluGET >> ")
|
printMainMenu()
|
||||||
if choice == "1":
|
inputSt = input(" pluGET >> ")
|
||||||
ressourceId = input("SpigotMC Ressource ID: ")
|
handleInput(inputSt)
|
||||||
|
|
||||||
|
|
||||||
|
def outputTest():
|
||||||
|
print("Hello world")
|
||||||
|
print("Waiting still seconds: 5", end='\r')
|
||||||
|
time.sleep(1)
|
||||||
|
print("Waiting still seconds: 4", end='\r')
|
||||||
|
time.sleep(1)
|
||||||
|
print("Waiting still seconds: 3", end='\r')
|
||||||
|
time.sleep(1)
|
||||||
|
print("Waiting still seconds: 2", end='\r')
|
||||||
|
time.sleep(1)
|
||||||
|
print("Waiting still seconds: 1", end='\r')
|
||||||
|
time.sleep(1)
|
||||||
|
print("Done ✅☑✔ ")
|
||||||
|
input("Press key to end program...")
|
||||||
|
|
||||||
|
|
||||||
# 28140 for Luckperms (Testing only)
|
# 28140 for Luckperms (Testing only)
|
||||||
url = "https://api.spiget.org/v2/resources/" + ressourceId + "/download"
|
def downloadPackageManual():
|
||||||
print(url)
|
ressourceId = input("SpigotMC Ressource ID: ")
|
||||||
|
|
||||||
# getting original filename
|
url = "https://api.spiget.org/v2/resources/" + ressourceId + "/download"
|
||||||
remotefile = urlopen(url)
|
#url2 = "https://api.spiget.org/v2/resources/" + ressourceId + "/versions/latest/download"
|
||||||
filecontent = remotefile.info()['Content-Disposition']
|
#print(url2)
|
||||||
filesize = remotefile.info()['Content-Length']
|
#user_agent = 'Mozilla/5.0 (X11; U; Linux i686) Gecko/20071127 Firefox/2.0.0.11'
|
||||||
value, params = cgi.parse_header(filecontent)
|
#header = { 'User-agent': 'Mozilla/5.0 (X11; U; Linux i686) Gecko/20071127 Firefox/2.0.0.11', 'Accept-Encoding': 'gzip, deflate, br' }
|
||||||
filename = params["filename"]
|
#req = urllib.request.Request(url2, headers=header)
|
||||||
|
#remotefile = urlopen(req)
|
||||||
|
remotefile = urllib.request.urlopen(url)
|
||||||
|
filecontent = remotefile.info()['Content-Disposition']
|
||||||
|
filesize = remotefile.info()['Content-Length']
|
||||||
|
# getting original filename
|
||||||
|
value, params = cgi.parse_header(filecontent)
|
||||||
|
filename = params["filename"]
|
||||||
|
|
||||||
# creating file path
|
# creating file path
|
||||||
path = r"C:\\Users\USER\Desktop\\"
|
path = r"C:\\Users\Jan-Luca\Desktop\\"
|
||||||
ppath = path + filename
|
ppath = path + filename
|
||||||
|
|
||||||
# download file
|
# download file
|
||||||
urllib.request.urlretrieve(url, ppath)
|
urllib.request.urlretrieve(url, ppath)
|
||||||
|
|
||||||
filesizeData = calculateFileSize(filesize)
|
filesizeData = calculateFileSize(filesize)
|
||||||
print(filesizeData)
|
print(f"Downloadsize: {filesizeData} MB")
|
||||||
|
|
||||||
#print(format(filesizeinmb, '.2f'))
|
|
||||||
|
|
||||||
print("Hello world")
|
# 89273
|
||||||
print("Waiting still seconds: 5", end='\r')
|
def handleRegexPackageName(packageNameFull):
|
||||||
time.sleep(1)
|
packageNameFull2 = packageNameFull
|
||||||
print("Waiting still seconds: 4", end='\r')
|
# trims the part of the package that has for example "[1.1 Off]" in it
|
||||||
time.sleep(1)
|
unwantedpackageName = re.search(r'(^\[+[a-zA-Z0-9\s\W*\.*\-*\+*\%*\,]*\]+)', packageNameFull)
|
||||||
print("Waiting still seconds: 3", end='\r')
|
unwantedpackageNamematch = bool(unwantedpackageName)
|
||||||
time.sleep(1)
|
if unwantedpackageNamematch:
|
||||||
print("Waiting still seconds: 2", end='\r')
|
unwantedpackageNameString = unwantedpackageName.group()
|
||||||
time.sleep(1)
|
packageNameFull2 = packageNameFull.replace(unwantedpackageNameString, '')
|
||||||
print("Waiting still seconds: 1", end='\r')
|
print(packageNameFull2)
|
||||||
time.sleep(1)
|
print("packageNameFull2")
|
||||||
print("Done ✅☑✔ ")
|
|
||||||
input("Press key to end program...")
|
|
||||||
|
|
||||||
|
# gets the real packagename "word1 & word2" is not supported only gets word 1
|
||||||
|
packageName = re.search(r'([a-zA-Z]\d*)+(\s?\-*\_*[a-zA-Z]\d*\+*\-*\'*)+', packageNameFull2)
|
||||||
|
packageNameFullString = packageName.group()
|
||||||
|
packageNameOnly = packageNameFullString.replace(' ', '')
|
||||||
|
print(packageNameOnly)
|
||||||
|
print("packageNameOnly")
|
||||||
|
return packageNameOnly
|
||||||
|
|
||||||
|
def getlatestVersion(packageId):
|
||||||
|
response = requests.get("https://api.spiget.org/v2/resources/" + packageId + "/versions/latest")
|
||||||
|
#packageDetails = response.json()
|
||||||
|
packageVersion = response.json()["name"]
|
||||||
|
return packageVersion
|
||||||
|
|
||||||
|
|
||||||
|
def apiCallTest():
|
||||||
|
ressourceId = input("SpigotMC Ressource ID: ")
|
||||||
|
response = requests.get("https://api.spiget.org/v2/resources/" + ressourceId)
|
||||||
|
packageDetails = response.json()
|
||||||
|
print(packageDetails)
|
||||||
|
packageName = response.json()["name"]
|
||||||
|
packageTag = response.json()["tag"]
|
||||||
|
print(packageName)
|
||||||
|
print(packageTag)
|
||||||
|
packageNameNew = handleRegexPackageName(packageName)
|
||||||
|
print(packageNameNew)
|
||||||
|
|
||||||
|
|
||||||
|
# check version
|
||||||
|
def compareVersions():
|
||||||
|
#https://api.spiget.org/v2/resources/28140/versions/latest
|
||||||
|
# compare latest package version with installed package version
|
||||||
|
print("compareVersions")
|
||||||
|
|
||||||
|
|
||||||
|
def searchPackage():
|
||||||
|
ressourceName = input(" SpigotMC Ressource Name: ")
|
||||||
|
response = requests.get("https://api.spiget.org/v2/search/resources/" + ressourceName + "?field=name")
|
||||||
|
#https://api.spiget.org/v2/search/resources/luckperms?field=name
|
||||||
|
print("https://api.spiget.org/v2/search/resources/" + ressourceName + "?field=name")
|
||||||
|
packageName = response.json()
|
||||||
|
i = 1
|
||||||
|
for ressource in packageName:
|
||||||
|
pName = ressource["name"]
|
||||||
|
print(f" [{i}] {pName}")
|
||||||
|
i = i + 1
|
||||||
|
|
||||||
|
ressourceSelected = int(input(" Select your wanted Ressource: "))
|
||||||
|
ressourceSelected = ressourceSelected - 1
|
||||||
|
fileInfo = response.json()[ressourceSelected]["file"]
|
||||||
|
packageUrl = fileInfo["url"]
|
||||||
|
ressourceId = response.json()[ressourceSelected]["id"]
|
||||||
|
print(packageUrl)
|
||||||
|
print(ressourceId)
|
||||||
|
|
||||||
|
def downloadLatestVersion(ressourceId, packageDownloadName, sourcePath):
|
||||||
|
url = "https://api.spiget.org/v2/resources/" + ressourceId + "/download"
|
||||||
|
remotefile = urllib.request.urlopen(url)
|
||||||
|
filesize = remotefile.info()['Content-Length']
|
||||||
|
downloadPath = sourcePath + packageDownloadName
|
||||||
|
urllib.request.urlretrieve(url, downloadPath)
|
||||||
|
filesizeData = calculateFileSize(filesize)
|
||||||
|
print(f" Downloadsize: {filesizeData} MB")
|
||||||
|
|
||||||
|
|
||||||
|
def getLatestPackageVersion():
|
||||||
|
ressourceId = input(" SpigotMC Ressource ID: ")
|
||||||
|
response = requests.get("https://api.spiget.org/v2/resources/" + ressourceId)
|
||||||
|
packageDetails = response.json()
|
||||||
|
packageName = response.json()["name"]
|
||||||
|
packageTag = response.json()["tag"]
|
||||||
|
packageNameNew = handleRegexPackageName(packageName)
|
||||||
|
packageVersion = getlatestVersion(ressourceId)
|
||||||
|
packageDownloadName = f"{packageNameNew}-{packageVersion}.jar"
|
||||||
|
downloadPath = r"C:\\Users\Jan-Luca\Desktop\\"
|
||||||
|
downloadLatestVersion(ressourceId, packageDownloadName, downloadPath)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
consoleTitle()
|
||||||
|
inputMainMenu()
|
||||||
|
outputTest()
|
||||||
|
|
||||||
|
|
||||||
# get latest update > https://api.spiget.org/v2/resources/28140/updates/latest
|
# get latest update > https://api.spiget.org/v2/resources/28140/updates/latest
|
||||||
# this also > https://api.spiget.org/v2/resources/28140/versions/latest
|
# this also > https://api.spiget.org/v2/resources/28140/versions/latest
|
||||||
# get latest download with correct name > https://api.spiget.org/v2/resources/28140/versions/latest/download
|
# get latest download with correct name > https://api.spiget.org/v2/resources/28140/versions/latest/download cloudflare protected
|
||||||
# query for a plugin https://api.spiget.org/v2/search/resources/luckperms?field=name
|
# query for a plugin https://api.spiget.org/v2/search/resources/luckperms?field=name
|
||||||
|
31
pluGET/plugin_updatechecker.py
Normal file
31
pluGET/plugin_updatechecker.py
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
import os
|
||||||
|
import re
|
||||||
|
|
||||||
|
#from consoleoutput import consoleTitle, clearConsole
|
||||||
|
#from plugin_downloader import handleInput
|
||||||
|
|
||||||
|
|
||||||
|
def getInstalledPackages(pluginFolderPath):
|
||||||
|
pluginList = os.listdir(pluginFolderPath)
|
||||||
|
print(pluginList)
|
||||||
|
for plugin in pluginList:
|
||||||
|
print(plugin)
|
||||||
|
getInstalledPluginVersion(plugin)
|
||||||
|
|
||||||
|
|
||||||
|
def getInstalledPluginVersion(pluginName):
|
||||||
|
pluginNameFull = pluginName
|
||||||
|
pluginVersion = re.search(r'([\d.]+[.jar]+)', pluginNameFull)
|
||||||
|
pluginVersionFull = pluginVersion.group()
|
||||||
|
pluginVersionString = pluginVersionFull.replace('.jar', '')
|
||||||
|
pluginNameOnly = pluginNameFull.replace(pluginVersionFull, '')
|
||||||
|
pluginNameOnly = pluginNameOnly[:-1]
|
||||||
|
print(pluginNameOnly)
|
||||||
|
print(pluginVersionString)
|
||||||
|
|
||||||
|
# start query
|
||||||
|
# get id
|
||||||
|
# search with id for all version upaates
|
||||||
|
# get version that matches installed version
|
||||||
|
# if match then download latest update
|
||||||
|
# else get second query
|
Loading…
Reference in New Issue
Block a user