add ssl, check content-type
This commit is contained in:
parent
23eb0543c8
commit
27fd41da49
11
oppaibot.py
11
oppaibot.py
|
@ -10,7 +10,7 @@ import configparser
|
||||||
import http.cookiejar
|
import http.cookiejar
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from twisted.internet import protocol, reactor
|
from twisted.internet import ssl, protocol, reactor
|
||||||
from twisted.words.protocols import irc
|
from twisted.words.protocols import irc
|
||||||
|
|
||||||
HEADERS = {"User-Agent": "spaghetti is a faggot"}
|
HEADERS = {"User-Agent": "spaghetti is a faggot"}
|
||||||
|
@ -39,6 +39,9 @@ class OppaiBot(irc.IRCClient):
|
||||||
"""
|
"""
|
||||||
res = requests.get(url, cookies=self.cj, headers=HEADERS, verify=True)
|
res = requests.get(url, cookies=self.cj, headers=HEADERS, verify=True)
|
||||||
res.raise_for_status()
|
res.raise_for_status()
|
||||||
|
if not res.headers['Content-Type'].startswith('application/x-bittorrent'):
|
||||||
|
print(f"ERROR: Could not download torrent file from URL '{url}'.")
|
||||||
|
return
|
||||||
fname =re.search(r'filename="(.+)"',res.headers['content-disposition'])
|
fname =re.search(r'filename="(.+)"',res.headers['content-disposition'])
|
||||||
fname = fname.group(1)
|
fname = fname.group(1)
|
||||||
fname = fname.encode("latin-1").decode("utf-8")
|
fname = fname.encode("latin-1").decode("utf-8")
|
||||||
|
@ -119,5 +122,9 @@ if __name__ == "__main__":
|
||||||
server = tracker_config["server"]
|
server = tracker_config["server"]
|
||||||
port = tracker_config.getint("port")
|
port = tracker_config.getint("port")
|
||||||
print("Connecting to:", tracker_config.name)
|
print("Connecting to:", tracker_config.name)
|
||||||
reactor.connectTCP(server, port, OppaiBotFactory(tracker_config))
|
reactor.connectSSL(
|
||||||
|
server,
|
||||||
|
port,
|
||||||
|
OppaiBotFactory(tracker_config),
|
||||||
|
ssl.ClientContextFactory())
|
||||||
reactor.run()
|
reactor.run()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user