Browse Source

Add HBMAME github site, add support for multiple download directories

pull/9/head
sebastian404 1 month ago
parent
commit
27257bfbc7
  1. 95
      PDMameUpdate.py
  2. 2
      PDMameUpdate.template.json
  3. 1
      Pipfile

95
PDMameUpdate.py

@ -66,7 +66,7 @@ def open_config_file():
)
for loc in locations:
if loc is not None:
logging.info("Searching for config file in '%s'", loc)
logging.debug("Searching for config file in '%s'", loc)
config_path = loc + '/PDMameUpdate.json'
if pathlib.Path(config_path).is_file():
config_file_loc = config_path
@ -107,43 +107,52 @@ def fetch_local_torrents():
"""Fetches local torrents versions"""
logging.info('Fetching current MAME versions')
directories = os.listdir(config['mame-directory'])
for directory in directories:
for regexp in regexps:
match = regexp.search(directory)
if match:
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))
for mdirectory in config['mame-directory']:
logging.debug('checking: %s', mdirectory)
directories = os.listdir(mdirectory)
for directory in directories:
for regexp in regexps:
match = regexp.search(directory)
if match:
version = match.group(0)
name = regexp.sub('#', directory)
torrents[name]['local-version'] = version
torrents[name]['local-name'] = directory
torrents[name]['local-path'] = mdirectory
logging.debug('Found the local torrent versions: %s', pformat(torrents))
def fetch_remote_torrents():
"""Fetches PleasureDome torrents versions"""
logging.info('Opening PleasureDome github feed')
page = get('https://pleasuredome.github.io/pleasuredome/mame/index.html')
html = bs(page.text, 'html.parser')
for link in html.find_all('a'):
for regexp in regexps:
match = regexp.search(link.string)
if match:
if urlparse(link.get('href')).netloc == 'mgnet.me':
matched_version = match.group(0)
matched_torrent = torrents[regexp.sub('#', link.string)]
remote_version = matched_torrent.get('remote-version', '')
if matched_version > remote_version:
matched_torrent['remote-version'] = matched_version
matched_torrent['remote-link'] = link.get('href')
matched_torrent['remote-name'] = link.string
else:
logging.info("Skipping '{}' version '{}'".format(
match.group(0),
matched_version
))
logging.debug('Found the remote torrent versions: %s', pformat(torrents))
pdurls = [
'https://pleasuredome.github.io/pleasuredome/mame/index.html',
'https://pleasuredome.github.io/pleasuredome/hbmame/index.html'
]
for url in pdurls:
page = get(url)
html = bs(page.text, 'html.parser')
for link in html.find_all('a'):
for regexp in regexps:
match = regexp.search(link.string)
if match:
if urlparse(link.get('href')).netloc == 'mgnet.me':
matched_version = match.group(0)
matched_torrent = torrents[regexp.sub('#', link.string)]
remote_version = matched_torrent.get('remote-version', '')
if matched_version > remote_version:
matched_torrent['remote-version'] = matched_version
matched_torrent['remote-link'] = link.get('href')
matched_torrent['remote-name'] = link.string
else:
logging.info("Skipping '{}' version '{}'".format(
match.group(0),
matched_version
))
logging.debug('Found the remote torrent versions: %s', pformat(torrents))
def filter_updatable_torrents():
@ -238,29 +247,33 @@ def update_torrents():
for torrent in torrents.values():
logging.info('Updating torrent : %s', torrent['remote-name'])
old_name = os.path.join(
config['mame-directory'],
torrent['local-path'],
torrent['local-name']
)
new_name = os.path.join(
config['mame-directory'],
torrent['local-path'],
torrent['remote-name']
)
if 'transmission-id' in torrent:
logging.debug(
'Removing from transmission : %s',
torrent['transmission-id']
)
client.torrent.remove(torrent['transmission-id'])
logging.debug('Renaming %s to %s', old_name, new_name)
os.rename(old_name, new_name)
logging.debug('Adding to transmission : %s', torrent['remote-link'])
client.torrent.add(
filename=torrent['remote-link'],
magnet_link=True,
download_dir=config['mame-directory'],
paused=True
)
logging.debug('Adding to transmission : %s', torrent['remote-link'])
arguments = {
"filename" : torrent['remote-link'],
"magnet_link": True,
"download_dir" : torrent['local-path'],
"paused" : True,
}
responce = client.torrent.add(arguments)
logging.debug('clutch responce : %s', responce)
if __name__ == '__main__':

2
PDMameUpdate.template.json

@ -1,5 +1,5 @@
{
"mame-directory":"/path/to/your/local/mame/files/target/folder",
"mame-directory":["/path/to/your/local/mame/files/target/folder","/path/to/your/local/mame/files/target/iotherfolder"],
"transmission-user":"user",
"transmission-password":"pass",
"transmission-port":8080

1
Pipfile

@ -6,7 +6,6 @@ name = "pypi"
[packages]
bs4 = "*"
requests = "*"
clutch = "*"
transmission-clutch = "*"
tabulate = "*"

Loading…
Cancel
Save