Skip to content

Commit

Permalink
Add support for .nomedia file (cmus#1190)
Browse files Browse the repository at this point in the history
When adding directories, ignore folders that contains a .nomedia file.

This mimics the convention of the Android OS[1] to tell smartphone apps
not to display or include the contents of the folder, which is also
supported by different Desktop programs[2] and other multimedia
platforms[3]

[1] https://en.wikipedia.org/wiki/Hidden_file_and_hidden_directory#Android
[2]
   * https://forum.strawberrymusicplayer.org/topic/412/exclude-paths-directories-files-from-library/2?_=1652534386411&lang=en-US
   * clementine-player/Clementine#5327
[3] https://kodi.wiki/view/Update_Music_Library#Exclude_Folder
  • Loading branch information
fekir authored Sep 25, 2022
1 parent ade6e2a commit 166091d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions job.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,11 @@ static void add_dir(const char *dirname, const char *root)
struct dir_entry *ent;
int size;

if (strcmp(name, ".nomusic") == 0 || strcmp(name, ".nomedia") == 0) {
ptr_array_clear(&array);
break;
}

if (name[0] == '.')
continue;

Expand Down
13 changes: 13 additions & 0 deletions load_dir.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,17 @@ static inline void ptr_array_unique(struct ptr_array *array,
array->count = j;
}

static inline void ptr_array_clear(struct ptr_array *array)
{
void **ptrs = array->ptrs;

for (int i = 0; i != array->count; i++) {
free(ptrs[i]);
}
free(ptrs);
array->ptrs = NULL;
array->alloc = 0;
array->count = 0;
}

#endif

0 comments on commit 166091d

Please sign in to comment.