forked from djib/PDMameUpdate
Improve handling of different URL formats in the RSS feed
This commit is contained in:
@ -50,6 +50,7 @@ import time
|
|||||||
from clutch.core import Client
|
from clutch.core import Client
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from pprint import pformat
|
from pprint import pformat
|
||||||
|
from urllib.parse import quote
|
||||||
|
|
||||||
|
|
||||||
def open_config_file():
|
def open_config_file():
|
||||||
@ -74,7 +75,7 @@ def fetch_local_torrents():
|
|||||||
logging.debug('Found the local torrent versions: %s', pformat(torrents))
|
logging.debug('Found the local torrent versions: %s', pformat(torrents))
|
||||||
|
|
||||||
|
|
||||||
def fetch_remote_terrents():
|
def fetch_remote_torrents():
|
||||||
"""Fetches PleasureDome torrents versions"""
|
"""Fetches PleasureDome torrents versions"""
|
||||||
|
|
||||||
logging.info('Opening PleasureDome RSS feed')
|
logging.info('Opening PleasureDome RSS feed')
|
||||||
@ -101,21 +102,39 @@ def filter_updatable_torrents():
|
|||||||
|
|
||||||
for torrent, data in list(torrents.items()):
|
for torrent, data in list(torrents.items()):
|
||||||
keys_to_check = {'local-version', 'remote-version', 'transmission-id'}
|
keys_to_check = {'local-version', 'remote-version', 'transmission-id'}
|
||||||
if not (
|
if (
|
||||||
keys_to_check.issubset(data.keys())
|
keys_to_check.issubset(data.keys())
|
||||||
and
|
and
|
||||||
data['local-version'] < data['remote-version']
|
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]
|
del torrents[torrent]
|
||||||
|
|
||||||
logging.info(
|
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():
|
def prompt_for_update():
|
||||||
"""Ask for user confirmation before updating"""
|
"""Ask for user confirmation before updating"""
|
||||||
|
|
||||||
@ -224,6 +243,11 @@ if __name__ == '__main__':
|
|||||||
action='store_true',
|
action='store_true',
|
||||||
help='Display more log messages'
|
help='Display more log messages'
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'-d', '--debug',
|
||||||
|
action='store_true',
|
||||||
|
help='Display debugging messages'
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-c', '--countdown',
|
'-c', '--countdown',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
@ -232,6 +256,8 @@ if __name__ == '__main__':
|
|||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
if args.log:
|
if args.log:
|
||||||
logging.getLogger().setLevel(logging.INFO)
|
logging.getLogger().setLevel(logging.INFO)
|
||||||
|
if args.debug:
|
||||||
|
logging.getLogger().setLevel(logging.DEBUG)
|
||||||
if args.countdown:
|
if args.countdown:
|
||||||
print('PDMameUpdate is about to start')
|
print('PDMameUpdate is about to start')
|
||||||
# Useful if you run this script when your machine boots
|
# Useful if you run this script when your machine boots
|
||||||
@ -247,7 +273,7 @@ if __name__ == '__main__':
|
|||||||
cookies = get_cookies_from_pleasuredome()
|
cookies = get_cookies_from_pleasuredome()
|
||||||
|
|
||||||
fetch_local_torrents()
|
fetch_local_torrents()
|
||||||
fetch_remote_terrents()
|
fetch_remote_torrents()
|
||||||
fetch_transmission_torrents()
|
fetch_transmission_torrents()
|
||||||
filter_updatable_torrents()
|
filter_updatable_torrents()
|
||||||
prompt_for_update()
|
prompt_for_update()
|
||||||
|
Reference in New Issue
Block a user