|
41 | 41 | import datetime
|
42 | 42 | import logging
|
43 | 43 | import re
|
| 44 | +import ssl |
44 | 45 | import time
|
45 | 46 | import traceback
|
| 47 | +import urllib2 |
46 | 48 |
|
47 | 49 | from deluge.common import is_url
|
48 | 50 | from deluge.core.rpcserver import export
|
@@ -80,12 +82,24 @@ def update(self):
|
80 | 82 | @export
|
81 | 83 | def update_trackerlist_from_url(self):
|
82 | 84 | if self.config["dynamic_trackerlist_url"]:
|
83 |
| - import requests # hide the import here in an attempt to lower the number of bug reports from people not having "python-requests" installed |
84 | 85 | now = datetime.datetime.utcnow()
|
85 | 86 | last_update = datetime.datetime.utcfromtimestamp(self.config["last_dynamic_trackers_update"])
|
86 | 87 | if now - last_update > datetime.timedelta(days=self.config["dynamic_trackers_update_interval"]):
|
87 | 88 | try:
|
88 |
| - page = requests.get(self.config["dynamic_trackerlist_url"]).text |
| 89 | + headers = { |
| 90 | + 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:62.0) Gecko/20100101 Firefox/62.0', |
| 91 | + 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', |
| 92 | + 'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3', |
| 93 | + 'Accept-Encoding': 'none', |
| 94 | + 'Accept-Language': 'en-US,en;q=0.8', |
| 95 | + } |
| 96 | + |
| 97 | + req = urllib2.Request(self.config["dynamic_trackerlist_url"], headers=headers) |
| 98 | + try: |
| 99 | + page = urllib2.urlopen(req, context=ssl._create_unverified_context()).read() |
| 100 | + except: |
| 101 | + # maybe an older Python version without a "context" argument |
| 102 | + page = urllib2.urlopen(req).read() |
89 | 103 | new_trackers = [url for url in re.findall(r'\w+://[\w\-.:/]+', page) if is_url(url)]
|
90 | 104 | if new_trackers:
|
91 | 105 | # replace all existing trackers
|
|
0 commit comments