Merge pull request 'Update for direct magnet links, add support for versions with multiple minor versions' (#10) from sebastian404/PDMameUpdate:master into master

Reviewed-on: https://djib.fr/djib/PDMameUpdate/pulls/10
This commit is contained in:
2023-04-10 08:33:27 +00:00

View File

@ -26,6 +26,7 @@ Requirements:
* A proper PDMameUpdate.json file (see PDMameUpdate.template.json) * A proper PDMameUpdate.json file (see PDMameUpdate.template.json)
* Python3 with the libraries below * Python3 with the libraries below
- bs4 - bs4
- packaging
- requests - requests
- transmission-clutch - transmission-clutch
- tabulate - tabulate
@ -53,6 +54,7 @@ from tabulate import tabulate
from collections import defaultdict from collections import defaultdict
from pprint import pformat from pprint import pformat
from urllib.parse import urlparse from urllib.parse import urlparse
from packaging import version
def open_config_file(): def open_config_file():
@ -93,16 +95,6 @@ def open_config_file():
return config return config
def get_magnet_link(link):
page = get(link)
html = bs(page.text, 'html.parser')
for link in html.find_all('a'):
href = link.get('href')
if urlparse(href).scheme == 'magnet':
return link.string
def fetch_local_torrents(): def fetch_local_torrents():
"""Fetches local torrents versions""" """Fetches local torrents versions"""
@ -139,7 +131,7 @@ def fetch_remote_torrents():
for regexp in regexps: for regexp in regexps:
match = regexp.search(link.string) match = regexp.search(link.string)
if match: if match:
if urlparse(link.get('href')).netloc == 'mgnet.me': if urlparse(link.get('href')).scheme == 'magnet':
matched_version = match.group(0) matched_version = match.group(0)
matched_torrent = torrents[regexp.sub('#', link.string)] matched_torrent = torrents[regexp.sub('#', link.string)]
remote_version = matched_torrent.get('remote-version', '') remote_version = matched_torrent.get('remote-version', '')
@ -148,8 +140,8 @@ def fetch_remote_torrents():
matched_torrent['remote-link'] = link.get('href') matched_torrent['remote-link'] = link.get('href')
matched_torrent['remote-name'] = link.string matched_torrent['remote-name'] = link.string
else: else:
logging.info("Skipping '{}' version '{}'".format( logging.debug("Skipping '{}' version '{}'".format(
match.group(0), link.string,
matched_version matched_version
)) ))
logging.debug('Found the remote torrent versions: %s', pformat(torrents)) logging.debug('Found the remote torrent versions: %s', pformat(torrents))
@ -160,13 +152,11 @@ def filter_updatable_torrents():
for torrent, data in list(torrents.items()): for torrent, data in list(torrents.items()):
keys_to_check = {'local-version', 'remote-version'} keys_to_check = {'local-version', 'remote-version'}
if ( if not (
keys_to_check.issubset(data.keys()) keys_to_check.issubset(data.keys())
and and
data['local-version'] < data['remote-version'] version.parse(data['local-version']) < version.parse(data['remote-version'])
): ):
data['remote-link'] = get_magnet_link(data['remote-link'])
else:
del torrents[torrent] del torrents[torrent]
logging.debug( logging.debug(