├── commiter.yml ├── .gitignore ├── Makefile └── mpdaddtoplaylist.c /commiter.yml: -------------------------------------------------------------------------------- 1 | convention: symphony 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | mpdaddtoplaylist 2 | mpdtoggletoplaylist 3 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | build: 2 | gcc mpdaddtoplaylist.c -o mpdaddtoplaylist -lmpdclient 3 | 4 | clean: 5 | rm mpdaddtoplaylist 6 | 7 | install: build 8 | cp mpdaddtoplaylist ~/.config/polybar/scripts/ 9 | -------------------------------------------------------------------------------- /mpdaddtoplaylist.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | //#define DEBUG 5 | #ifdef DEBUG 6 | #define D(x) \ 7 | do { \ 8 | x; \ 9 | } while (0) 10 | #else 11 | #define D(x) \ 12 | do { \ 13 | } while (0) 14 | #endif 15 | 16 | #define HOST "android" 17 | #define PORT 6600 // usually it's 6600 18 | /* #define PASS "mpdsky" // comment out if no password */ 19 | #define PLAYLIST "favourite" 20 | 21 | struct mpd_connection* conn() 22 | { 23 | D(printf("%s %s\n", "Connecting to", HOST)); 24 | const char* host = HOST; 25 | unsigned port = PORT; 26 | struct mpd_connection* c = mpd_connection_new(host, port, 0); 27 | 28 | enum mpd_error err = mpd_connection_get_error(c); 29 | if (err != 0) { 30 | printf("Error code: %u. View error codes here: " 31 | "https://www.musicpd.org/doc/libmpdclient/error_8h.html\n", 32 | err); 33 | return 0; 34 | } 35 | 36 | #ifdef PASS 37 | const char* pass = PASS; 38 | if (mpd_run_password(c, pass) == false) { 39 | printf("%s\n", "Bad password"); 40 | return 0; 41 | } 42 | #endif 43 | 44 | D(printf("%s %s\n", "Connected to", HOST)); 45 | return c; 46 | } 47 | 48 | int main(int argc, char *argv[]) 49 | { 50 | struct mpd_connection* c = conn(); 51 | if (c == 0) 52 | return -1; 53 | 54 | struct mpd_song* curr = mpd_run_current_song(c); 55 | const char* curr_uri = mpd_song_get_uri(curr); 56 | D(printf("Currently playing: %s\n", curr_uri)); 57 | 58 | if (mpd_run_playlist_add(c, PLAYLIST, curr_uri)) { 59 | printf("%s %s %s %s\n", "Added", curr_uri, "to playlist", PLAYLIST); 60 | } else { 61 | printf("%s\n", "Some error"); 62 | return -1; 63 | } 64 | 65 | return 0; 66 | } 67 | --------------------------------------------------------------------------------