Revert requiring MODDB: prefix

Signed-off-by: Antoine Mazeas <antoine@karthanis.net>
This commit is contained in:
Antoine Mazeas 2023-01-17 00:32:48 +01:00 committed by Mathieu Comandon
parent 10c4c8fcdf
commit 88a004c86d
5 changed files with 20 additions and 21 deletions

View file

@ -396,13 +396,12 @@ the platform rotates the actual download links every few hours, making it
impractical to set these links as source url in installers. Lutris has
routines to overcome this limitation (with blessing from moddb.com). When
specifying a file hosted on moddb.com, please use the url of the files details
page (the one with the red "Download now" button). You must prefix the URL
with ``MODDB:``.
page (the one with the red "Download now" button).
Example URLs for ModDB files::
MODDB:https://www.moddb.com/games/{game-title}/downloads/{file-title}
MODDB:https://www.moddb.com/mods/{mod-title}/downloads/{file-title}
https://www.moddb.com/games/{game-title}/downloads/{file-title}
https://www.moddb.com/mods/{mod-title}/downloads/{file-title}
Writing the installation script
===============================

View file

@ -15,7 +15,7 @@ from lutris.services import SERVICES
from lutris.util.game_finder import find_linux_game_executable, find_windows_game_executable
from lutris.util.gog import convert_gog_config_to_lutris, get_gog_config_from_path, get_gog_game_path
from lutris.util.log import logger
from lutris.util.moddb import ModDB
from lutris.util.moddb import ModDB, is_moddb_url
class LutrisInstaller: # pylint: disable=too-many-instance-attributes
@ -159,8 +159,8 @@ class LutrisInstaller: # pylint: disable=too-many-instance-attributes
# Run variable substitution on the URLs from the script
for file in self.files:
file.set_url(self.interpreter._substitute(file.url))
if file.url.startswith("MODDB:"):
file.set_url(ModDB().transform_url(file.url[6:]))
if is_moddb_url(file.url):
file.set_url(ModDB().transform_url(file.url))
if installer_file_id and self.service:
logger.info("Getting files for %s", installer_file_id)

View file

@ -143,7 +143,7 @@ class InstallerFile:
def is_downloadable(self):
"""Return True if the file can be downloaded (even from the local filesystem)"""
return self.url.startswith(("http", "file", "MODDB"))
return self.url.startswith(("http", "file"))
def uses_pga_cache(self, create=False):
"""Determines whether the installer files are stored in a PGA cache

View file

@ -6,20 +6,20 @@ import types
MODDB_FQDN = 'https://www.moddb.com'
MODDB_URL_MATCHER = '^https://(www\.)?moddb\.com'
def is_moddb_url(url):
return re.match(MODDB_URL_MATCHER, url.lower()) is not None
class ModDB:
def __init__(self, parse_page_method: types.MethodType = moddb.parse_page):
self.parse = parse_page_method
def transform_url(self, moddb_permalink_url):
if not self._is_moddb_url(moddb_permalink_url):
if not is_moddb_url(moddb_permalink_url):
raise RuntimeError("provided url must be from moddb.com")
return MODDB_FQDN + self._autoselect_moddb_mirror(self._get_html_and_resolve_mirrors_list(moddb_permalink_url))._url
def _is_moddb_url(self, url):
return re.match(MODDB_URL_MATCHER, url.lower()) is not None
def _autoselect_moddb_mirror(self, mirrors_list):
# dumb autoselect for now: rank mirrors by capacity (lower is better), pick first (lowest load)
return sorted(mirrors_list, key=lambda m: m.capacity)[0]

View file

@ -1,6 +1,6 @@
import unittest
import moddb
from lutris.util.moddb import ModDB
from lutris.util.moddb import ModDB, is_moddb_url
class ModDBHelperTests(unittest.TestCase):
@ -96,33 +96,33 @@ class ModDBHelperTests(unittest.TestCase):
## is_moddb_url
def test_is_moddb_url_has_www_success(self):
url = 'https://www.moddb.com/something'
self.assertTrue(self.helper_obj._is_moddb_url(url))
self.assertTrue(is_moddb_url(url))
def test_is_moddb_url_no_slug_has_www_success(self):
url = 'https://www.moddb.com'
self.assertTrue(self.helper_obj._is_moddb_url(url))
self.assertTrue(is_moddb_url(url))
def test_is_moddb_url_no_www_success(self):
url = 'https://moddb.com/something'
self.assertTrue(self.helper_obj._is_moddb_url(url))
self.assertTrue(is_moddb_url(url))
def test_is_moddb_url_no_slug_no_www_success(self):
url = 'https://moddb.com'
self.assertTrue(self.helper_obj._is_moddb_url(url))
self.assertTrue(is_moddb_url(url))
def test_is_moddb_url_other_subdomain_failure(self):
url = 'https://subdomain.moddb.com/something'
self.assertFalse(self.helper_obj._is_moddb_url(url))
self.assertFalse(is_moddb_url(url))
def test_is_moddb_url_no_slug_other_subdomain_failure(self):
url = 'https://subdomain.moddb.com'
self.assertFalse(self.helper_obj._is_moddb_url(url))
self.assertFalse(is_moddb_url(url))
def test_is_moddb_url_random_domain_failure(self):
url = 'https://somedomain.com/something'
self.assertFalse(self.helper_obj._is_moddb_url(url))
self.assertFalse(is_moddb_url(url))
def test_is_moddb_url_no_slug_random_domain_failure(self):
url = 'https://somedomain.com'
self.assertFalse(self.helper_obj._is_moddb_url(url))
self.assertFalse(is_moddb_url(url))