diff options
| author | cooljqln <cooljqln@noreply.codeberg.org> | 2025-07-25 03:38:30 +0200 |
|---|---|---|
| committer | cooljqln <cooljqln@noreply.codeberg.org> | 2025-07-25 03:38:30 +0200 |
| commit | b68ac702817316e75270355e19231e04f484cb74 (patch) | |
| tree | 2a1407be70ca6c63d390c492b7f4505497e9218c | |
| parent | 855e69c93a507561b250e92e79a619fead07236a (diff) | |
| parent | 032ba5383f44277e8f579ac1f8300aede7bf2cd2 (diff) | |
| download | tangara-fw-b68ac702817316e75270355e19231e04f484cb74.tar.gz | |
Merge pull request 'Handle file:/// URIs generated from VLC playlists.' (#407) from tursiae/tangara-fw:vlcm3u into main
Reviewed-on: https://codeberg.org/cool-tech-zone/tangara-fw/pulls/407
| -rw-r--r-- | src/tangara/audio/playlist.cpp | 27 | ||||
| -rw-r--r-- | src/tangara/audio/playlist.hpp | 1 |
2 files changed, 28 insertions, 0 deletions
diff --git a/src/tangara/audio/playlist.cpp b/src/tangara/audio/playlist.cpp index 6ed5f162..89d7e378 100644 --- a/src/tangara/audio/playlist.cpp +++ b/src/tangara/audio/playlist.cpp @@ -308,6 +308,33 @@ 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] == '%' && + std::isxdigit(line[n+1]) && std::isxdigit(line[n+2])) { + char value = std::stoi(std::string(line.substr(n+1, 2)), 0, 16); + 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_; |
