From e46b9c06e865ac912b2a6f9d9985c0708bc1630b Mon Sep 17 00:00:00 2001 From: djib Date: Fri, 4 Sep 2020 22:44:32 +0200 Subject: [PATCH] Initial work on multible torrent formats (untested) --- PDMameUpdate.py | 48 +++++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/PDMameUpdate.py b/PDMameUpdate.py index 1868a89..b017c2a 100755 --- a/PDMameUpdate.py +++ b/PDMameUpdate.py @@ -103,10 +103,11 @@ def fetch_local_torrents(): logging.info('Fetching current MAME versions') directories = os.listdir(config['mame-directory']) for directory in directories: - match = re_mame_version.match(directory) - if match: - torrents[match.group(2)]['local-version'] = int(match.group(1)) - torrents[match.group(2)]['local-name'] = directory + for regexp in regexps: + match = regexp.match(directory) + if match: + torrents[match.group('name')]['local-version'] = match.group('version') + torrents[match.group('name')]['local-name'] = directory logging.debug('Found the local torrent versions: %s', pformat(torrents)) @@ -116,19 +117,20 @@ def fetch_remote_torrents(): logging.info('Opening PleasureDome RSS feed') d = feedparser.parse('http://www.pleasuredome.org.uk/rss.xml') for post in d.entries: - match = re_mame_version.match(post.title) - if match: - matched_version = int(match.group(1)) - matched_torrent = torrents[match.group(2)] - if matched_version > matched_torrent.get('remote-version', 0): - matched_torrent['remote-version'] = matched_version - matched_torrent['remote-link'] = post.link - matched_torrent['remote-name'] = post.title - else: - logging.info("Skipping '{}' version '{}'".format( - match.group(0), - matched_version - )) + for regexp in regexps: + match = regexp.match(post.title) + if match: + matched_version = match.group('version') + matched_torrent = torrents[match.group('name')] + if matched_version > matched_torrent.get('remote-version', ''): + matched_torrent['remote-version'] = matched_version + matched_torrent['remote-link'] = post.link + matched_torrent['remote-name'] = post.title + else: + logging.info("Skipping '{}' version '{}'".format( + match.group(0), + matched_version + )) logging.debug('Found the remote torrent versions: %s', pformat(torrents)) @@ -235,9 +237,10 @@ def fetch_transmission_torrents(): logging.info('Listing Transmission torrents') for torrent in client.list().values(): - match = re_mame_version.match(torrent['name']) - if match: - torrents[match.group(2)]['transmission-id'] = torrent['id'] + for regexp in regexps: + match = regexp.match(torrent['name']) + if match: + torrents[match.group('name')]['transmission-id'] = torrent['id'] logging.debug('Found the Transmission torrent ids: %s', pformat(torrents)) @@ -322,7 +325,10 @@ if __name__ == '__main__': print('{}\r'.format(i), end=''), time.sleep(1) - re_mame_version = re.compile(r'MAME 0.(\d+) (.*)') + regexps = [ + re.compile(r'(?P(?:HB)?MAME (?P[\d.]+) .*)'), + re.compile(r'(?PNo-Intro \((?P[\d-]+)\) .*)') + ] config = open_config_file() torrents = defaultdict(dict)