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:
parent
b734c3aa30
commit
e698803c87
5
requirements.txt
Normal file
5
requirements.txt
Normal file
@ -0,0 +1,5 @@
|
||||
urllib3 >= 1.21.1
|
||||
requests >=2.25.1
|
||||
requests_toolbelt >= 0.9.1
|
||||
pyparsing >= 2.4.7
|
||||
cloudscraper >= 1.2.56
|
@ -3,7 +3,7 @@ from os import system
|
||||
from os import name
|
||||
|
||||
def consoleTitle():
|
||||
system("title " + "🧱 pluGET │ by Neocky")
|
||||
system("title " + "pluGET │ by Neocky")
|
||||
|
||||
|
||||
def clearConsole():
|
||||
@ -76,12 +76,16 @@ def printLogo():
|
||||
print()
|
||||
|
||||
|
||||
def printHorizontalLine():
|
||||
print(" ─────────────────────────────────────────────────────────────────────────────────")
|
||||
|
||||
|
||||
def printMainMenu():
|
||||
printLogo()
|
||||
print(" ─────────────────────────────────────────────────────────────────────────────────")
|
||||
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")
|
||||
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()
|
@ -1,7 +1,28 @@
|
||||
import time
|
||||
from consoleoutput import consoleTitle, clearConsole, printMainMenu
|
||||
from plugin_downloader import downloadPackageManual, apiCallTest, searchPackage, getLatestPackageVersionInteractive
|
||||
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):
|
||||
@ -17,7 +38,7 @@ def inputOption(inputOptionString):
|
||||
return inputString
|
||||
|
||||
|
||||
def handleInput(inputString):
|
||||
def handleInputOLD(inputString):
|
||||
if inputString == "1":
|
||||
downloadPackageManual()
|
||||
if inputString == "2":
|
||||
@ -35,8 +56,9 @@ def handleInput(inputString):
|
||||
def inputMainMenu():
|
||||
clearConsole()
|
||||
printMainMenu()
|
||||
inputSt = input(" pluGET >> ")
|
||||
handleInput(inputSt)
|
||||
getInput()
|
||||
#inputSt = input(" pluGET >> ")
|
||||
#handleInputOLD(inputSt)
|
||||
|
||||
|
||||
def outputTest():
|
||||
@ -54,6 +76,8 @@ def outputTest():
|
||||
print("Done ✅☑✔ ")
|
||||
input("Press key to end program...")
|
||||
|
||||
|
||||
createCloudScraperInstance()
|
||||
consoleTitle()
|
||||
inputMainMenu()
|
||||
outputTest()
|
@ -1,6 +1,7 @@
|
||||
import urllib.request
|
||||
import cgi
|
||||
import re
|
||||
import cloudscraper
|
||||
from web_request import doAPIRequest
|
||||
|
||||
|
||||
@ -60,6 +61,7 @@ def handleRegexPackageName(packageNameFull):
|
||||
print("packageNameOnly")
|
||||
return packageNameOnly
|
||||
|
||||
|
||||
def getlatestVersion(packageId):
|
||||
url = f"https://api.spiget.org/v2/resources/{packageId}/versions/latest"
|
||||
response = doAPIRequest(url)
|
||||
@ -86,6 +88,24 @@ def compareVersions():
|
||||
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)
|
||||
@ -119,17 +139,46 @@ def downloadLatestVersion(ressourceId, packageDownloadName, sourcePath):
|
||||
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
|
||||
|
||||
def getLatestPackageVersion(ressourceId, downloadPath):
|
||||
|
||||
#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)
|
||||
packageVersion = getlatestVersion(ressourceId)
|
||||
versionId = getVersionID(ressourceId, packageVersion)
|
||||
packageVersion = getVersionName(ressourceId, versionId)
|
||||
#packageVersion = getlatestVersion(ressourceId)
|
||||
packageDownloadName = f"{packageNameNew}-{packageVersion}.jar"
|
||||
downloadLatestVersion(ressourceId, packageDownloadName, downloadPath)
|
||||
downloadSpecificVersion(ressourceId, packageDownloadName, versionId, downloadPath)
|
||||
|
||||
|
||||
def getLatestPackageVersionInteractive(downloadPath):
|
||||
@ -143,6 +192,10 @@ def getLatestPackageVersionInteractive(downloadPath):
|
||||
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
|
@ -2,7 +2,7 @@ import os
|
||||
import re
|
||||
|
||||
from consoleoutput import oColors #consoleTitle, clearConsole
|
||||
from plugin_downloader import getLatestPackageVersion #handleInput
|
||||
from plugin_downloader import getPackageVersion #handleInput
|
||||
from web_request import doAPIRequest
|
||||
|
||||
|
||||
@ -75,10 +75,8 @@ def getInstalledPackages(pluginFolderPath):
|
||||
|
||||
|
||||
def getInstalledPlugin(localFileName, localFileVersion):
|
||||
#response = requests.get("https://api.spiget.org/v2/search/resources/" + localFileName + "?field=name")
|
||||
url = "https://api.spiget.org/v2/search/resources/" + localFileName + "?field=name"
|
||||
packageName = doAPIRequest(url)
|
||||
#https://api.spiget.org/v2/search/resources/luckperms?field=name
|
||||
print("https://api.spiget.org/v2/search/resources/" + localFileName + "?field=name")
|
||||
#packageName = response.json()
|
||||
i = 1
|
@ -1,4 +1,6 @@
|
||||
# Handles the web requests
|
||||
import requests
|
||||
import cloudscraper
|
||||
#import urllib.request
|
||||
|
||||
|
||||
@ -7,3 +9,8 @@ def doAPIRequest(url):
|
||||
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
|
Loading…
Reference in New Issue
Block a user