Skip to content

Instantly share code, notes, and snippets.

@su8
Last active July 31, 2026 13:19
Show Gist options
  • Select an option

  • Save su8/389111a54167bdf3dd2027329ef0ee0a to your computer and use it in GitHub Desktop.

Select an option

Save su8/389111a54167bdf3dd2027329ef0ee0a to your computer and use it in GitHub Desktop.
favs.diff
96a97,99
> // Load,Save,Remove favourite song(s)
> std::vector<std::string> loadFav(void);
> void addFav(int toRemove);
100a104,106
> int highlight = 0;
> int showFavourites = 0;
> std::vector<Track> playlist;
101a108
> std::vector<Track> playlist3;
106a114
> bool showfavs = false;
110a119
> std::string mp3Home = (getenv("HOME") ? static_cast<std::string>(getenv("HOME")) : static_cast<std::string>(".")) + static_cast<std::string>("/0verau.list");
115a125
> if (argc > 2) { showfavs = true; }
118c128
< auto playlist = listAudioFiles(musicDir);
---
> playlist = listAudioFiles(musicDir);
138d147
< int highlight = 0;
182a192,194
> else if (showFavourites == 1) {
> drawStatus(rows, cols, playlist3, highlight, colorPair, status, offset, shuffle, repeat, volume, searchQuery, keys, showHideAlbum, showHideArtist, playlist3);
> }
204a217,221
> else if (showFavourites == 1) {
> if (!playlist3.empty()) {
> highlight = (highlight - 1 + playlist3.size()) % playlist3.size();
> }
> }
214a232,236
> else if (showFavourites == 1) {
> if (!playlist3.empty()) {
> highlight = (highlight + 1) % playlist3.size();
> }
> }
243a266,276
> else if (showFavourites == 1) {
> addFav(0);
> /*if (!playlist3.empty()) {
> if (choice == keys["PREVIOUS_SONG"]) {
> highlight = (highlight - 1 + playlist3.size()) % playlist3.size();
> }
> else if (choice == keys["NEXT_SONG"]) {
> highlight = (highlight + 1 + playlist3.size()) % playlist3.size();
> }
> }*/
> }
291a325,331
> else if (choice == keys["REMOVE_FROM_FAVS"]) {
> if (!playlist3.empty()) {
> playlist3[highlight].path = "";
> playlist3[highlight].title = "";
> addFav(1);
> }
> }
315a356,364
> else if (choice == keys["SHOW_HIDE_FAVOURITES"]) {
> showFavourites = !showFavourites;
> }
> else if (choice == keys["ADD_FAVOURITE"]) {
> if (argc > 2) {
> if (showFavourites == 0) { showfavs = true; addFav(0); }
> else addFav(1);
> }
> }
401a451,485
> std::vector<std::string> loadFav(void) {
> std::vector<std::string> fav;
> std::vector<std::string> favEmpty = {""};
> if (showfavs == false) { return favEmpty; }
> std::string line;
> std::ifstream favs(mp3Home);
> if (!favs.is_open()) return !fav.empty() ? fav : favEmpty;
> playlist3.clear();
> while (std::getline(favs, line)) {
> if (line.empty()) continue;
> fav.push_back(line);
> playlist3.push_back(readMetadata(line));
> }
> favs.close();
> //playlist3.push_back(playlist[highlight]);
> return !fav.empty() ? fav : favEmpty;
> }
>
> void addFav(int toRemove) {
> std::vector<std::string> favs = loadFav();
> if (toRemove == 1) {
> unsigned int x = 0U;
> for (; x < favs.size(); x++) {
> if (favs[x] == playlist3[highlight].path) { favs[x] = ""; break; }
> }
> }
> std::ofstream fileToSave(mp3Home, std::ios::trunc);
> unsigned int songMatch = 0U;
> if (!fileToSave) return;
> if (!favs.empty()) { for (const auto &savedFav : favs) { fileToSave << savedFav << "\n"; } }
> for (const auto &line : favs) { if (line == playlist[highlight].path) { songMatch = 1U; break; } }
> if (songMatch == 0U && toRemove == 0) fileToSave << playlist[highlight].path << "\n";
> else showFavourites = 0U;
> }
>
834a919
> {"SHOW_HIDE_FAVOURITES", '('}, {"ADD_FAVOURITE", ')'}, {"REMOVE_FROM_FAVS", '['},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment