From 60f0f5689473d7022503029cdffe8b3094660364 Mon Sep 17 00:00:00 2001 From: olari Date: Sat, 27 Apr 2019 16:37:10 +0300 Subject: [PATCH] Add anime collection parity checker --- python/verify_anime_collection.py | 85 +++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100755 python/verify_anime_collection.py diff --git a/python/verify_anime_collection.py b/python/verify_anime_collection.py new file mode 100755 index 0000000..589c06b --- /dev/null +++ b/python/verify_anime_collection.py @@ -0,0 +1,85 @@ +#!/bin/env python3 + +import sys +import os +import re + +class Episode: + def __init__(self, filename): + self.filename = filename + + self.tags = re.findall(r'([(,[][A-Z,a-z,0-9,_, ]+[),\]])', self.filename) + try: + self.number = re.findall(r'-[ ,_](\d+)', self.filename)[0] + except: + self.number = "OP/ED" + + self.name = self.filename + + for tag in self.tags: + self.name = self.name.replace(tag, '') + + if self.name.find(' ') == -1: + self.name = self.name.replace('_', ' ') + + self.name = self.name[:self.name.find('-')] + self.name = self.name.strip() + +class Show: + def __init__(self, path): + self.path = path + + self.name = self.path[self.path.rfind('/') + 1:] + + self.episodes = [] + + for episode in os.listdir(self.path): + if episode[0] == '#': + continue + + episodepath = '/'.join([self.path, episode]) + + if not os.path.isfile(episodepath): + continue + + self.episodes.append(Episode(episode)) + +class Collection: + def __init__(self, path): + self.path = path + + self.shows = [] + + for show in os.listdir(self.path): + if show[0] == '#': + continue + + showpath = '/'.join([self.path, show]) + + if not os.path.isdir(showpath): + continue + + self.shows.append(Show(showpath)) + +def main(): + if len(sys.argv) < 2: + print("Usage: {} [path to anime collection]".format(sys.argv[0])) + return + + collection_path = sys.argv[1] + + if not os.path.isdir(collection_path): + print("FATAL: '{}' is not a valid directory!".format(collection_path)) + return + + collection = Collection(collection_path) + + for show in collection.shows: + print(show.name) + + for episode in show.episodes: + print(episode.name, episode.number, episode.tags) + +if __name__ == "__main__": + main() +