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