diff --git a/PDMameUpdate.py b/PDMameUpdate.py index 3e5c7ac..166d692 100755 --- a/PDMameUpdate.py +++ b/PDMameUpdate.py @@ -104,10 +104,10 @@ def fetch_local_torrents(): directories = os.listdir(config['mame-directory']) for directory in directories: for regexp in regexps: - match = regexp.match(directory) + match = regexp.search(directory) if match: - version = match.group('version') - name = match.group(0).replace(version, '#') + version = match.group(0) + name = regexp.sub('#', directory) torrents[name]['local-version'] = version torrents[name]['local-name'] = directory logging.debug('Found the local torrent versions: %s', pformat(torrents)) @@ -122,8 +122,8 @@ def fetch_remote_torrents(): for regexp in regexps: match = regexp.match(post.title) if match: - matched_version = match.group('version') - matched_torrent = torrents[match.group(0).replace(matched_version, '#')] + matched_version = match.group(0) + matched_torrent = regexp.sub('#', post.title) if matched_version > matched_torrent.get('remote-version', ''): matched_torrent['remote-version'] = matched_version matched_torrent['remote-link'] = post.link @@ -240,9 +240,10 @@ def fetch_transmission_torrents(): logging.info('Listing Transmission torrents') for torrent in client.list().values(): for regexp in regexps: - match = regexp.match(torrent['name']) + match = regexp.search(torrent['name']) if match: - torrents[match.group(0).replace(match.group('version'), '#')]['transmission-id'] = torrent['id'] + name = regexp.sub('#', torrent['name']) + torrents[name]['transmission-id'] = torrent['id'] logging.debug('Found the Transmission torrent ids: %s', pformat(torrents)) @@ -328,8 +329,9 @@ if __name__ == '__main__': time.sleep(1) regexps = [ - re.compile(r'(?:HB)?MAME (?P[\d.]+) .*'), - re.compile(r'No-Intro \((?P[\d-]+)\) .*') + re.compile(r'(?<=MAME )[\d.]+'), + re.compile(r'(?<=HBMAME )[\d.]+'), + re.compile(r'(?<=No-Intro \()[\d-]+') ] config = open_config_file() torrents = defaultdict(dict)