Mercurial > minori
annotate src/track/media.cc @ 367:8d45d892be88 default tip
*: instead of pugixml, use Qt XML features
this means we have one extra Qt dependency though...
author | Paper <paper@tflc.us> |
---|---|
date | Sun, 17 Nov 2024 22:55:47 -0500 |
parents | 886f66775f31 |
children |
rev | line source |
---|---|
301
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
1 #include "track/media.h" |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
2 #include "core/filesystem.h" |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
3 #include "core/session.h" |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
4 #include "core/strings.h" |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
5 |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
6 #include <QFile> |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
7 #include <QTextStream> |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
8 |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
9 #include <filesystem> |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
10 #include <string> |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
11 #include <unordered_map> |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
12 #include <vector> |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
13 |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
14 #include <iostream> |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
15 |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
16 #include "animone.h" |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
17 |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
18 namespace Track { |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
19 namespace Media { |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
20 |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
21 static bool GetCurrentlyPlayingResults(std::vector<animone::Result>& results) { |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
22 std::vector<animone::Player> players; |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
23 |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
24 players.reserve(session.config.recognition.players.size()); |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
25 for (const auto& [enabled, player] : session.config.recognition.players) |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
26 if (enabled && player.type == animone::PlayerType::Default) |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
27 players.push_back(player); |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
28 |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
29 return animone::GetResults(players, results); |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
30 } |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
31 |
366
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
343
diff
changeset
|
32 /* The results from this function are KIND OF guaranteed to be UTF-8; |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
343
diff
changeset
|
33 * more specifically any files returned are UTF-8 as required by the C++ |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
343
diff
changeset
|
34 * standard. However, window titles are not, and for some obscure X11 |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
343
diff
changeset
|
35 * window managers, WILL not be in UTF-8. I don't care enough about this |
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
343
diff
changeset
|
36 * to do anything about it though. */ |
301
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
37 bool GetCurrentlyPlaying(std::vector<std::string>& vec) { |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
38 std::vector<animone::Result> results; |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
39 |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
40 if (!GetCurrentlyPlayingResults(results)) |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
41 return false; |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
42 |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
43 bool success = false; |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
44 |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
45 for (const auto& result : results) { |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
46 for (const auto& media : result.media) { |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
47 for (const auto& info : media.information) { |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
48 switch (info.type) { |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
49 case animone::MediaInfoType::File: |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
50 vec.push_back(std::filesystem::path(info.value).filename().u8string()); |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
51 success |= true; |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
52 break; |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
53 case animone::MediaInfoType::Title: |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
54 vec.push_back(info.value); |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
55 success |= true; |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
56 break; |
343
1faa72660932
*: transfer back to cmake from autotools
Paper <paper@paper.us.eu.org>
parents:
317
diff
changeset
|
57 case animone::MediaInfoType::Tab: |
1faa72660932
*: transfer back to cmake from autotools
Paper <paper@paper.us.eu.org>
parents:
317
diff
changeset
|
58 break; |
1faa72660932
*: transfer back to cmake from autotools
Paper <paper@paper.us.eu.org>
parents:
317
diff
changeset
|
59 case animone::MediaInfoType::Url: |
1faa72660932
*: transfer back to cmake from autotools
Paper <paper@paper.us.eu.org>
parents:
317
diff
changeset
|
60 break; |
301
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
61 default: break; |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
62 } |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
63 } |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
64 } |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
65 } |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
66 |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
67 return success; |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
68 } |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
69 |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
70 } // namespace Media |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
279
diff
changeset
|
71 } // namespace Track |