Compare commits
No commits in common. "master" and "logictags" have entirely different histories.
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 packages: `twisted requests`
|
||||
Python modules: `requests, twisted`
|
||||
|
||||
## Config
|
||||
`server` - The address of the IRC server the bot should connect to.
|
||||
|
@ -18,8 +18,7 @@ Python packages: `twisted requests`
|
|||
`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. 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.
|
||||
`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.
|
||||
|
||||
### Example config.cfg
|
||||
```
|
||||
|
@ -32,8 +31,7 @@ tracker_bot = Udon
|
|||
auth_msg = BOT #oppaitime-announce iou1name SpaghettiIsAFaggot
|
||||
watch_dir = /home/iou1name/torrent/oppaitime/Watch/
|
||||
cookies_txt = cookies.txt
|
||||
tags = [English,!Manga],[Manga,English,Archived],[Dual Language],[Softsubs]
|
||||
blacklist = scat
|
||||
tags = [Manga,English,Archived],[Dual Language],[Softsubs]
|
||||
|
||||
[redacted]
|
||||
server = irc.scratch-network.net
|
||||
|
@ -44,5 +42,5 @@ tracker_bot = Drone
|
|||
auth_msg = enter #red-announce iou1name TheyllAlwaysBePTHToMe
|
||||
watch_dir = /home/iou1name/torrent/passtheheadphones/Watch/
|
||||
cookies_txt = cookies.txt
|
||||
tags = [rock]
|
||||
tags = [rock],[metal]
|
||||
```
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env python3
|
||||
"""
|
||||
A lazy bot for idling in OppaiTime's announce channel and downloading
|
||||
A really 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 ssl, protocol, reactor
|
||||
from twisted.internet import protocol, reactor
|
||||
from twisted.words.protocols import irc
|
||||
|
||||
HEADERS = {"User-Agent": "spaghetti is a faggot"}
|
||||
|
@ -27,10 +27,8 @@ 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):
|
||||
|
@ -39,12 +37,9 @@ class OppaiBot(irc.IRCClient):
|
|||
"""
|
||||
res = requests.get(url, cookies=self.cj, headers=HEADERS, verify=True)
|
||||
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.encode("latin-1").decode("utf-8")
|
||||
fname = fname.replace(u"â\x80\x93", "–")
|
||||
print(self.tracker + ": Saving torrent:", fname)
|
||||
with open(os.path.join(directory, fname), "wb") as file:
|
||||
for chunk in res.iter_content(100000):
|
||||
|
@ -57,20 +52,9 @@ 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_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))
|
||||
|
||||
tags_in_msg.append(all([tag in msg for tag in tag_group]))
|
||||
if any(tags_in_msg):
|
||||
url = re.findall(r"(http.+?) ", message)[1]
|
||||
self.save_torrent(url, self.watch_dir)
|
||||
|
@ -122,9 +106,5 @@ if __name__ == "__main__":
|
|||
server = tracker_config["server"]
|
||||
port = tracker_config.getint("port")
|
||||
print("Connecting to:", tracker_config.name)
|
||||
reactor.connectSSL(
|
||||
server,
|
||||
port,
|
||||
OppaiBotFactory(tracker_config),
|
||||
ssl.ClientContextFactory())
|
||||
reactor.connectTCP(server, port, OppaiBotFactory(tracker_config))
|
||||
reactor.run()
|
Loading…
Reference in New Issue
Block a user