Coretex
utils.py
1 # Copyright (C) 2023 Coretex LLC
2 
3 # This file is part of Coretex.ai
4 
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License as
7 # published by the Free Software Foundation, either version 3 of the
8 # License, or (at your option) any later version.
9 
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU Affero General Public License for more details.
14 
15 # You should have received a copy of the GNU Affero General Public License
16 # along with this program. If not, see <https://www.gnu.org/licenses/>.
17 
18 # from typing import Optional
19 # from pathlib import Path
20 
21 # from ..coretex import CustomSample
22 # from ..utils import guessMimeType, InvalidFileExtension
23 
24 
25 # def getTxtFilePath(sample: CustomSample) -> Optional[Path]:
26  # """
27  # Looks for text file in Coretex sample
28  # If extension is .txt file is considered textual
29 
30  # Parameters
31  # ----------
32  # sample : CustomSample
33  # sample to be searched
34 
35  # Returns
36  # -------
37  # Optional[Path] -> first occurence of .txt file if there is any, None otherwise
38  # """
39 
40 # folderContent = list(sample.load().folderContent)
41 # for path in folderContent:
42 # if path.suffix == ".txt":
43 # return path
44 
45 # return None
46 
47 
48 # def isTxtSample(sample: CustomSample) -> bool:
49  # """
50  # Checks whether sample is text sample or not
51 
52  # Parameters
53  # ----------
54  # sample : CustomSample
55  # sample to be checked
56 
57  # Returns
58  # -------
59  # bool -> True if sample is text sample, False otherwise
60  # """
61 
62 # return getTxtFilePath(sample) is not None
63 
64 
65 # def getAudioFilePath(sample: CustomSample) -> Optional[Path]:
66  # """
67  # Looks for any kind of audio file in Coretex sample
68  # Guesses mime type of the file and looks for any kind of audio mime type
69 
70  # Parameters
71  # ----------
72  # sample : CustomSample
73  # sample to be searched
74 
75  # Returns
76  # -------
77  # Optional[Path] -> first occurence of audio file if there is any, None otherwise
78  # """
79 
80 # folderContent = list(sample.load().folderContent)
81 # for path in folderContent:
82 # try:
83 # mimeType = guessMimeType(str(path))
84 # if "audio" in mimeType:
85 # return path
86 # except InvalidFileExtension:
87 # continue
88 
89 # return None
90 
91 
92 # def isAudioSample(sample: CustomSample) -> bool:
93  # """
94  # Checks whether sample is audio sample or not
95 
96  # Parameters
97  # ----------
98  # sample : CustomSample
99  # sample to be checked
100 
101  # Returns
102  # -------
103  # bool -> True if sample is audio sample, False otherwise
104  # """
105 
106 # return getAudioFilePath(sample) is not None