Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""LICENSE
2Copyright 2015 Hermann Krumrey <hermann@krumreyh.com>
4This file is part of toktokkie.
6toktokkie is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
11toktokkie is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
16You should have received a copy of the GNU General Public License
17along with toktokkie. If not, see <http://www.gnu.org/licenses/>.
18LICENSE"""
20import os
21from abc import ABC
22from puffotter.os import listdir
23from typing import Optional, Dict, List
24from toktokkie.metadata.base.MetadataBase import MetadataBase
27class GameExtras(MetadataBase, ABC):
28 """
29 Additional methods and attributes for game metadata objects
30 """
32 @property
33 def video_dir(self) -> str:
34 """
35 :return: Path to the video directory
36 """
37 return os.path.join(self.directory_path, ".meta/videos")
39 @property
40 def cg_dir(self) -> str:
41 """
42 :return: Path to the CG directory
43 """
44 return os.path.join(self.directory_path, ".meta/cgs")
46 @property
47 def ost_dir(self) -> str:
48 """
49 :return: Path to the OST directory
50 """
51 return os.path.join(self.directory_path, ".meta/ost")
53 @property
54 def has_ed(self) -> bool:
55 """
56 :return: Whether or not the Visual Novel has an ending theme
57 """
58 return len(self.eds) > 0
60 @property
61 def has_op(self) -> bool:
62 """
63 :return: Whether or not the Visual Novel has an opening theme
64 """
65 return len(self.ops) > 0
67 @property
68 def has_cgs(self) -> bool:
69 """
70 :return: Whether or not the Visual Novel has a CG gallery
71 """
72 return len(self.cgs) > 0
74 @property
75 def has_ost(self) -> bool:
76 """
77 :return: Whether or not the Visual Novel has an OST
78 """
79 return len(self.ost) > 0
81 @property
82 def cgs(self) -> Dict[str, List[str]]:
83 """
84 Generates a dictionary of paths to CG images
85 :return: A dictionary mapping the various CG images to their
86 respective directory identifiers
87 """
88 if not os.path.isdir(self.cg_dir):
89 return {}
90 else:
91 cgs: Dict[str, List[str]] = {}
92 for cg_dir, cg_dir_path in listdir(self.cg_dir, no_files=True):
93 cgs[cg_dir] = []
94 for _, img_path in listdir(cg_dir_path, no_dirs=True):
95 cgs[cg_dir].append(img_path)
96 return cgs
98 @property
99 def ost(self) -> List[str]:
100 """
101 :return: a list of files for the OST of a visual novel
102 """
103 return self._get_file_list(self.ost_dir)
105 @property
106 def eds(self) -> List[str]:
107 """
108 :return: a list of ending theme videos
109 """
110 return self._get_file_list(self.video_dir, "ED")
112 @property
113 def ops(self) -> List[str]:
114 """
115 :return: a list of opening theme videos
116 """
117 return self._get_file_list(self.video_dir, "OP")
119 @staticmethod
120 def _get_file_list(path: str, prefix: Optional[str] = None) -> List[str]:
121 """
122 Retrieves a list of files from a directory
123 :param path: The path to check
124 :param prefix: An optional prefix
125 :return: The list of files
126 """
127 if not os.path.isdir(path):
128 return []
129 else:
130 files = []
131 for _file, file_path in listdir(path, no_dirs=True):
132 if prefix is not None and not _file.startswith(prefix):
133 continue
134 files.append(file_path)
135 return files