Merge pull request 'Add HBMAME github site, add support for multiple download directories' (#9) from sebastian404/PDMameUpdate:master into master

Reviewed-on: #9
master
djib 2021-10-26 22:16:13 +02:00
commit d2c05b69ec
3 changed files with 54 additions and 42 deletions

View File

@ -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')
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))
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__':

View File

@ -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

View File

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