diff options
Diffstat (limited to 'apps/plugins')
-rw-r--r-- | apps/plugins/favorites.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/apps/plugins/favorites.c b/apps/plugins/favorites.c new file mode 100644 index 0000000000..59001647ac --- /dev/null +++ b/apps/plugins/favorites.c | |||
@@ -0,0 +1,51 @@ | |||
1 | #include "plugin.h" | ||
2 | #define FAVORITES_FILE "/favorites.m3u" | ||
3 | |||
4 | static struct plugin_api* rb; | ||
5 | |||
6 | enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | ||
7 | { | ||
8 | struct mp3entry* id3; | ||
9 | char track_path[MAX_PATH+1]; | ||
10 | int fd, seek, result, len; | ||
11 | |||
12 | /* this macro should be called as the first thing you do in the plugin. | ||
13 | it test that the api version and model the plugin was compiled for | ||
14 | matches the machine it is running on */ | ||
15 | TEST_PLUGIN_API(api); | ||
16 | |||
17 | /* if you don't use the parameter, you can do like | ||
18 | this to avoid the compiler warning about it */ | ||
19 | (void)parameter; | ||
20 | |||
21 | rb = api; | ||
22 | |||
23 | id3 = rb->mpeg_current_track(); | ||
24 | if (!id3) | ||
25 | return PLUGIN_ERROR; | ||
26 | |||
27 | fd = rb->open(FAVORITES_FILE, O_WRONLY); | ||
28 | |||
29 | // creat the file if it does not return on open. | ||
30 | if (fd < 0) | ||
31 | fd = rb->creat(FAVORITES_FILE, 0); | ||
32 | |||
33 | if (fd > 0) { | ||
34 | rb->strcpy(track_path, id3->path); | ||
35 | len = rb->strlen(track_path); | ||
36 | |||
37 | // seek to the end of file | ||
38 | seek = rb->lseek(fd, 0, SEEK_END); | ||
39 | // append the current mp3 path | ||
40 | track_path[len] = '\n'; | ||
41 | result = rb->write(fd, track_path, len + 1); | ||
42 | track_path[len] = '\0'; | ||
43 | rb->close(fd); | ||
44 | } | ||
45 | |||
46 | rb->splash(HZ*2, 0, true, "Saved Favorite"); | ||
47 | |||
48 | return PLUGIN_OK; | ||
49 | } | ||
50 | |||
51 | |||