diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..3232d14 --- /dev/null +++ b/requirements.txt @@ -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 \ No newline at end of file diff --git a/pluGET/consoleoutput.py b/src/consoleoutput.py similarity index 94% rename from pluGET/consoleoutput.py rename to src/consoleoutput.py index cb38135..b2261f7 100644 --- a/pluGET/consoleoutput.py +++ b/src/consoleoutput.py @@ -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() \ No newline at end of file diff --git a/pluGET/handle_input.py b/src/handle_input.py similarity index 67% rename from pluGET/handle_input.py rename to src/handle_input.py index f120d7b..3d766b9 100644 --- a/pluGET/handle_input.py +++ b/src/handle_input.py @@ -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() diff --git a/pluGET/plugin_downloader.py b/src/plugin_downloader.py similarity index 72% rename from pluGET/plugin_downloader.py rename to src/plugin_downloader.py index 72d7b56..ad4ff2e 100644 --- a/pluGET/plugin_downloader.py +++ b/src/plugin_downloader.py @@ -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 diff --git a/pluGET/plugin_updatechecker.py b/src/plugin_updatechecker.py similarity index 94% rename from pluGET/plugin_updatechecker.py rename to src/plugin_updatechecker.py index 63d0bff..1178625 100644 --- a/pluGET/plugin_updatechecker.py +++ b/src/plugin_updatechecker.py @@ -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 diff --git a/pluGET/web_request.py b/src/web_request.py similarity index 50% rename from pluGET/web_request.py rename to src/web_request.py index 9690137..41cc479 100644 --- a/pluGET/web_request.py +++ b/src/web_request.py @@ -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 \ No newline at end of file