|
|
|
@ -6,7 +6,7 @@ versions are detected |
|
|
|
|
|
|
|
|
|
Basically what it does is: |
|
|
|
|
* Get all torrents in a directory torrents |
|
|
|
|
* Get all torrents from PleasureDome RSS |
|
|
|
|
* Get all torrents from PleasureDome github |
|
|
|
|
* Get all torrents currently active in Transmission |
|
|
|
|
* Intersect the first two lists to get updatable torrents |
|
|
|
|
* And for each updatable torrent: |
|
|
|
@ -17,14 +17,12 @@ Basically what it does is: |
|
|
|
|
Supported Torrents: |
|
|
|
|
* MAME |
|
|
|
|
* HBMAME |
|
|
|
|
* No-Intro |
|
|
|
|
|
|
|
|
|
Work in progress… |
|
|
|
|
* TODO: implement some error handling |
|
|
|
|
|
|
|
|
|
Requirements: |
|
|
|
|
* Transmission for Bitorrent |
|
|
|
|
* A PleasureDome account |
|
|
|
|
* A proper PDMameUpdate.json file (see PDMameUpdate.template.json) |
|
|
|
|
* Python3 with the libraries below |
|
|
|
|
- feedparser |
|
|
|
@ -32,11 +30,6 @@ Requirements: |
|
|
|
|
- tabulate |
|
|
|
|
* Linux (untested on other OS, but it might work) |
|
|
|
|
|
|
|
|
|
Notes |
|
|
|
|
* This script logs in PleasureDome to get the proper cookies. |
|
|
|
|
It seems you can also set your cookies in Transmission using |
|
|
|
|
a cookies.txt file in the .config/transmission directory |
|
|
|
|
See: https://forum.transmissionbt.com/viewtopic.php?t=7468 |
|
|
|
|
|
|
|
|
|
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|
|
|
|
!!! Provided with no warranty whatsoever. !!! |
|
|
|
@ -46,19 +39,19 @@ Notes |
|
|
|
|
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|
|
|
|
''' |
|
|
|
|
import argparse |
|
|
|
|
import feedparser |
|
|
|
|
from bs4 import BeautifulSoup as bs |
|
|
|
|
import json |
|
|
|
|
import logging |
|
|
|
|
import os |
|
|
|
|
import re |
|
|
|
|
import requests |
|
|
|
|
from requests import get |
|
|
|
|
import time |
|
|
|
|
import pathlib |
|
|
|
|
from clutch.core import Client |
|
|
|
|
from tabulate import tabulate |
|
|
|
|
from collections import defaultdict |
|
|
|
|
from pprint import pformat |
|
|
|
|
from urllib.parse import quote |
|
|
|
|
from urllib.parse import quote, urlparse |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def open_config_file(): |
|
|
|
@ -88,9 +81,6 @@ def open_config_file(): |
|
|
|
|
config = json.load(config_file) |
|
|
|
|
parameters = [ |
|
|
|
|
"mame-directory", |
|
|
|
|
"pleasuredome-password", |
|
|
|
|
"pleasuredome-user", |
|
|
|
|
"torrent-directory", |
|
|
|
|
"transmission-password", |
|
|
|
|
"transmission-port", |
|
|
|
|
"transmission-user" |
|
|
|
@ -102,6 +92,16 @@ def open_config_file(): |
|
|
|
|
return config |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_magnet_link(link): |
|
|
|
|
page = get(link) |
|
|
|
|
html = bs(page.text, 'html.parser') |
|
|
|
|
|
|
|
|
|
for link in html.find_all('a'): |
|
|
|
|
href = link.get('href') |
|
|
|
|
if urlparse(href).scheme=='magnet': |
|
|
|
|
return link.string |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def fetch_local_torrents(): |
|
|
|
|
"""Fetches local torrents versions""" |
|
|
|
|
|
|
|
|
@ -121,28 +121,31 @@ def fetch_local_torrents(): |
|
|
|
|
def fetch_remote_torrents(): |
|
|
|
|
"""Fetches PleasureDome torrents versions""" |
|
|
|
|
|
|
|
|
|
logging.info('Opening PleasureDome RSS feed') |
|
|
|
|
d = feedparser.parse('http://www.pleasuredome.org.uk/rss.xml') |
|
|
|
|
for post in d.entries: |
|
|
|
|
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(post.title) |
|
|
|
|
match = regexp.search(link.string) |
|
|
|
|
if match: |
|
|
|
|
matched_version = match.group(0) |
|
|
|
|
matched_torrent = torrents[regexp.sub('#', post.title)] |
|
|
|
|
if matched_version > matched_torrent.get('remote-version', ''): |
|
|
|
|
matched_torrent['remote-version'] = matched_version |
|
|
|
|
matched_torrent['remote-link'] = post.link |
|
|
|
|
matched_torrent['remote-name'] = post.title |
|
|
|
|
else: |
|
|
|
|
logging.info("Skipping '{}' version '{}'".format( |
|
|
|
|
match.group(0), |
|
|
|
|
matched_version |
|
|
|
|
)) |
|
|
|
|
if urlparse(link.get('href')).netloc == 'mgnet.me': |
|
|
|
|
matched_version = match.group(0) |
|
|
|
|
matched_torrent = torrents[regexp.sub('#', link.string)] |
|
|
|
|
if matched_version > matched_torrent.get('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(): |
|
|
|
|
"""Checks if newer versions are available and prompt for update""" |
|
|
|
|
"""Checks if newer versions are available and get magnet link""" |
|
|
|
|
|
|
|
|
|
for torrent, data in list(torrents.items()): |
|
|
|
|
keys_to_check = {'local-version', 'remote-version'} |
|
|
|
@ -151,7 +154,7 @@ def filter_updatable_torrents(): |
|
|
|
|
and |
|
|
|
|
data['local-version'] < data['remote-version'] |
|
|
|
|
): |
|
|
|
|
check_and_rewrite_download_url(data) |
|
|
|
|
data['remote-link'] = get_magnet_link(data['remote-link']) |
|
|
|
|
else: |
|
|
|
|
del torrents[torrent] |
|
|
|
|
|
|
|
|
@ -161,24 +164,6 @@ def filter_updatable_torrents(): |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def check_and_rewrite_download_url(torrent_data): |
|
|
|
|
url_match = re.compile( |
|
|
|
|
r"https?://www.pleasuredome.org.uk/details.php\?id=(.*)" |
|
|
|
|
) |
|
|
|
|
match = url_match.match(torrent_data['remote-link']) |
|
|
|
|
if match: |
|
|
|
|
url = ("http://www.pleasuredome.org.uk/download.php" |
|
|
|
|
"?id={}&f={}.torrent&secure=no").format( |
|
|
|
|
match.group(1), |
|
|
|
|
quote('+'.join(torrent_data['remote-name'].split(' ')), safe='+') |
|
|
|
|
) |
|
|
|
|
logging.info('Changed url {} to {}'.format( |
|
|
|
|
torrent_data['remote-link'], |
|
|
|
|
url |
|
|
|
|
)) |
|
|
|
|
torrent_data['remote-link'] = url |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def prompt_for_update(): |
|
|
|
|
"""Ask for user confirmation before updating""" |
|
|
|
|
|
|
|
|
@ -206,28 +191,6 @@ def prompt_for_update(): |
|
|
|
|
logging.info('User chose to update torrents') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_cookies_from_pleasuredome(): |
|
|
|
|
"""Connects to PleasureDome to retrieve Cookies""" |
|
|
|
|
|
|
|
|
|
logging.info('Logging in PleasureDome') |
|
|
|
|
data = { |
|
|
|
|
'uid': config['pleasuredome-user'], |
|
|
|
|
'pwd': config['pleasuredome-password'] |
|
|
|
|
} |
|
|
|
|
r = requests.post('http://www.pleasuredome.org.uk/login3.php', data=data) |
|
|
|
|
if r.status_code == 200: |
|
|
|
|
logging.info('Connected to PleasureDome') |
|
|
|
|
logging.info('Logging out') |
|
|
|
|
requests.get('http://www.pleasuredome.org.uk/logout.php') |
|
|
|
|
else: |
|
|
|
|
logging.error( |
|
|
|
|
'Connection to PleasureDome failed with status %s', |
|
|
|
|
r.status_code |
|
|
|
|
) |
|
|
|
|
exit(1) |
|
|
|
|
return {k: r.cookies[k] for k in ('uid', 'pass')} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def connect_to_transmission(): |
|
|
|
|
"""Connects to Transmission and return a Client object""" |
|
|
|
|
|
|
|
|
@ -271,26 +234,19 @@ def update_torrents(): |
|
|
|
|
config['mame-directory'], |
|
|
|
|
torrent['remote-name'] |
|
|
|
|
) |
|
|
|
|
new_torrent = os.path.join( |
|
|
|
|
config['torrent-directory'], |
|
|
|
|
torrent['remote-name']+'.torrent' |
|
|
|
|
) |
|
|
|
|
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'], |
|
|
|
|
cookies=cookies, |
|
|
|
|
paused=False |
|
|
|
|
paused=True |
|
|
|
|
) |
|
|
|
|
if args.keep: |
|
|
|
|
logging.debug('Downloading torrent : %s', new_torrent) |
|
|
|
|
t = requests.get(torrent['remote-link'], verify=False, cookies=cookies) |
|
|
|
|
open(new_torrent, 'wb').write(t.content) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
|
@ -311,11 +267,6 @@ if __name__ == '__main__': |
|
|
|
|
action='store_true', |
|
|
|
|
help='Display debugging messages' |
|
|
|
|
) |
|
|
|
|
parser.add_argument( |
|
|
|
|
'-k', '--keep', |
|
|
|
|
action='store_true', |
|
|
|
|
help='Keep torrent files localy' |
|
|
|
|
) |
|
|
|
|
parser.add_argument( |
|
|
|
|
'-c', '--countdown', |
|
|
|
|
action='store_true', |
|
|
|
@ -336,13 +287,11 @@ if __name__ == '__main__': |
|
|
|
|
regexps = [ |
|
|
|
|
re.compile(r'(?<=MAME )[\d.]+'), |
|
|
|
|
re.compile(r'(?<=HBMAME )[\d.]+'), |
|
|
|
|
re.compile(r'(?<=No-Intro \()[\d-]+') |
|
|
|
|
] |
|
|
|
|
config = open_config_file() |
|
|
|
|
torrents = defaultdict(dict) |
|
|
|
|
|
|
|
|
|
client = connect_to_transmission() |
|
|
|
|
cookies = get_cookies_from_pleasuredome() |
|
|
|
|
|
|
|
|
|
fetch_local_torrents() |
|
|
|
|
fetch_remote_torrents() |
|
|
|
|