From f40fdb11160c8dc1cc4fa2d68d893637cd598272 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Tue, 7 Jul 2020 05:42:17 +0200 Subject: Add option to start tracking anime from filename --- episode.py | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100755 episode.py (limited to 'episode.py') diff --git a/episode.py b/episode.py new file mode 100755 index 0000000..6ac8ab1 --- /dev/null +++ b/episode.py @@ -0,0 +1,73 @@ +#!/usr/bin/env python3 + +class EpisodeInfo: + group_name = None + anime_name = None + episode = None + resolution = None + extension = None + + def get_generic_name(self): + if not self.group_name or not self.anime_name: + return "" + generic_name = "[%s] %s" % (self.group_name, self.anime_name) + if self.resolution: + generic_name += " [%s]" % self.resolution + if self.extension: + generic_name += self.extension + return generic_name + +def episode_extract_info(episode_name): + episode_name = episode_name.strip() + episode_info = EpisodeInfo() + + if len(episode_name) == 0: + return episode_info + + extension_index = episode_name.rfind('.') + if extension_index != -1: + episode_info.extension = episode_name[extension_index:] + episode_name = episode_name[0:extension_index] + + if episode_name[0] != '[': + return episode_info + + group_name_end = episode_name.find(']') + if group_name_end == -1: + return episode_info + + episode_info.group_name = episode_name[1:group_name_end].strip() + + last_dash = episode_name.rfind('-') + if last_dash == -1: + return episode_info + + episode_info.anime_name = episode_name[group_name_end+1:last_dash].strip() + + resolution_index = episode_name.find('[', last_dash + 1) + if resolution_index == -1: + episode_info.episode = episode_name[last_dash+1:].strip() + else: + episode_info.episode = episode_name[last_dash+1:resolution_index].strip() + resolution_end = episode_name.find(']', resolution_index + 1) + if resolution_end != -1: + episode_info.resolution = episode_name[resolution_index+1:resolution_end] + + return episode_info + +if __name__ == "__main__": + episode_info = episode_extract_info("[Erai-raws] Saiki Kusuo no Psi Nan - Kanketsu-hen - 01 [1080p][Multiple Subtitle].mkv") + print("|{}|".format(episode_info.group_name)) + print("|{}|".format(episode_info.anime_name)) + print("|{}|".format(episode_info.episode)) + print("|{}|".format(episode_info.resolution)) + print("|{}|".format(episode_info.extension)) + print("|{}|".format(episode_info.get_generic_name())) + + episode_info = episode_extract_info("nyaa.si") + print("|{}|".format(episode_info.group_name)) + print("|{}|".format(episode_info.anime_name)) + print("|{}|".format(episode_info.episode)) + print("|{}|".format(episode_info.resolution)) + print("|{}|".format(episode_info.extension)) + print("|{}|".format(episode_info.get_generic_name())) \ No newline at end of file -- cgit v1.2.3