Skip to content

Commit

Permalink
Api fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Metalit committed Mar 28, 2024
1 parent 72e2c25 commit 01f9391
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
6 changes: 0 additions & 6 deletions shared/PlaylistCore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,6 @@ namespace PlaylistCore {
/// @return The number of songs missing from the playlist
int PlaylistHasMissingSongs(Playlist* playlist);

/// @brief Downloads songs that are supposed to be in a playlist but not owned - does not modify the playlist
/// @param playlist The playlist to check for missing songs
/// @param finishCallback A function to run after all missing songs have been downloaded
/// @param updateCallback A function to run when each song is downloaded (args: number of songs downloaded, total songs to be downloaded)
void DownloadMissingSongsFromPlaylist(Playlist* playlist, std::function<void()> finishCallback = nullptr, std::function<void(int, int)> updateCallback = nullptr);

/// @brief Removes songs that are supposed to be in a playlist but not owned from the playlist
/// @param playlist The playlist to remove missing songs from
void RemoveMissingSongsFromPlaylist(Playlist* playlist);
Expand Down
12 changes: 7 additions & 5 deletions src/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,14 @@ namespace PlaylistCore {

std::string SanitizeFileName(std::string_view fileName) {
std::string newName;
// yes I know not all of these are disallowed, and also that they are unlikely to end up in a name
static const std::unordered_set<unsigned char> replacedChars = {
'/', '\n', '\\', '\'', '\"', ' ', '?', '<', '>', ':', '*'
// just whitelist simple characters
static const auto okChar = [](unsigned char c) {
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9')) return true;
if (c == '_' || c == '-' || c == '(' || c == ')') return true;
return false;
};
std::transform(fileName.begin(), fileName.end(), std::back_inserter(newName), [](unsigned char c) {
if(replacedChars.contains(c))
if(!okChar(c))
return (unsigned char)('_');
return c;
});
Expand All @@ -95,7 +97,7 @@ namespace PlaylistCore {
std::string GetNewPlaylistPath(std::string_view title) {
std::string fileTitle = SanitizeFileName(title);
while(!UniqueFileName(fileTitle + ".bplist_BMBF.json", GetPlaylistsPath()))
fileTitle += "_";
fileTitle = "_" + fileTitle;
return GetPlaylistsPath() + "/" + fileTitle + ".bplist_BMBF.json";
}

Expand Down

0 comments on commit 01f9391

Please sign in to comment.