86 lines
2.0 KiB
Python
Executable File
86 lines
2.0 KiB
Python
Executable File
#!/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()
|
|
|