Jump to content

Download plugins directly from uMod.org


Dennis

Recommended Posts

I threw together a quick script for Python that allows your clients to install mods directly from TCAdmin by inputting a URL.

 

 

import sys
sys.path.append(ThisServer.CustomField1)
sys.path.append(ThisServer.CustomField2)
import clr;
clr.AddReference("TCAdmin.SDK")
from TCAdmin.SDK.Misc import WebClient;
import bs4
import urllib, urlparse, os

wc = WebClient();
site = str(ThisService.Variables['umodurl'])
split = urlparse.urlsplit(site)
filename = str(ThisService.RootDirectory) + '\oxide\\plugins\\' + split.path.split("/")[-1]
if ".cs" in site:
 wc.DownloadFile(site, filename);
 Script.WriteToConsole('The plugin was downloaded successfully')
else:
 try:
   wc = WebClient();
   html=wc.DownloadData(site);
   only_copyurl_tags = bs4.SoupStrainer('a', {"class":"btn btn-primary btn-block"})
   soup = bs4.BeautifulSoup(html.encode('utf-8'), 'html.parser', parse_only=only_copyurl_tags)
   for a in soup.find_all('a', href=True)[0:1]:
     download_link = a['href']
 except:
   Script.WriteToConsole('Couldn\'t parse URL. Please contact support.')
 
 modname = download_link.replace('https://umod.org/plugins/', '')
 try:
   with open(str(ThisService.RootDirectory) + '\oxide\\plugins\\' + modname, 'wb') as output:
     output.write(wc.DownloadData(download_link))
 except:
   Script.WriteToConsole('Failed to download\nfile from ' + download_link + '.\nTrying another URL...')
   try:
     os.remove(str(ThisService.RootDirectory) + '\oxide\\plugins\\' + modname)
     filename = str(ThisService.RootDirectory) + '\oxide\\plugins\\' + split.path.split("/")[-1] +'.cs'
     wc.DownloadFile(site + '.cs', filename)
     Script.WriteToConsole('The plugin was downloaded successfully')
   except:
     Script.WriteToConsole('Couldn\'t download the plugin.\nPlease contact support')

A few things to note:

- Install Python 2.7 on your server and go to Servers > Custom Fields. In Custom Field 1, input the path to the Python 2.7 library on your server (like C:\Python27\Lib)

- Install BeautifulSoup4 on your server and go to Servers > Custom Fields. In Custom Field 2, input the path to the BeautifulSoup4 library on your server (like C:\beautifulsoup4-4.1.0\)

- You need to create a variable called 'umodurl'. To avoid cases where your client enters an incorrect URL, use regex validation like so: ^https\:\/\/umod\.org\/plugins\/[a-zA-Z0-9-#]+(.cs)?

- Remember to set the script to ask for variables

 

 

 

Clients can both enter the URL for the plugin page (eg. https://umod.org/plugins/absolut-gifts) and for the plugin download (eg. https://umod.org/plugins/AbsolutGifts.cs).

In some cases the script will fail when the client enters the link for the plugin page, and in this case the script will try to append '.cs' and see if that works.

Link to comment
Share on other sites

  • 1 year later...

I prefere just to link directly to the latest download that way i can setup configuration files etc, i have message support to include an Updater feature, however in the latest update you have to provide a version number, this makes updating a pain, the update button should appear constantly and it just downloads the latest. This method is nice, it just lacks in UI side (being able to manage plugin produce configs in Configuration Files).

Link to comment
Share on other sites

  • 6 months later...

i am having issue where im gettimg 

No module named bs4
No module named bs4

i have searched for bs4 on the server and found this location /usr/lib/python2.7/dist-packages/bs4 so i put that into the scrpts and still get the error. any help is appreciated

Link to comment
Share on other sites

On 11/19/2020 at 8:23 PM, numpty said:

i am having issue where im gettimg 


No module named bs4

No module named bs4

i have searched for bs4 on the server and found this location /usr/lib/python2.7/dist-packages/bs4 so i put that into the scrpts and still get the error. any help is appreciated

Turn /usr/lib/python2.7/dist-packages/bs4

into

/usr/lib/python2.7/dist-packages/

That's what worked for me.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Who's Online   0 Members, 0 Anonymous, 6 Guests (See full list)

    • There are no registered users currently online
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Terms of Use