Mercurial > minori
comparison src/track/types.cc @ 118:39521c47c7a3
*: another huge megacommit, SORRY
The torrents page works a lot better now
Added the edit option to the anime list right click menu
Vectorized currently playing files
Available player and extensions are now loaded at runtime
from files in (dotpath)/players.json and (dotpath)/extensions.json
These paths are not permanent and will likely be moved to
(dotpath)/recognition
...
...
...
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Tue, 07 Nov 2023 23:40:54 -0500 |
parents | |
children | 0a458cb26ff4 |
comparison
equal
deleted
inserted
replaced
117:2c1b6782e1d0 | 118:39521c47c7a3 |
---|---|
1 #include "track/types.h" | |
2 #include "core/filesystem.h" | |
3 #include "core/json.h" | |
4 #include <fstream> | |
5 #include <vector> | |
6 #include <string> | |
7 | |
8 using namespace nlohmann::literals::json_literals; | |
9 | |
10 namespace Track { | |
11 namespace Types { | |
12 | |
13 static nlohmann::json default_players = { | |
14 { | |
15 {"name", "VLC"}, | |
16 #ifdef MACOSX | |
17 {"executable", "VLC"}, | |
18 #elif defined(WIN32) | |
19 {"executable", "vlc.exe"}, | |
20 #else | |
21 {"executable", "vlc"}, | |
22 #endif | |
23 {"enabled", true} | |
24 }, | |
25 { | |
26 {"name", "mpv"}, | |
27 #ifdef WIN32 | |
28 {"executable", "mpv.exe"}, | |
29 #else | |
30 {"executable", "mpv"}, | |
31 #endif | |
32 {"enabled", true} | |
33 }, | |
34 #ifdef WIN32 | |
35 { | |
36 {"name", "MPC-HC x64"}, | |
37 {"executable", "mpc-hc64.exe"}, | |
38 {"enabled", true} | |
39 }, | |
40 { | |
41 {"name", "MPC-HC"}, | |
42 {"executable", "mpc-hc.exe"}, | |
43 {"enabled", true} | |
44 }, | |
45 { | |
46 {"name", "Windows Media Player"}, | |
47 {"executable", "wmplayer.exe"}, | |
48 {"enabled", true} | |
49 } | |
50 #elif defined(MACOSX) | |
51 { | |
52 {"name", "IINA"}, | |
53 {"executable", "IINA"}, | |
54 {"enabled", true} | |
55 }, | |
56 { | |
57 {"name", "QuickTime Player"}, | |
58 {"executable", "QuickTime Player"}, | |
59 {"enabled", false} | |
60 } | |
61 #else | |
62 { | |
63 {"name", "MPC-Qt"}, | |
64 {"executable", "mpc-qt"}, | |
65 {"enabled", true} | |
66 } | |
67 #endif | |
68 }; | |
69 | |
70 static nlohmann::json default_extensions = { | |
71 /* These are the four most common file extensions | |
72 according to... me. */ | |
73 { | |
74 {"extension", "mkv"}, | |
75 {"enabled", true} | |
76 }, | |
77 { | |
78 {"extension", "mp4"}, | |
79 {"enabled", true} | |
80 }, | |
81 { | |
82 {"extension", "m4v"}, | |
83 {"enabled", true} | |
84 }, | |
85 { | |
86 {"extension", "avi"}, | |
87 {"enabled", true} | |
88 }, | |
89 /* Matroska's retarded inbred cousin */ | |
90 { | |
91 {"extension", "webm"}, | |
92 {"enabled", true} | |
93 }, | |
94 /* QuickTime */ | |
95 { | |
96 {"extension", "mov"}, | |
97 {"enabled", true} | |
98 }, | |
99 { | |
100 {"extension", "qt"}, | |
101 {"enabled", true} | |
102 }, | |
103 /* MPEG transport stream */ | |
104 { | |
105 {"extension", "mts"}, | |
106 {"enabled", true} | |
107 }, | |
108 { | |
109 {"extension", "m2ts"}, | |
110 {"enabled", true} | |
111 }, | |
112 { | |
113 {"extension", "ts"}, | |
114 {"enabled", true} | |
115 }, | |
116 /* MPEG-1 */ | |
117 { | |
118 {"extension", "mpg"}, | |
119 {"enabled", true} | |
120 }, | |
121 { | |
122 {"extension", "mpeg"}, | |
123 {"enabled", true} | |
124 }, | |
125 { | |
126 {"extension", "mpe"}, | |
127 {"enabled", true} | |
128 }, | |
129 { | |
130 {"extension", "mpv"}, | |
131 {"enabled", true} | |
132 }, | |
133 /* MPEG-2 */ | |
134 { | |
135 {"extension", "m2v"}, | |
136 {"enabled", true} | |
137 }, | |
138 { | |
139 {"extension", "mp2"}, | |
140 {"enabled", true} | |
141 }, | |
142 /* 3GPP */ | |
143 { | |
144 {"extension", "3gp"}, | |
145 {"enabled", true} | |
146 }, | |
147 { | |
148 {"extension", "3g2"}, | |
149 {"enabled", true} | |
150 }, | |
151 /* Windows Media */ | |
152 { | |
153 {"extension", "asf"}, | |
154 {"enabled", true} | |
155 }, | |
156 { | |
157 {"extension", "wmv"}, | |
158 {"enabled", true} | |
159 }, | |
160 /* Adobe Flash */ | |
161 { | |
162 {"extension", "flv"}, | |
163 {"enabled", true} | |
164 }, | |
165 { | |
166 {"extension", "swf"}, // lol | |
167 {"enabled", false} | |
168 }, | |
169 /* Ogg Video */ | |
170 { | |
171 {"extension", "ogv"}, | |
172 {"enabled", true} | |
173 }, | |
174 /* RealPlayer... LOL */ | |
175 { | |
176 {"extension", "rm"}, | |
177 {"enabled", true} | |
178 }, | |
179 { | |
180 {"extension", "rmvb"}, | |
181 {"enabled", true} | |
182 }, | |
183 /* Nullsoft Streaming Video (Winamp) */ | |
184 { | |
185 {"extension", "nsv"}, | |
186 {"enabled", true} | |
187 }, | |
188 /* Material Exchange Format (Sony) */ | |
189 { | |
190 {"extension", "mxf"}, | |
191 {"enabled", true} | |
192 }, | |
193 }; | |
194 | |
195 void LoadPlayers(std::vector<MediaPlayer>& players) { | |
196 nlohmann::json json; | |
197 { | |
198 std::ifstream is(Filesystem::GetPlayersPath().GetPath()); | |
199 if (!is.is_open()) | |
200 json = default_players; | |
201 else | |
202 is >> json; | |
203 } | |
204 | |
205 players.reserve(json.size()); | |
206 for (const auto& item : json) { | |
207 MediaPlayer player; | |
208 player.SetName(JSON::GetString(item, "/name"_json_pointer)); | |
209 player.SetExecutable(JSON::GetString(item, "/executable"_json_pointer)); | |
210 player.SetEnabled(JSON::GetBoolean(item, "/enabled"_json_pointer)); | |
211 players.push_back(player); | |
212 } | |
213 } | |
214 | |
215 void LoadExtensions(std::vector<MediaExtension>& extensions) { | |
216 nlohmann::json json; | |
217 { | |
218 std::ifstream is(Filesystem::GetExtensionsPath().GetPath()); | |
219 if (!is.is_open()) | |
220 json = default_extensions; | |
221 else | |
222 is >> json; | |
223 } | |
224 | |
225 extensions.reserve(json.size()); | |
226 for (const auto& item : json) { | |
227 MediaExtension extension; | |
228 extension.SetExtension(JSON::GetString(item, "/extension"_json_pointer)); | |
229 extension.SetEnabled(JSON::GetBoolean(item, "/enabled"_json_pointer)); | |
230 extensions.push_back(extension); | |
231 } | |
232 } | |
233 | |
234 void SavePlayers(const std::vector<MediaPlayer>& players) { | |
235 nlohmann::json json = {}; | |
236 for (const auto& player : players) { | |
237 json.push_back({ | |
238 {"name", player.GetName()}, | |
239 {"executable", player.GetExecutable()}, | |
240 {"enabled", player.GetEnabled()} | |
241 }); | |
242 } | |
243 | |
244 { | |
245 std::ofstream os(Filesystem::GetPlayersPath().GetPath()); | |
246 if (!os.is_open()) | |
247 return; | |
248 os << std::setw(4) << json << std::endl; | |
249 } | |
250 } | |
251 | |
252 void SaveExtensions(const std::vector<MediaExtension>& extensions) { | |
253 nlohmann::json json = {}; | |
254 for (const auto& extension : extensions) { | |
255 json.push_back({ | |
256 {"extension", extension.GetExtension()}, | |
257 {"enabled", extension.GetEnabled()} | |
258 }); | |
259 } | |
260 | |
261 { | |
262 std::ofstream os(Filesystem::GetExtensionsPath().GetPath()); | |
263 if (!os.is_open()) | |
264 return; | |
265 os << std::setw(4) << json << std::endl; | |
266 } | |
267 } | |
268 | |
269 } | |
270 } |