Skip to content

Commit

Permalink
Add ability to filter plugins (fixes #9)
Browse files Browse the repository at this point in the history
Rather than force people to use one of 3 "bundles" of plugins, instead
do the following:

* If the user specifies a `-p` parameter, filter the plugins to only
  that comma-separated list
* If `-p` is not specified, default to Friends of Galaxy plugins. This
  is controlled via a `default: true` flag in the yaml file

With this new functionality, all yaml files have been merged. I left the
existing files as-is so older clients do not break immediately. In the future
they will be cleaned up.
  • Loading branch information
Slashbunny committed Nov 17, 2019
1 parent 72fd09e commit 7ca45bd
Show file tree
Hide file tree
Showing 7 changed files with 253 additions and 68 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,6 @@ venv.bak/

# mypy
.mypy_cache/

# Testing output directory
output/
68 changes: 35 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,34 @@ The plugins are from Mixaill's excellent [Awesome GOG Galaxy](https://github.com
repository. If you'd like to see a plugin included in this program, please
request it be added to that project _first_.

# Basic Usage
# Basic Installation/Usage

This section is meant for Windows users only. If you are using another OS,
you will need to follow the Advanced instructions below.

* Download the latest release from the [Releases](https://github.com/Slashbunny/gog-galaxy-plugin-downloader/releases) page.
* Extract the zip file anywhere on your PC.
* Within the zip file, there are 3 programs:
* `gog-plugins-downloader-stores`: Downloads and installs plugins for game stores- Steam, Origin, Uplay, Epic, PSN, BattleNet, and more.
* `gog-plugins-downloader-games`: Downloads and installs plugins for single game launchers- Minecraft, Final Fantasy XIV, Path of Exile, Guild Wars 2, and more.
* `gog-plugins-downloader-emulators`: Downloads and installs plugins for emulators- bSNES, RetroArch, Cemu, Dolphin, Citra, mGBA, and more.
* Run the programs of your choice regularly to keep your plugins up to date

This will only work for Windows. If you are using another OS, you will need to
follow the Advanced instructions below.
* Within the zip file, there is a single executable:
* `gog-plugins-downloader.exe`: Downloads and installs all Friends of Galaxy plugins
* If you want to install other plugins, you'll need to create a `.bat` file with the plugins you are interested in (see "Customizing the list..." section below)
* Run the program regularly to keep your plugins up to date

## Install through Scoop

Alternatively, on Windows, [Scoop](https://scoop.sh/) package manager can be used to install and update this tool: `scoop install gog-galaxy-plugin-downloader`.

## Customizing the list of plugins being downloaded

If you want to download a specific set of plugins, refer to the `gog-plugins.bat` file that comes with the
release. Open it in Notepad. Plugins are specified via a comma-separated list, using the `-p` flag. For example:

```
gog-plugins-downloader.exe -p steam,battlenet,humblebundle,ffxiv,gw2,minecraft,poe,snes,nes
```

Change the list to whatever you require and save the `.bat` file. Double click
on the `.bat` file to install or update the list of plugins.

# Advanced Usage

## Requirements
Expand All @@ -47,34 +58,16 @@ Next, install python dependencies:
pip install -r requirements.txt
```

To download Store plugins to Galaxy's "installed" directory on Windows (`%localappdata%\GOG.com\Galaxy\plugins\installed`):
To download default plugins to Galaxy's "installed" directory on Windows (`%localappdata%\GOG.com\Galaxy\plugins\installed`):

```
python download.py
```

### Install Single Game Launcher Plugins

```
python download.py -c https://raw.githubusercontent.com/Slashbunny/gog-galaxy-plugin-downloader/master/plugins-games.yaml
```

or:
### List Available Plugins

```
python download.py -c plugins-games.yaml
```

### Install Emulator Plugins

```
python download.py -c https://raw.githubusercontent.com/Slashbunny/gog-galaxy-plugin-downloader/master/plugins-emulators.yaml
```

or

```
python download.py -c plugins-emulators.yaml
python download.py -l
```

## Custom Parameters
Expand All @@ -93,7 +86,7 @@ For example, on MacOS, to install Store plugins to the default Galaxy plugins fo
python download.py -d "${HOME}/Library/Application Support/GOG.com/Galaxy/plugins/installed/"
```

### Custom Plugins
### Custom Plugin Lists

You can use your own local plugins YAML file like this:

Expand All @@ -107,9 +100,18 @@ Or use your own remote plugins YAML file hosted at any URL:
python download.py -c https://www.mydomain.com/gog-plugins.yaml
```

## Building the Executables
### Filtering Plugins

Rather than install all the plugins referenced in a `yaml` file, you can filter
the list using the `-p` option:

```
python download.py -p battlenet,steam,rockstar,humblebundle
```

## Building the Executable

If you want to build the Windows executables, you can run the following batch
If you want to build the Windows executable, you can run the following batch
files on a Windows PC:

```
Expand Down
4 changes: 1 addition & 3 deletions build-win.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
pip install pyinstaller
pyinstaller download.py -n gog-plugins-downloader-stores --onefile
copy dist\gog-plugins-downloader-stores.exe dist\gog-plugins-downloader-games.exe
copy dist\gog-plugins-downloader-stores.exe dist\gog-plugins-downloader-emulators.exe
pyinstaller download.py -n gog-plugins-downloader --onefile
103 changes: 78 additions & 25 deletions download.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
from urllib.request import urlopen
from urllib.error import URLError

__version__ = '0.0.3'
__version__ = '0.1.0'

# Base URL to plugins
plugin_url = 'https://raw.githubusercontent.com/Slashbunny/' \
'gog-galaxy-plugin-downloader/master/'
default_plugin_url = 'https://raw.githubusercontent.com/Slashbunny/' \
'gog-galaxy-plugin-downloader/master/plugins-all.yaml'


def get_plugin_config(config_uri):
Expand Down Expand Up @@ -46,6 +46,50 @@ def get_plugin_config(config_uri):
print(e)


def list_plugins(plugin_data):
"""
Outputs known plugins, along with whether or not they are marked as default
"""
print('Available plugins:')

for name, data in plugin_data.items():
print(name, end='')

if 'default' in data and data['default'] is True:
print(' [default]')
else:
print()


def filter_plugins(plugin_data, selected_plugins):
"""
Takes the full set of plugin data and filters out only the plugins the
user selected.
If the user did not specify a list of plugins, it enables all the default
plugins
"""
# No plugins selected- remove all plugins not marked as "default"
if selected_plugins is None:
for name, data in list(plugin_data.items()):
if 'default' not in data or data['default'] is not True:
del plugin_data[name]
# Plugin list provided at the command line
else:
selected_plugins = selected_plugins.split(',')
# Ensure each selected plugin actually exists to point out errors
for name in selected_plugins:
if name not in plugin_data.keys():
print('ERROR: Unknown plugin specified: {}'.format(name))
sys.exit(1)
# Remove any plugin not matching the providedlist
for name, data in list(plugin_data.items()):
if name not in selected_plugins:
del plugin_data[name]

return plugin_data


def process_template_strings(data):
"""
Replaces $variables in strings with corresponding variables in plugin data
Expand All @@ -56,6 +100,8 @@ def process_template_strings(data):
for key, value in plugin_data.items():
if key == 'version':
continue
if not isinstance(value, str):
continue

# Replace references to $name and $version with the real values
data[plugin_name][key] = Template(value).substitute(
Expand Down Expand Up @@ -153,39 +199,38 @@ def delete_old_plugins(data, dest):
- Parses command line arguments
- Calls function to fetch/parse plugin config yaml file
- Calls function to filter the plugin list
- Calls function to download plugins
- Calls function to delete old/invalid plugins
"""
# Define script arguments
parser = argparse.ArgumentParser(
description='GOG Galaxy Plugin Downloader')

# OS Default Settings
if os.name == "nt":
# Windows Defaults

# Plugin config default: Depends on which .exe is being run
if sys.argv[0].endswith('-emulators.exe'):
plugins_file = 'plugins-emulators.yaml'
elif sys.argv[0].endswith('-games.exe'):
plugins_file = 'plugins-games.yaml'
else:
plugins_file = 'plugins.yaml'

parser.add_argument('-c', '--conf', default=plugin_url + plugins_file,
help='Path/URL to plugin configuration YAML file')
req_dest = False

# Destination default: %LOCALAPPDATA%\GOG.com\Galaxy\plugins\installed\
plugins_dir = os.path.join(os.environ['localappdata'], 'GOG.com',
'Galaxy', 'plugins', 'installed')

parser.add_argument('-d', '--dest', default=plugins_dir,
help='Destination directory for plugins')
else:
# Non-Windows Defaults
parser.add_argument('-c', '--conf', default=plugin_url + 'plugins.yml',
help='Path/URL to plugin configuration YAML file')
parser.add_argument('-d', '--dest', required=True,
help='Destination directory for plugins')
req_dest = True
plugins_dir = None

# Define script arguments
parser = argparse.ArgumentParser(
description='GOG Galaxy Plugin Downloader')

parser.add_argument('-d', '--dest', default=plugins_dir, required=req_dest,
help='Destination directory for plugins')

parser.add_argument('-c', '--conf', default=default_plugin_url,
help='Path/URL to plugin configuration YAML file')

parser.add_argument('-p', '--plugin-filter',
help='Comma-separated list of plugins to update')

parser.add_argument('-l', '--list', action='store_true',
help='Output list of available plugins')

parser.add_argument('--version', action='version',
version='{}'.format(__version__))
Expand All @@ -196,6 +241,14 @@ def delete_old_plugins(data, dest):
# Download/Load Plugin Data
plugins = get_plugin_config(args.conf)

# List plugins and exit
if args.list is True:
list_plugins(plugins)
sys.exit(0)

# Filter plugin data list to selected plugins or default plugins
plugins = filter_plugins(plugins, args.plugin_filter)

# Replace variables in templated strings
plugins = process_template_strings(plugins)

Expand Down
1 change: 1 addition & 0 deletions gog-plugins.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gog-plugins-downloader.exe -p battlenet,bethesda,epic,gw2,humblebundle,minecraft,origin,paradox,psn,rockstar,steam,twitch,uplay,wargaming
Loading

0 comments on commit 7ca45bd

Please sign in to comment.