initial update to use new github site

This commit is contained in:
2021-09-29 23:56:57 +01:00
parent 49c1b9df0b
commit a7b1249ccb
3 changed files with 37 additions and 93 deletions

View File

@ -6,7 +6,7 @@ versions are detected
Basically what it does is: Basically what it does is:
* Get all torrents in a directory torrents * 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 * Get all torrents currently active in Transmission
* Intersect the first two lists to get updatable torrents * Intersect the first two lists to get updatable torrents
* And for each updatable torrent: * And for each updatable torrent:
@ -17,14 +17,12 @@ Basically what it does is:
Supported Torrents: Supported Torrents:
* MAME * MAME
* HBMAME * HBMAME
* No-Intro
Work in progress… Work in progress…
* TODO: implement some error handling * TODO: implement some error handling
Requirements: Requirements:
* Transmission for Bitorrent * Transmission for Bitorrent
* A PleasureDome account
* A proper PDMameUpdate.json file (see PDMameUpdate.template.json) * A proper PDMameUpdate.json file (see PDMameUpdate.template.json)
* Python3 with the libraries below * Python3 with the libraries below
- feedparser - feedparser
@ -32,11 +30,6 @@ Requirements:
- tabulate - tabulate
* Linux (untested on other OS, but it might work) * 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. !!! !!! Provided with no warranty whatsoever. !!!
@ -46,19 +39,19 @@ Notes
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
''' '''
import argparse import argparse
import feedparser from bs4 import BeautifulSoup as bs
import json import json
import logging import logging
import os import os
import re import re
import requests from requests import get
import time import time
import pathlib import pathlib
from clutch.core import Client from clutch.core import Client
from tabulate import tabulate from tabulate import tabulate
from collections import defaultdict from collections import defaultdict
from pprint import pformat from pprint import pformat
from urllib.parse import quote from urllib.parse import quote, urlparse
def open_config_file(): def open_config_file():
@ -88,9 +81,6 @@ def open_config_file():
config = json.load(config_file) config = json.load(config_file)
parameters = [ parameters = [
"mame-directory", "mame-directory",
"pleasuredome-password",
"pleasuredome-user",
"torrent-directory",
"transmission-password", "transmission-password",
"transmission-port", "transmission-port",
"transmission-user" "transmission-user"
@ -102,6 +92,16 @@ def open_config_file():
return config 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(): def fetch_local_torrents():
"""Fetches local torrents versions""" """Fetches local torrents versions"""
@ -121,28 +121,31 @@ def fetch_local_torrents():
def fetch_remote_torrents(): def fetch_remote_torrents():
"""Fetches PleasureDome torrents versions""" """Fetches PleasureDome torrents versions"""
logging.info('Opening PleasureDome RSS feed') logging.info('Opening PleasureDome github feed')
d = feedparser.parse('http://www.pleasuredome.org.uk/rss.xml') page = get('https://pleasuredome.github.io/pleasuredome/mame/index.html')
for post in d.entries: html = bs(page.text, 'html.parser')
for link in html.find_all('a'):
for regexp in regexps: for regexp in regexps:
match = regexp.search(post.title) match = regexp.search(link.string)
if match: if match:
matched_version = match.group(0) if urlparse(link.get('href')).netloc == 'mgnet.me':
matched_torrent = torrents[regexp.sub('#', post.title)] matched_version = match.group(0)
if matched_version > matched_torrent.get('remote-version', ''): matched_torrent = torrents[regexp.sub('#', link.string)]
matched_torrent['remote-version'] = matched_version if matched_version > matched_torrent.get('remote-version', ''):
matched_torrent['remote-link'] = post.link matched_torrent['remote-version'] = matched_version
matched_torrent['remote-name'] = post.title matched_torrent['remote-link'] = link.get('href')
else: matched_torrent['remote-name'] = link.string
logging.info("Skipping '{}' version '{}'".format( else:
match.group(0), logging.info("Skipping '{}' version '{}'".format(
matched_version match.group(0),
)) 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():
"""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()): for torrent, data in list(torrents.items()):
keys_to_check = {'local-version', 'remote-version'} keys_to_check = {'local-version', 'remote-version'}
@ -151,7 +154,7 @@ def filter_updatable_torrents():
and and
data['local-version'] < data['remote-version'] data['local-version'] < data['remote-version']
): ):
check_and_rewrite_download_url(data) data['remote-link'] = get_magnet_link(data['remote-link'])
else: else:
del torrents[torrent] 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(): def prompt_for_update():
"""Ask for user confirmation before updating""" """Ask for user confirmation before updating"""
@ -206,28 +191,6 @@ def prompt_for_update():
logging.info('User chose to update torrents') 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(): def connect_to_transmission():
"""Connects to Transmission and return a Client object""" """Connects to Transmission and return a Client object"""
@ -271,26 +234,19 @@ def update_torrents():
config['mame-directory'], config['mame-directory'],
torrent['remote-name'] torrent['remote-name']
) )
new_torrent = os.path.join(
config['torrent-directory'],
torrent['remote-name']+'.torrent'
)
if 'transmission-id' in torrent: if 'transmission-id' in torrent:
logging.debug('Removing from transmission : %s',torrent['transmission-id']) logging.debug('Removing from transmission : %s',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']) logging.debug('Adding to transmission : %s', torrent['remote-link'])
client.torrent.add( client.torrent.add(
filename=torrent['remote-link'], filename=torrent['remote-link'],
magnet_link=True,
download_dir=config['mame-directory'], download_dir=config['mame-directory'],
cookies=cookies, paused=True
paused=False
) )
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__': if __name__ == '__main__':
@ -311,11 +267,6 @@ if __name__ == '__main__':
action='store_true', action='store_true',
help='Display debugging messages' help='Display debugging messages'
) )
parser.add_argument(
'-k', '--keep',
action='store_true',
help='Keep torrent files localy'
)
parser.add_argument( parser.add_argument(
'-c', '--countdown', '-c', '--countdown',
action='store_true', action='store_true',
@ -336,13 +287,11 @@ if __name__ == '__main__':
regexps = [ regexps = [
re.compile(r'(?<=MAME )[\d.]+'), re.compile(r'(?<=MAME )[\d.]+'),
re.compile(r'(?<=HBMAME )[\d.]+'), re.compile(r'(?<=HBMAME )[\d.]+'),
re.compile(r'(?<=No-Intro \()[\d-]+')
] ]
config = open_config_file() config = open_config_file()
torrents = defaultdict(dict) torrents = defaultdict(dict)
client = connect_to_transmission() client = connect_to_transmission()
cookies = get_cookies_from_pleasuredome()
fetch_local_torrents() fetch_local_torrents()
fetch_remote_torrents() fetch_remote_torrents()

View File

@ -1,9 +1,6 @@
{ {
"mame-directory":"/path/to/your/local/mame/files/target/folder", "mame-directory":"/path/to/your/local/mame/files/target/folder",
"torrent-directory":"/path/to/your/local/mame/torrent/target/folder",
"transmission-user":"user", "transmission-user":"user",
"transmission-password":"pass", "transmission-password":"pass",
"pleasuredome-user":"user",
"pleasuredome-password":"pass",
"transmission-port":8080 "transmission-port":8080
} }

View File

@ -7,7 +7,6 @@ versions are detected
Supported torrents: Supported torrents:
* MAME * MAME
* HBMAME * HBMAME
* No-Intro
![Sample output](https://djib.fr/djib/PDMameUpdate/raw/branch/master/screenshot.png) ![Sample output](https://djib.fr/djib/PDMameUpdate/raw/branch/master/screenshot.png)
@ -33,6 +32,5 @@ optional arguments:
-h, --help show this help message and exit -h, --help show this help message and exit
-l, --log Display more log messages -l, --log Display more log messages
-d, --debug Display debugging messages -d, --debug Display debugging messages
-k, --keep Keep torrent files localy
-c, --countdown Start with a 5 second countdown -c, --countdown Start with a 5 second countdown
``` ```