diff options
author | lonkaars <loek@pipeframe.xyz> | 2022-01-20 16:17:42 +0100 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2022-01-20 16:17:42 +0100 |
commit | 78b6ad43f661c3e1f0d797c05a9ac3da6e57e5e7 (patch) | |
tree | 3076bddcf6b6db8e34143c566ae9d8c56c73226a | |
parent | 60ddbddc997ea2294604f2fbac402ad6f65cadc1 (diff) |
new episodes settings
-rwxr-xr-x | autonyaa.py | 37 | ||||
-rw-r--r-- | configuration.an | 4 | ||||
-rw-r--r-- | readme.md | 26 |
3 files changed, 45 insertions, 22 deletions
diff --git a/autonyaa.py b/autonyaa.py index 67160af..b574114 100755 --- a/autonyaa.py +++ b/autonyaa.py @@ -31,9 +31,9 @@ def parse_config_prop_name(line): return line[5:].strip() def parse_config_prop_filename(line): - def return_funtion(variables): + def return_function(variables): return fill_format_string(line[9:].strip(), variables) - return return_funtion + return return_function def parse_config_prop_match_submitter(line): return line[16:].strip() @@ -45,7 +45,7 @@ def parse_config_prop_match_name(line): parser = re.compile(match[0][1:-1]) variables = [x.strip() for x in match[1].split(" ")] - def return_funtion(name): + def return_function(name): match = parser.match(name) if match == None or match.start() != 0 or match.end() != len(name): return [ False, {} ] @@ -53,14 +53,29 @@ def parse_config_prop_match_name(line): for index, name in enumerate(variables): vars[name] = match.groups()[index] return [ True, vars ] - return return_funtion + return return_function def parse_config_prop_destination(line): return line[12:].strip() def parse_config_prop_episodes(line): parsed = line[9:].strip().split(" ") - return { "var": parsed[0], "count": int(parsed[1]) } + episode_var = parsed[0] + season_var = None + if not parsed[-1].isdigit(): + season_var = parsed[-1] + del parsed[-1] + season_lens = [int(s) for s in parsed[1:]] + def return_function(vars): + season = 0 + episode = int(vars[episode_var]) + while episode > season_lens[season % len(season_lens)]: + episode -= season_lens[season % len(season_lens)] + season += 1 + vars[episode_var] = str(episode).rjust(2, '0') + vars[season_var] = str(season + 1).rjust(2, '0') + return vars + return return_function config_props = [ {"prop": "name", "parser": parse_config_prop_name}, @@ -73,12 +88,12 @@ config_props = [ def parse_config_section(section): props = { - "name": "", + "name": '', "filename": None, "match-submitter": [], "match-name": None, - "destination": "", - "episodes": {"var": None, "count": 0}, + "destination": '', + "episodes": None } lines = section.split("\n") for line in lines: @@ -99,16 +114,13 @@ def parse_config_file(): return parsed_sections -def episode_limit_reached(section, vars): - return int(vars[section["episodes"]["var"]]) > section["episodes"]["count"] - 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] source = torrent.download_dir + "/" + torrent.files()[0].name - target = section["destination"] + "/" + section["filename"](vars) + target = section["destination"] + "/" + section["filename"](section["episodes"](vars)) if torrent.progress == 100 and not os.path.exists(target): print("linking " + section["name"]) print(source + " -> " + target) @@ -127,7 +139,6 @@ def main(): for result in results: match = section["match-name"](result.findtext("title")) if not match[0]: continue - if episode_limit_reached(section, match[1]): continue start_dl(result, section, match[1]) if __name__ == "__main__": diff --git a/configuration.an b/configuration.an index 698f0a1..b5407d1 100644 --- a/configuration.an +++ b/configuration.an @@ -1,7 +1,7 @@ name Sabikui Bisco -filename Sabikui-Bisco_s01e${e}.${x} +filename Sabikui-Bisco_s${s}e${e}.${x} match-submitter subsplease match-name /\[SubsPlease\] Sabikui Bisco - (\d{2}) \(1080p\) \[[0-9A-F]{8}\]\.(.+)/ e x destination /mnt/e/anime/Sabikui Bisco -episodes e 12 +episodes e 12 s @@ -63,11 +63,12 @@ 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 +match-name /\[coolgroup\] Anime name episode (\d{2}) - episode title \(1080p\)\.(.+)/ e_i 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) +> in this example, the variable e is set to the first group (`(\d{2})`) and +> parsed into an integer internally, and x is set to (`(.+)`) as a string. for +> regex help, see [regexr](https://regexr.com) ### match-submitter @@ -94,15 +95,26 @@ destination folder ### episodes ``` -episodes <var> <int> +episodes <var> <int>... [season] ``` -limit episode download count using variable from [match-name](#match-name). +calculate season number from continuous episode numbering -example +examples + +``` +episodes e 12 s +``` + +> in this example, the anime contains an unknown number of seasons with 12 +> episodes each. if the variable e is set to 15, it will be changed to 3, with +> `s` set to 2. + +if each season has a different number of episodes, more episode counts can be +added before the season variable: ``` -episodes e 12 +episodes e 24 12 12 s ``` ## todo |