Browse Source

Improve handling of different URL formats in the RSS feed

master
djib 2 years ago
parent
commit
3c479ac5d4
1 changed files with 34 additions and 8 deletions
  1. +34
    -8
      PDMameUpdate.py

+ 34
- 8
PDMameUpdate.py View File

@ -50,6 +50,7 @@ import time
from clutch.core import Client
from collections import defaultdict
from pprint import pformat
from urllib.parse import quote
def open_config_file():
@ -74,7 +75,7 @@ def fetch_local_torrents():
logging.debug('Found the local torrent versions: %s', pformat(torrents))
def fetch_remote_terrents():
def fetch_remote_torrents():
"""Fetches PleasureDome torrents versions"""
logging.info('Opening PleasureDome RSS feed')
@ -101,21 +102,39 @@ def filter_updatable_torrents():
for torrent, data in list(torrents.items()):
keys_to_check = {'local-version', 'remote-version', 'transmission-id'}
if not (
if (
keys_to_check.issubset(data.keys())
and
data['local-version'] < data['remote-version']
and
data['remote-link'].startswith(
'http://www.pleasuredome.org.uk/download.php'
)
):
check_and_rewrite_download_url(data)
else:
del torrents[torrent]
logging.info(
'The following torrents can be updated: %s', pformat(torrents)
'The following torrents can be updated: %s',
[t for t in torrents.keys()]
)
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"""
@ -224,6 +243,11 @@ if __name__ == '__main__':
action='store_true',
help='Display more log messages'
)
parser.add_argument(
'-d', '--debug',
action='store_true',
help='Display debugging messages'
)
parser.add_argument(
'-c', '--countdown',
action='store_true',
@ -232,6 +256,8 @@ if __name__ == '__main__':
args = parser.parse_args()
if args.log:
logging.getLogger().setLevel(logging.INFO)
if args.debug:
logging.getLogger().setLevel(logging.DEBUG)
if args.countdown:
print('PDMameUpdate is about to start')
# Useful if you run this script when your machine boots
@ -247,7 +273,7 @@ if __name__ == '__main__':
cookies = get_cookies_from_pleasuredome()
fetch_local_torrents()
fetch_remote_terrents()
fetch_remote_torrents()
fetch_transmission_torrents()
filter_updatable_torrents()
prompt_for_update()


Loading…
Cancel
Save