diff options
author | lonkaars <loek@pipeframe.xyz> | 2022-01-18 16:33:55 +0100 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2022-01-18 16:33:55 +0100 |
commit | 62decc54968cee0a35cd5eda38d891767ba9786d (patch) | |
tree | 210c4f8fc3a2f21d2d54f4f2dcb820b6dd6c60e1 | |
parent | 71edd1fa62fc48a8c37e26a22078258b3d25a58a (diff) |
worky
-rwxr-xr-x | autonyaa.py | 38 | ||||
-rw-r--r-- | configuration.an | 2 | ||||
-rw-r--r-- | readme.md | 76 | ||||
-rw-r--r-- | requirements.txt | 10 |
4 files changed, 118 insertions, 8 deletions
diff --git a/autonyaa.py b/autonyaa.py index e4cc144..8776da3 100755 --- a/autonyaa.py +++ b/autonyaa.py @@ -1,12 +1,20 @@ #!/bin/python3 -import urllib, sys, re, requests, xml.etree.ElementTree as et, transmission_rpc, os, json +import urllib,\ + sys,\ + re,\ + requests,\ + xml.etree.ElementTree as et,\ + transmission_rpc,\ + os,\ + json current_path = os.path.dirname(__file__) config_file = open(current_path + "/configuration.an", "r") transmission_rpc_file = open(current_path + "/transmission.json", "r") transmission_rpc_config = json.loads(transmission_rpc_file.read()) -transmission_client = transmission_rpc.Client(host='localhost', port=9091,) +transmission_client = transmission_rpc.Client(**transmission_rpc_config) +torrents = transmission_client.get_torrents() def generate_url(query): return "https://nyaa.si/?" + urllib.parse.urlencode({"q": query, "page": "rss"}) @@ -88,18 +96,34 @@ def parse_config_file(): return parsed_sections -def start_dl(result, section): - print(result, section) +def done_dl(transmission_id, section): + print(section) + +def start_dl(result, section, vars): + hash = result.findtext("nyaa:infoHash", None, {"nyaa": "https://nyaa.si/xmlns/nyaa"}) + torrent = [t for t in torrents if t.hashString == hash] + if len(torrent) == 1: + torrent = torrent[0] + if torrent.progress == 100: + print("linking " + section["name"]) + source = torrent.download_dir + "/" + torrent.files()[0].name + target = section["destination"] + "/" + section["filename"](vars) + print(source + " -> " + target) + os.makedirs(os.path.dirname(target), exist_ok=True) + os.link(source, target) + else: + transmission_client.add_torrent(result.findtext("link")) + print("adding torrent: " + result.findtext("title")) def main(): sections = parse_config_file() for section in sections: response = requests.get(generate_url(section["name"])).text root = et.fromstring(response) - results = [child for child in root[0] if child.tag == "item"] + results = root[0].findall("item") for result in results: - match = section["match-name"]([el.text for el in result if el.tag == "title"][0]) - if match[0]: start_dl(result, match[1]) + match = section["match-name"](result.findtext("title")) + if match[0]: start_dl(result, section, match[1]) if __name__ == "__main__": main() diff --git a/configuration.an b/configuration.an index bcd7447..680601b 100644 --- a/configuration.an +++ b/configuration.an @@ -2,6 +2,6 @@ name Sabikui Bisco filename Sabikui-Bisco_s01e${e}.${x} match-submitter subsplease match-name /\[SubsPlease\] Sabikui Bisco - (\d{2}) \(1080p\) \[[0-9A-F]{8}\]\.(.+)/ e x -destination ~/anime/Sabikui Bisco +destination /mnt/e/anime/Sabikui Bisco episodes 12 @@ -3,3 +3,79 @@ script that automatically adds new anime episodes from nyaa.si to a transmission daemon, and symlinks them once they're done downloading +it's intentionally janky, because i don't expect it to work for a long time. if +it keeps working (well) for long enough i'll refactor/document the code better. + +## configuration + +autonyaa is configured through two files: configuration.an and +transmission.json. both have to be located in the same folder as the python +script itself. example config files are included. + +transmission.json is a regular json file containing credentials for connecting +to the transmission daemon. note that if you've configured a localhost +whitelist for your transmission-daemon, that the `username` and `password` keys +can be either set to `null` or be omitted entirely. + +configuration.an is a file with a custom key-value syntax for defining how +autonyaa should look up and match torrent titles. if you want to keep track of +multiple anime's, you can define multiple config sections by seperating them +with an empty line. here's a reference for all the configuration keys: + +### name + +``` +name <string> +``` + +set the name and search query + +### filename + +``` +filename <string> +``` + +set the filename for finished downloads. finished downloads are hard-linked +into [destination](#destination), with any variables replaced with values from +regex groups. for more info on variables, see [match-name](#match-name). + +example: + +``` +filename Anime-name_s01e${e}.${x} +``` + +### match-name + +``` +match-name <regex> <groups> +``` + +filter torrent titles using regex. for a match to be successful, the entire +regex has to match. match groups are mapped onto the variable names defined +after the regex, and can be reused for the target filename. + +example + +``` +match-name /\[coolgroup\] Anime name episode (\d{2}) - episode title \(1080p\)\.(.+)/ e x +``` + +> in this example, the variable e is set to the first group (`(\d{2})`), and x +> is set to (`(.+)`). for regex help, see [regexr](https://regexr.com) + +### destination + +``` +destination <folder> +``` + +destination folder + +## todo + +- [ ] implement episode limit +- [ ] implement match-submitter + + diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..4765776 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,10 @@ +certifi==2021.10.8 +charset-normalizer==2.0.10 +idna==3.3 +jedi==0.18.1 +parso==0.8.3 +regex==2021.11.10 +requests==2.27.1 +transmission-rpc==3.3.0 +typing-extensions==3.10.0.2 +urllib3==1.26.8 |