Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
27fd41da49 | |||
23eb0543c8 | |||
e8baf1848b | |||
905564dbe7 | |||
1dbdb1f546 | |||
b8243374d4 | |||
fa6ac2d4c0 | |||
d1c9c0a0bb | |||
46387e2299 | |||
32d430c8e5 | |||
6762a4a137 | |||
233579e765 |
10
README.md
10
README.md
|
@ -7,7 +7,7 @@ Supports connecting to multiple tracker IRC servers at once. Simply make separat
|
|||
|
||||
## Requirements
|
||||
Python 3+
|
||||
Python modules: `requests, twisted`
|
||||
Python packages: `twisted requests`
|
||||
|
||||
## Config
|
||||
`server` - The address of the IRC server the bot should connect to.
|
||||
|
@ -18,7 +18,8 @@ Python modules: `requests, twisted`
|
|||
`auth_msg` - The message to send to the `tracker_bot` to authenticate with and access the announce channel. It's up to you figure this out.
|
||||
`watch_dir` - The directory to save torrents to.
|
||||
`cookies_txt` - The path to where your session cookie(s) are stored. Should be in Netscape format.
|
||||
`tags` - Comma-delineated list of tags to look for in each announce message. The script is just performing simple string comparisons on the entire message, so the 'tag' can be any substring appearing in the announce message. Tag inside of brackets are AND'd together, tag groups are then OR'd together. In the example below, announce messages with ['Manga' AND 'English' AND 'Archived'] OR 'Dual Language' OR 'Softsubs' will be matched.
|
||||
`tags` - Comma-delineated list of tags to look for in each announce message. The script is just performing simple string comparisons on the entire message, so the 'tag' can be any substring appearing in the announce message. Tag inside of brackets are AND'd together, tag groups are then OR'd together. Tags starting with ! are treated as NOT [tag]. In the example below, announce messages with ['English' AND NOT 'Manga'] OR ['Manga' AND 'English' AND 'Archived'] OR 'Dual Language' OR 'Softsubs' will be matched.
|
||||
`blacklist` - Comma-delineated list of blacklisted tags. Same as `tags`, except if any of these are found in the announce message the bot skips the entire message. This parameter is optional.
|
||||
|
||||
### Example config.cfg
|
||||
```
|
||||
|
@ -31,7 +32,8 @@ tracker_bot = Udon
|
|||
auth_msg = BOT #oppaitime-announce iou1name SpaghettiIsAFaggot
|
||||
watch_dir = /home/iou1name/torrent/oppaitime/Watch/
|
||||
cookies_txt = cookies.txt
|
||||
tags = [Manga,English,Archived],[Dual Language],[Softsubs]
|
||||
tags = [English,!Manga],[Manga,English,Archived],[Dual Language],[Softsubs]
|
||||
blacklist = scat
|
||||
|
||||
[redacted]
|
||||
server = irc.scratch-network.net
|
||||
|
@ -42,5 +44,5 @@ tracker_bot = Drone
|
|||
auth_msg = enter #red-announce iou1name TheyllAlwaysBePTHToMe
|
||||
watch_dir = /home/iou1name/torrent/passtheheadphones/Watch/
|
||||
cookies_txt = cookies.txt
|
||||
tags = [rock],[metal]
|
||||
tags = [rock]
|
||||
```
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env python3
|
||||
"""
|
||||
A really lazy bot for idling in OppaiTime's announce channel and downloading
|
||||
A lazy bot for idling in OppaiTime's announce channel and downloading
|
||||
every torrent with matching tags.
|
||||
"""
|
||||
import os
|
||||
|
@ -10,7 +10,7 @@ import configparser
|
|||
import http.cookiejar
|
||||
|
||||
import requests
|
||||
from twisted.internet import protocol, reactor
|
||||
from twisted.internet import ssl, protocol, reactor
|
||||
from twisted.words.protocols import irc
|
||||
|
||||
HEADERS = {"User-Agent": "spaghetti is a faggot"}
|
||||
|
@ -27,8 +27,10 @@ class OppaiBot(irc.IRCClient):
|
|||
self.cj.load()
|
||||
|
||||
self.watch_dir = self.config["watch_dir"]
|
||||
|
||||
self.tags = re.findall(r"\[(.+?)\]", self.config["tags"])
|
||||
self.tags = [tag.split(",") for tag in self.tags]
|
||||
self.blacklist = self.config.get("blacklist", "").split(",")
|
||||
|
||||
|
||||
def save_torrent(self, url, directory):
|
||||
|
@ -37,9 +39,12 @@ class OppaiBot(irc.IRCClient):
|
|||
"""
|
||||
res = requests.get(url, cookies=self.cj, headers=HEADERS, verify=True)
|
||||
res.raise_for_status()
|
||||
fname = re.search(r'filename="(.+)"',res.headers['content-disposition'])
|
||||
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 = fname.group(1)
|
||||
fname = fname.replace(u"â\x80\x93", "–")
|
||||
fname = fname.encode("latin-1").decode("utf-8")
|
||||
print(self.tracker + ": Saving torrent:", fname)
|
||||
with open(os.path.join(directory, fname), "wb") as file:
|
||||
for chunk in res.iter_content(100000):
|
||||
|
@ -52,9 +57,20 @@ class OppaiBot(irc.IRCClient):
|
|||
or users alike.
|
||||
"""
|
||||
# More advanced logic is left as an exercise to the reader.
|
||||
black_in_msg = [tag in message for tag in self.blacklist if tag]
|
||||
if any(black_in_msg):
|
||||
return
|
||||
|
||||
tags_in_msg = []
|
||||
for tag_group in self.tags:
|
||||
tags_in_msg.append(all([tag in msg for tag in tag_group]))
|
||||
tags_in_group = []
|
||||
for tag in tag_group:
|
||||
if tag.startswith("!"):
|
||||
tags_in_group.append(tag[1:] not in message)
|
||||
else:
|
||||
tags_in_group.append(tag in message)
|
||||
tags_in_msg.append(all(tags_in_group))
|
||||
|
||||
if any(tags_in_msg):
|
||||
url = re.findall(r"(http.+?) ", message)[1]
|
||||
self.save_torrent(url, self.watch_dir)
|
||||
|
@ -106,5 +122,9 @@ if __name__ == "__main__":
|
|||
server = tracker_config["server"]
|
||||
port = tracker_config.getint("port")
|
||||
print("Connecting to:", tracker_config.name)
|
||||
reactor.connectTCP(server, port, OppaiBotFactory(tracker_config))
|
||||
reactor.connectSSL(
|
||||
server,
|
||||
port,
|
||||
OppaiBotFactory(tracker_config),
|
||||
ssl.ClientContextFactory())
|
||||
reactor.run()
|
Loading…
Reference in New Issue
Block a user