From 8ead17e25e35d31849198616b8aa1db0010126c2 Mon Sep 17 00:00:00 2001 From: Noam Date: Tue, 1 Mar 2016 10:15:36 +0200 Subject: [PATCH] Try Different User-Agent for Specific Sites - DLing not working for some users, possibly because of the site - maybe a different UA will make a difference - Make links lowercase before testing them for content --- headphones/deluge.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/headphones/deluge.py b/headphones/deluge.py index 72aa76ff..79104bc9 100644 --- a/headphones/deluge.py +++ b/headphones/deluge.py @@ -72,16 +72,20 @@ def addTorrent(link, data=None): try: result = {} retid = False + special_treatment_sites = ['https://what.cd/', 'http://what.cd/'] - if link.startswith('magnet:'): + if link.lower().startswith('magnet:'): logger.debug('Deluge: Got a magnet link: %s' % _scrubber(link)) result = {'type': 'magnet', 'url': link} retid = _add_torrent_magnet(result) - elif link.startswith('http://') or link.startswith('https://'): + elif link.lower().startswith('http://') or link.lower().startswith('https://'): logger.debug('Deluge: Got a URL: %s' % _scrubber(link)) - user_agent = 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2243.2 Safari/537.36' + if link.lower().startswith(tuple(special_treatment_sites)): + user_agent = 'Headphones' + else: + user_agent = 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2243.2 Safari/537.36' headers = {'User-Agent': user_agent} torrentfile = '' logger.debug('Deluge: Trying to download (GET)') @@ -118,7 +122,7 @@ def addTorrent(link, data=None): retid = _add_torrent_file(result) # elif link.endswith('.torrent') or data: - elif not (link.startswith('http://') or link.startswith('https://')): + elif not (link.lower().startswith('http://') or link.lower().startswith('https://')): if data: logger.debug('Deluge: Getting .torrent data') torrentfile = data