summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTursiae <git@tursiae.org>2025-06-19 21:28:06 +1000
committerTursiae <git@tursiae.org>2025-07-01 21:26:35 +1000
commitb5d302e1167cc44a24763e346a32c989dbd0601a (patch)
tree20f6508c88bc8240cfc8f177a04b0b59b9142da7
parent42fc963acc81860b7cc794550e13e8920e547d93 (diff)
downloadtangara-fw-b5d302e1167cc44a24763e346a32c989dbd0601a.tar.gz
Handle file:/// URIs generated from VLC playlists.
-rw-r--r--src/tangara/audio/playlist.cpp34
-rw-r--r--src/tangara/audio/playlist.hpp1
2 files changed, 35 insertions, 0 deletions
diff --git a/src/tangara/audio/playlist.cpp b/src/tangara/audio/playlist.cpp
index 6ed5f162..d0c7e5a3 100644
--- a/src/tangara/audio/playlist.cpp
+++ b/src/tangara/audio/playlist.cpp
@@ -308,6 +308,40 @@ auto Playlist::nextItem(std::span<TCHAR> buf)
if (line.ends_with('\r')) {
line = line.substr(0, line.size() - 1);
}
+
+ const char *kMacFilePrefix = "file:///Volumes/";
+ // Handle absolute URIs that came from VLC on Mac by stripping the leading file:///Volumes/Foo/.
+ if (line.find(kMacFilePrefix) == 0) {
+ size_t second_slash = line.find("/", strlen(kMacFilePrefix));
+ if (second_slash != std::string::npos) {
+ line = line.substr(second_slash + 1);
+ }
+ }
+
+ mutated_ = "";
+ // Does this look like a URL-encoded path? Decode it to a filename.
+ // Tangara handles filenames, not URIs.
+ if (line.find('%') != std::string::npos) {
+ mutated_.reserve(line.size());
+ for (size_t n = 0; n < line.size(); ++n) {
+ if (n < (line.size() - 2) && line[n] == '%' &&
+ (isdigit(line[n+1]) || (line[n+1] >= 'a' && line[n+1] <= 'f') || (line[n+1] >= 'A' && line[n+1] <= 'F')) &&
+ (isdigit(line[n+2]) || (line[n+2] >= 'a' && line[n+2] <= 'f') || (line[n+2] >= 'A' && line[n+2] <= 'F'))) {
+ char value = 0;
+ if (isdigit(line[n+1])) value += (line[n+1] - '0') << 4;
+ if (isdigit(line[n+2])) value += (line[n+2] - '0') << 0;
+ if (line[n+1] >= 'a' && line[n+1] <= 'f') value += (0x0a + line[n+1] - 'a') << 4;
+ if (line[n+2] >= 'a' && line[n+2] <= 'f') value += (0x0a + line[n+2] - 'a') << 0;
+ if (line[n+1] >= 'A' && line[n+1] <= 'F') value += (0x0A + line[n+1] - 'A') << 4;
+ if (line[n+2] >= 'A' && line[n+2] <= 'F') value += (0x0A + line[n+2] - 'A') << 0;
+ mutated_ += value;
+ n += 2;
+ } else {
+ mutated_ += line[n];
+ }
+ }
+ line = mutated_;
+ }
return line;
}
diff --git a/src/tangara/audio/playlist.hpp b/src/tangara/audio/playlist.hpp
index 1e05e9c4..2f73d57a 100644
--- a/src/tangara/audio/playlist.hpp
+++ b/src/tangara/audio/playlist.hpp
@@ -51,6 +51,7 @@ class Playlist {
protected:
const std::string filepath_;
+ std::string mutated_;
mutable std::mutex mutex_;
size_t total_size_;