mirror of
https://github.com/Neocky/pluGET.git
synced 2024-04-29 16:12:30 +00:00
Renamed folder to src\; Added new input system and added a specific plugin downloader for testing
This commit is contained in:
91
src/consoleoutput.py
Normal file
91
src/consoleoutput.py
Normal file
@@ -0,0 +1,91 @@
|
||||
# Handles the console output
|
||||
from os import system
|
||||
from os import name
|
||||
|
||||
def consoleTitle():
|
||||
system("title " + "pluGET │ by Neocky")
|
||||
|
||||
|
||||
def clearConsole():
|
||||
system('cls' if name=='nt' else 'clear')
|
||||
|
||||
|
||||
# https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences
|
||||
class oColors:
|
||||
standardWhite = "\033[0m"
|
||||
brightYellow = "\033[93m"
|
||||
brightMagenta = "\033[95m"
|
||||
brightRed = "\033[91m"
|
||||
darkMagenta = "\033[35m"
|
||||
|
||||
|
||||
def printLogo():
|
||||
print()
|
||||
print(oColors.brightYellow + r" ___ ___ ___ ___ ___ ___ ")
|
||||
print(oColors.brightMagenta + r" /\ " + oColors.brightYellow + r"\ " + oColors.brightMagenta + r"/"'\\' +
|
||||
oColors.brightYellow + r"__\ " + oColors.brightMagenta + r"/"'\\' + oColors.brightYellow + r"__\ " +
|
||||
oColors.brightMagenta + r"/\ "+ oColors.brightYellow + r"\ " + oColors.brightMagenta + r"/\ "+
|
||||
oColors.brightYellow + r"\ " + oColors.brightMagenta + r"/\ "+ oColors.brightYellow + r""'\\ ')
|
||||
print(oColors.brightMagenta + r" /::\ "+ oColors.brightYellow + r"\ " + oColors.brightMagenta + r"/:/ " +
|
||||
oColors.brightYellow + r"/ " + oColors.brightMagenta + r"/:/ "+ oColors.brightYellow + r"/ " +
|
||||
oColors.brightMagenta + r"/::\ "+ oColors.brightYellow + r"\ " + oColors.brightMagenta + r"/::\ "+
|
||||
oColors.brightYellow + r"\ " + oColors.brightMagenta + r"\:\ "+ oColors.brightYellow + r""'\\ ')
|
||||
print(oColors.brightMagenta + r" /:/\:\ "+ oColors.brightYellow + r"\ " + oColors.brightMagenta + r"/:/ "+
|
||||
oColors.brightYellow + r"/ " + oColors.brightMagenta + r"/:/ "+ oColors.brightYellow + r"/ " +
|
||||
oColors.brightMagenta + r"/:/\:\ "+ oColors.brightYellow + r"\ " + oColors.brightMagenta + r"/:/\:\ "+
|
||||
oColors.brightYellow + r"\ " + oColors.brightMagenta + r"\:\ "+ oColors.brightYellow + r""'\\ ')
|
||||
print(oColors.brightMagenta + r" /::"'\\' + oColors.brightYellow + r"~" + oColors.brightMagenta + r"\:\ "+
|
||||
oColors.brightYellow + r"\ " + oColors.brightMagenta + r"/:/ "+ oColors.brightYellow + r"/ " +
|
||||
oColors.brightMagenta + r"/:/ "+ oColors.brightYellow + r"/ ___ " + oColors.brightMagenta + r"/:/ \:\ "+
|
||||
oColors.brightYellow + r"\ " + oColors.brightMagenta + r"/::"'\\'+ oColors.brightYellow + r"~" +
|
||||
oColors.brightMagenta + r"\:\ "+ oColors.brightYellow + r"\ " + oColors.brightMagenta + r"/::\ "+
|
||||
oColors.brightYellow + r""'\\')
|
||||
print(oColors.brightMagenta + r" /:/\:\ \:"'\\'+ oColors.brightYellow + r"__\ " + oColors.brightMagenta + r"/:/"+
|
||||
oColors.brightYellow + r"__/ " + oColors.brightMagenta + r"/:/"+ oColors.brightYellow + r"__/ " +
|
||||
oColors.brightMagenta + r"/"'\\'+ oColors.brightYellow + r"__\ " + oColors.brightMagenta + r"/:/"+
|
||||
oColors.brightYellow + r"__/_" + oColors.brightMagenta + r"\:"'\\'+ oColors.brightYellow + r"__\ " +
|
||||
oColors.brightMagenta + r"/:/\:\ \:"'\\' + oColors.brightYellow + r"__\ " +
|
||||
oColors.brightMagenta + r"/:/\:"'\\'+ oColors.brightYellow + r"__\ ")
|
||||
print(oColors.brightMagenta + r" " + oColors.brightMagenta + r"\/"+ oColors.brightYellow + r"__" +
|
||||
oColors.brightMagenta + r"\:\/:/"+ oColors.brightYellow + r" / " + oColors.brightMagenta + r"\:"'\\'+
|
||||
oColors.brightYellow + r" \ " + oColors.brightMagenta + r"\:"'\\' + oColors.brightYellow + r" \ " +
|
||||
oColors.brightMagenta + r"/:/ "+ oColors.brightYellow + r"/ " + oColors.brightMagenta + r"\:\ /\ \/" +
|
||||
oColors.brightYellow + r"__/ " + oColors.brightMagenta + r"\:"'\\' + oColors.brightYellow + r"~" +
|
||||
oColors.brightMagenta + r"\:\ \/" + oColors.brightYellow + r"__/ " + oColors.brightMagenta + r"/:/ \/"+
|
||||
oColors.brightYellow + r"__/")
|
||||
print(oColors.brightMagenta + r" \::/ "+ oColors.brightYellow + r"/ " + oColors.brightMagenta + r"\:\ "+
|
||||
oColors.brightYellow + r"\ " + oColors.brightMagenta + r"\:\ /:/ "+ oColors.brightYellow + r"/ " +
|
||||
oColors.brightMagenta + r"\:\ \:"'\\'+ oColors.brightYellow + r"__\ " + oColors.brightMagenta + r"\:\ \:"'\\'+
|
||||
oColors.brightYellow + r"__\ " + oColors.brightMagenta + r"/:/ "+ oColors.brightYellow + r"/ ")
|
||||
print(oColors.brightMagenta + r" \/"+ oColors.brightYellow + r"__/ " +
|
||||
oColors.brightMagenta + r"\:\ " + oColors.brightYellow + r"\ " + oColors.brightMagenta + r"\:\/:/ "+
|
||||
oColors.brightYellow + r"/ " + oColors.brightMagenta + r"\:\/:/ "+ oColors.brightYellow + r"/ " +
|
||||
oColors.brightMagenta + r"\:\ \/"+ oColors.brightYellow + r"__/ " + oColors.brightMagenta + r"\/"+
|
||||
oColors.brightYellow + r"__/ ")
|
||||
print(oColors.brightMagenta + r" \:"'\\' + oColors.brightYellow + r"__\ " +
|
||||
oColors.brightMagenta + r"\::/ " + oColors.brightYellow + r"/ " + oColors.brightMagenta + r"\::/ " +
|
||||
oColors.brightYellow + r"/ " + oColors.brightMagenta + r"\:"'\\' + oColors.brightYellow + r"__\ ")
|
||||
print(oColors.brightMagenta + r" \/" + oColors.brightYellow + r"__/ " +
|
||||
oColors.brightMagenta + r"\/" + oColors.brightYellow + r"__/ " + oColors.brightMagenta + r"\/" +
|
||||
oColors.brightYellow + r"__/ " + oColors.brightMagenta + r"\/" + oColors.brightYellow + r"__/ " +
|
||||
oColors.standardWhite)
|
||||
print()
|
||||
print()
|
||||
print(oColors.brightYellow + " [" + oColors.darkMagenta + "by Neocky" +
|
||||
oColors.brightYellow + "] " + oColors.standardWhite)
|
||||
print()
|
||||
|
||||
|
||||
def printHorizontalLine():
|
||||
print(" ─────────────────────────────────────────────────────────────────────────────────")
|
||||
|
||||
|
||||
def printMainMenu():
|
||||
printLogo()
|
||||
printHorizontalLine()
|
||||
#print(" [1] Download a specific 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()
|
83
src/handle_input.py
Normal file
83
src/handle_input.py
Normal file
@@ -0,0 +1,83 @@
|
||||
import time
|
||||
from consoleoutput import consoleTitle, clearConsole, printMainMenu
|
||||
from plugin_downloader import downloadPackageManual, apiCallTest, searchPackage, getLatestPackageVersionInteractive, getPackageVersion
|
||||
from plugin_updatechecker import getInstalledPackages
|
||||
from web_request import createCloudScraperInstance#, CLOUDSCRAPER
|
||||
|
||||
|
||||
|
||||
def handleInput(inputCommand, inputSelectedObject, inputParams="latest"):
|
||||
if inputCommand == 'get':
|
||||
getPackageVersion(inputSelectedObject, inputParams, r"C:\\Users\USER\Desktop\\")
|
||||
|
||||
|
||||
|
||||
def getInput():
|
||||
inputCommand, inputSelectedObject, *inputParams = input("pluGET >> ").split()
|
||||
inputParams = inputParams[0] if inputParams else ''
|
||||
print(inputCommand)
|
||||
print(inputSelectedObject)
|
||||
print(inputParams)
|
||||
handleInput(inputCommand, inputSelectedObject,inputParams)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def inputOption(inputOptionString):
|
||||
inputString = None
|
||||
print(inputOptionString)
|
||||
if inputOptionString == 1:
|
||||
inputString = input("SpigotMC Ressource ID: ")
|
||||
if inputOptionString == 2:
|
||||
inputString = input("SpigotMC Ressource ID: ")
|
||||
if inputOptionString == 3:
|
||||
inputString = input(" SpigotMC Ressource Name: ")
|
||||
print("ich bin ein test")
|
||||
return inputString
|
||||
|
||||
|
||||
def handleInputOLD(inputString):
|
||||
if inputString == "1":
|
||||
downloadPackageManual()
|
||||
if inputString == "2":
|
||||
ressourceId = inputOption(2)
|
||||
apiCallTest(ressourceId)
|
||||
if inputString == "3":
|
||||
ressourceName = inputOption(3)
|
||||
searchPackage(ressourceName)
|
||||
if inputString == "4":
|
||||
getLatestPackageVersionInteractive(r"C:\\Users\USER\Desktop\\")
|
||||
if inputString == "5":
|
||||
getInstalledPackages('C:\\Users\\USER\\Desktop\\plugins')
|
||||
|
||||
|
||||
def inputMainMenu():
|
||||
clearConsole()
|
||||
printMainMenu()
|
||||
getInput()
|
||||
#inputSt = input(" pluGET >> ")
|
||||
#handleInputOLD(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...")
|
||||
|
||||
|
||||
createCloudScraperInstance()
|
||||
consoleTitle()
|
||||
inputMainMenu()
|
||||
outputTest()
|
203
src/plugin_downloader.py
Normal file
203
src/plugin_downloader.py
Normal file
@@ -0,0 +1,203 @@
|
||||
import urllib.request
|
||||
import cgi
|
||||
import re
|
||||
import cloudscraper
|
||||
from web_request import doAPIRequest
|
||||
|
||||
|
||||
def calculateFileSize(downloadFileSize):
|
||||
fileSizeDownload = int(downloadFileSize)
|
||||
fileSizeKb = fileSizeDownload / 1024
|
||||
roundedFileSize = round(fileSizeKb, 2)
|
||||
return roundedFileSize
|
||||
|
||||
|
||||
# 28140 for Luckperms (Testing only)
|
||||
def downloadPackageManual():
|
||||
ressourceId = input("SpigotMC Ressource ID: ")
|
||||
|
||||
url = "https://api.spiget.org/v2/resources/" + ressourceId + "/download"
|
||||
#url2 = "https://api.spiget.org/v2/resources/" + ressourceId + "/versions/latest/download"
|
||||
#print(url2)
|
||||
#user_agent = 'Mozilla/5.0 (X11; U; Linux i686) Gecko/20071127 Firefox/2.0.0.11'
|
||||
#header = { 'User-agent': 'Mozilla/5.0 (X11; U; Linux i686) Gecko/20071127 Firefox/2.0.0.11', 'Accept-Encoding': 'gzip, deflate, br' }
|
||||
#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
|
||||
path = r"C:\\Users\Jan-Luca\Desktop\\"
|
||||
ppath = path + filename
|
||||
|
||||
# download file
|
||||
urllib.request.urlretrieve(url, ppath)
|
||||
|
||||
filesizeData = calculateFileSize(filesize)
|
||||
print(f"Downloadsize: {filesizeData} MB")
|
||||
|
||||
|
||||
# 89273
|
||||
def handleRegexPackageName(packageNameFull):
|
||||
packageNameFull2 = packageNameFull
|
||||
# trims the part of the package that has for example "[1.1 Off]" in it
|
||||
unwantedpackageName = re.search(r'(^\[+[a-zA-Z0-9\s\W*\.*\-*\+*\%*\,]*\]+)', packageNameFull)
|
||||
unwantedpackageNamematch = bool(unwantedpackageName)
|
||||
if unwantedpackageNamematch:
|
||||
unwantedpackageNameString = unwantedpackageName.group()
|
||||
packageNameFull2 = packageNameFull.replace(unwantedpackageNameString, '')
|
||||
print(packageNameFull2)
|
||||
print("packageNameFull2")
|
||||
|
||||
# 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):
|
||||
url = f"https://api.spiget.org/v2/resources/{packageId}/versions/latest"
|
||||
response = doAPIRequest(url)
|
||||
packageVersion = response["name"]
|
||||
return packageVersion
|
||||
|
||||
|
||||
def apiCallTest(ressourceId):
|
||||
url = f"https://api.spiget.org/v2/resources/{ressourceId}"
|
||||
response = doAPIRequest(url)
|
||||
print(response)
|
||||
packageName = response["name"]
|
||||
packageTag = response["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 getVersionID(packageId, packageVersion):
|
||||
url = f"https://api.spiget.org/v2/resources/{packageId}/versions?size=100&sort=-name"
|
||||
versionList = doAPIRequest(url)
|
||||
|
||||
for packages in versionList:
|
||||
packageUpdate = packages["name"]
|
||||
versionId = packages["id"]
|
||||
if packageUpdate == packageVersion:
|
||||
return versionId
|
||||
return versionList[0]["id"]
|
||||
|
||||
def getVersionName(packageId, versionId):
|
||||
url = f"https://api.spiget.org/v2/resources/{packageId}/versions/{versionId}"
|
||||
response = doAPIRequest(url)
|
||||
versionName = response["name"]
|
||||
return versionName
|
||||
|
||||
|
||||
def searchPackage(ressourceName):
|
||||
url = f"https://api.spiget.org/v2/search/resources/{ressourceName}?field=name"
|
||||
packageName = doAPIRequest(url)
|
||||
print(url)
|
||||
i = 1
|
||||
print("Index / Name / Description / Downloads")
|
||||
for ressource in packageName:
|
||||
pName = ressource["name"]
|
||||
pTag = ressource["tag"]
|
||||
pDownloads = ressource["downloads"]
|
||||
print(f" [{i}] {pName} / {pTag}/ {pDownloads}")
|
||||
i = i + 1
|
||||
|
||||
ressourceSelected = int(input(" Select your wanted Ressource: "))
|
||||
ressourceSelected = ressourceSelected - 1
|
||||
fileInfo = packageName[ressourceSelected]["file"]
|
||||
packageUrl = fileInfo["url"]
|
||||
ressourceId = packageName[ressourceSelected]["id"]
|
||||
print(packageUrl)
|
||||
print(ressourceId)
|
||||
|
||||
|
||||
def downloadLatestVersion(ressourceId, packageDownloadName, sourcePath):
|
||||
url = f"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(filesizeData)
|
||||
print(filesize)
|
||||
print(f" Downloadsize: {filesizeData} KB")
|
||||
|
||||
def downloadSpecificVersion(ressourceId, packageDownloadName, versionId, sourcePath):
|
||||
url = f"https://spigotmc.org/resources/{ressourceId}/download?version={versionId}"
|
||||
#url = f"https://api.spiget.org/v2/resources/{ressourceId}/versions/{versionId}/download"
|
||||
downloadPath = sourcePath + packageDownloadName
|
||||
|
||||
|
||||
#local_filename = url.split('/')[-1]
|
||||
# NOTE the stream=True parameter below
|
||||
with CLOUDSCRAPER.get(url, stream=True) as r:
|
||||
#r.raise_for_status()
|
||||
with open(downloadPath, 'wb') as fd:
|
||||
for chunk in r.iter_content(chunk_size=128):
|
||||
fd.write(chunk)
|
||||
#return downloadPath
|
||||
|
||||
|
||||
#remotefile = urllib.request.urlopen(url)
|
||||
#cloudscraper.requests.get()
|
||||
#filesize = remotefile.info()['Content-Length']
|
||||
|
||||
#urllib.request.urlretrieve(url, downloadPath)
|
||||
#filesizeData = calculateFileSize(filesize)
|
||||
#print(filesizeData)
|
||||
#print(filesize)
|
||||
#print(f" Downloadsize: {filesizeData} KB")
|
||||
|
||||
|
||||
def getPackageVersion(ressourceId, packageVersion, downloadPath):
|
||||
#ressourceId = input(" SpigotMC Ressource ID: ")
|
||||
CLOUDSCRAPER = createCloudScraperInstance()
|
||||
url = f"https://api.spiget.org/v2/resources/{ressourceId}"
|
||||
packageDetails = doAPIRequest(url)
|
||||
packageName = packageDetails["name"]
|
||||
#packageTag = packageDetails["tag"]
|
||||
packageNameNew = handleRegexPackageName(packageName)
|
||||
versionId = getVersionID(ressourceId, packageVersion)
|
||||
packageVersion = getVersionName(ressourceId, versionId)
|
||||
#packageVersion = getlatestVersion(ressourceId)
|
||||
packageDownloadName = f"{packageNameNew}-{packageVersion}.jar"
|
||||
downloadSpecificVersion(ressourceId, packageDownloadName, versionId, downloadPath)
|
||||
|
||||
|
||||
def getLatestPackageVersionInteractive(downloadPath):
|
||||
ressourceId = input(" SpigotMC Ressource ID: ")
|
||||
url = f"https://api.spiget.org/v2/resources/{ressourceId}"
|
||||
packageDetails = doAPIRequest(url)
|
||||
packageName = packageDetails["name"]
|
||||
#packageTag = packageDetails["tag"]
|
||||
packageNameNew = handleRegexPackageName(packageName)
|
||||
packageVersion = getlatestVersion(ressourceId)
|
||||
packageDownloadName = f"{packageNameNew}-{packageVersion}.jar"
|
||||
downloadLatestVersion(ressourceId, packageDownloadName, downloadPath)
|
||||
|
||||
def createCloudScraperInstance():
|
||||
global CLOUDSCRAPER
|
||||
CLOUDSCRAPER = cloudscraper.create_scraper(interpreter='nodejs',debug=True) # returns a CloudScraper instance
|
||||
return CLOUDSCRAPER
|
||||
|
||||
# get latest update > https://api.spiget.org/v2/resources/28140/updates/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 cloudflare protected
|
||||
# query for a plugin https://api.spiget.org/v2/search/resources/luckperms?field=name
|
114
src/plugin_updatechecker.py
Normal file
114
src/plugin_updatechecker.py
Normal file
@@ -0,0 +1,114 @@
|
||||
import os
|
||||
import re
|
||||
|
||||
from consoleoutput import oColors #consoleTitle, clearConsole
|
||||
from plugin_downloader import getPackageVersion #handleInput
|
||||
from web_request import doAPIRequest
|
||||
|
||||
|
||||
def createPluginList():
|
||||
global INSTALLEDPLUGINLIST
|
||||
INSTALLEDPLUGINLIST = []
|
||||
return INSTALLEDPLUGINLIST
|
||||
|
||||
|
||||
def addToPluginList(pluginId, versionId, plugin_is_outdated):
|
||||
INSTALLEDPLUGINLIST.append([pluginId, versionId, plugin_is_outdated])
|
||||
|
||||
|
||||
def getFileName(pluginName):
|
||||
pluginNameFull = pluginName
|
||||
pluginVersion = re.search(r'([\d.]+[.jar]+)', pluginNameFull)
|
||||
pluginVersionFull = pluginVersion.group()
|
||||
pluginNameOnly = pluginNameFull.replace(pluginVersionFull, '')
|
||||
pluginNameOnly = re.sub(r'(\-$)', '', pluginNameOnly)
|
||||
return pluginNameOnly
|
||||
|
||||
|
||||
def getFileVersion(pluginName):
|
||||
#pluginVersionString = None
|
||||
pluginNameFull = pluginName
|
||||
pluginVersion = re.search(r'([\d.]+[.jar]+)', pluginNameFull)
|
||||
pluginVersionFull = pluginVersion.group()
|
||||
pluginVersionString = pluginVersionFull.replace('.jar', '')
|
||||
return pluginVersionString
|
||||
|
||||
|
||||
def compareVersions(pluginId, pluginVersion):
|
||||
url = f"https://api.spiget.org/v2/resources/{pluginId}/versions/latest"
|
||||
latestUpdateSearch = doAPIRequest(url)
|
||||
versionLatestUpdate = latestUpdateSearch["name"]
|
||||
print(pluginVersion)
|
||||
print(versionLatestUpdate)
|
||||
if pluginVersion != versionLatestUpdate:
|
||||
plugin_is_outdated = True
|
||||
else:
|
||||
plugin_is_outdated = False
|
||||
return plugin_is_outdated
|
||||
|
||||
|
||||
def getInstalledPackages(pluginFolderPath):
|
||||
createPluginList()
|
||||
pluginList = os.listdir(pluginFolderPath)
|
||||
print(pluginList)
|
||||
i = 0
|
||||
for plugin in pluginList:
|
||||
print(plugin)
|
||||
fileName = getFileName(plugin)
|
||||
fileVersion = getFileVersion(plugin)
|
||||
pluginId = getInstalledPlugin(fileName, fileVersion)
|
||||
|
||||
print(f"name: {fileName}")
|
||||
print(f"version: {fileVersion}")
|
||||
|
||||
print(INSTALLEDPLUGINLIST)
|
||||
|
||||
if pluginId == None:
|
||||
print(oColors.brightRed + "Couldn't find plugin id. Sorry :(" + oColors.standardWhite)
|
||||
continue
|
||||
if INSTALLEDPLUGINLIST[i][2] == True:
|
||||
os.remove(f"C:\\Users\\USER\\Desktop\\plugins\\{plugin}")
|
||||
getLatestPackageVersion(pluginId, r"C:\\Users\\USER\\Desktop\\plugins\\")
|
||||
i = i + 1
|
||||
print(INSTALLEDPLUGINLIST[1][0])
|
||||
#getLatestPackageVersion(pluginID, r"C:\\Users\USER\Desktop\\plugins\\")
|
||||
|
||||
|
||||
def getInstalledPlugin(localFileName, localFileVersion):
|
||||
url = "https://api.spiget.org/v2/search/resources/" + localFileName + "?field=name"
|
||||
packageName = doAPIRequest(url)
|
||||
print("https://api.spiget.org/v2/search/resources/" + localFileName + "?field=name")
|
||||
#packageName = response.json()
|
||||
i = 1
|
||||
plugin_match_found = False
|
||||
pluginID = None
|
||||
for ressource in packageName:
|
||||
if plugin_match_found == True:
|
||||
break
|
||||
pName = ressource["name"]
|
||||
pID = ressource["id"]
|
||||
print(f" [{i}] {pName} - {pID}")
|
||||
url2 = f"https://api.spiget.org/v2/resources/{pID}/versions?size=100&sort=-name"
|
||||
packageVersions = doAPIRequest(url2)
|
||||
for updates in packageVersions:
|
||||
updateVersion = updates["name"]
|
||||
if localFileVersion == updateVersion:
|
||||
plugin_match_found = True
|
||||
pluginID = pID
|
||||
updateId = updates["id"]
|
||||
plugin_is_outdated = compareVersions(pID, updateVersion)
|
||||
addToPluginList(pID, updateId, plugin_is_outdated)
|
||||
print(updateId)
|
||||
print(pID)
|
||||
print("Found match")
|
||||
break
|
||||
i = i + 1
|
||||
return pluginID
|
||||
|
||||
|
||||
# start query
|
||||
# get id
|
||||
# search with id for all version upates
|
||||
# get version that matches installed version
|
||||
# if match then download latest update
|
||||
# else get second query
|
16
src/web_request.py
Normal file
16
src/web_request.py
Normal file
@@ -0,0 +1,16 @@
|
||||
# Handles the web requests
|
||||
import requests
|
||||
import cloudscraper
|
||||
#import urllib.request
|
||||
|
||||
|
||||
def doAPIRequest(url):
|
||||
headers = {'user-agent': 'pluGET'}
|
||||
response = requests.get(url, headers=headers)
|
||||
packageDetails = response.json()
|
||||
return packageDetails
|
||||
|
||||
def createCloudScraperInstance():
|
||||
global CLOUDSCRAPER
|
||||
CLOUDSCRAPER = cloudscraper.create_scraper() # returns a CloudScraper instance
|
||||
return CLOUDSCRAPER
|
Reference in New Issue
Block a user