Files
PDMameUpdate/PDMameUpdate.py

81 lines
2.6 KiB
Python

#!/usr/bin/python3
'''
Checks available MAME Torrents on PleasureDome
and updates the local versions if more recent
versions are detected
Work in progress…
Requirements:
* Python3 with the libraries below
* Transmission for Bitorrent
* A PleasureDome account
/!\/!\/!\/!\/!\/!\/!\/!\/!\/!\/!\/!\/!\/!\/!\
/!\ Provided with no warranty whatsoever. /!\
/!\ Use with caution. /!\
/!\/!\/!\/!\/!\/!\/!\/!\/!\/!\/!\/!\/!\/!\/!\
'''
import feedparser
import json
import logging
import os
import re
from clutch.core import Client
if __name__ == '__main__':
logging.basicConfig(level=logging.DEBUG, format=' %(asctime)s - %(levelname)s - %(message)s')
re_mame_version = re.compile('MAME 0.(\d+) (.*)')
logging.info('Opening config file: config.json')
with open('config.json') as config_file:
config = json.load(config_file)
logging.info('Fetching current MAME versions')
files = os.listdir(config['mame_directory'])
local_torrents = {}
for file in files:
match = re_mame_version.match(file)
if match:
local_torrents[match[2]] = int(match[1])
logging.info('Found the following Torrent version on disk: %s', local_torrents)
logging.info('Opening PleasureDome RSS feed')
d = feedparser.parse('http://www.pleasuredome.org.uk/rss.xml')
remote_torrents = {}
for post in d.entries:
match = re_mame_version.match(post.title)
if match:
remote_torrents[match[2]] = int(match[1])
logging.info('Found the following Torrent version on PleasureDome: %s', remote_torrents)
for torrent, version in local_torrents.items():
if torrent in remote_torrents:
if version < remote_torrents[torrent]:
print('Torrent {}: {} -> {}'.format(torrent, version, remote_torrents[torrent]))
print('Should I update the torrents listed above? (y/N)')
answer = input()
if answer.lower() == 'y':
logging.info('Updating…')
logging.info('Connecting to Transmission Remote Control')
client = Client(
username=config['transmission-user'],
password=config['transmission-password'],
port=config['transmission-port']
)
logging.info('Listing Transmission torrents')
for torrent in client.list().values():
print(torrent['name']);
else:
logging.info('Quitting: user cancelled update.')
# TODO: connect to PleasureDome
# TODO: remove local torrent from Transmission
# TODO: rename local folder
# TODO: add new torrent to Transmission
# TODO: implement some error handling