-
Notifications
You must be signed in to change notification settings - Fork 0
/
song.c
89 lines (71 loc) · 2.31 KB
/
song.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "song.h"
#include <mpd/client.h>
#include "constants.h"
#include "log.h"
#include "status.h"
#include "util.h"
void print_current_song(struct mpd_connection *connection) {
struct mpd_song *song;
song = mpd_run_current_song(connection);
if (song == NULL) {
die(connection, NULL, NULL, RECV_SONG_FAIL); /* song is null anyways */
}
mpd_check_error(connection, NULL, song);
const char *artist = mpd_song_get_tag(song, MPD_TAG_ARTIST, 0);
const char *title = mpd_song_get_tag(song, MPD_TAG_TITLE, 0);
printf("%s - %s\n", artist ? artist : NULL_STRING, title ? title : NULL_STRING);
mpd_song_free(song);
#ifdef DEBUG
log_info("Got current song information");
#endif
}
void print_current_song_metadata(struct mpd_connection *connection) {
int i;
const char *uri;
struct mpd_song *song;
song = mpd_run_current_song(connection);
if (song == NULL) {
die(connection, NULL, NULL, RECV_SONG_FAIL);
}
mpd_check_error(connection, NULL, song);
uri = mpd_song_get_uri(song);
if (uri == NULL) {
die(connection, NULL, NULL, RECV_SONG_FAIL);
}
mpd_check_error(connection, NULL, song);
printf("URI: %s\n", uri);
/* the first 10 fields are the most relevant ones */
for (i = 0; i < 10; ++i) {
const char *field_name = mpd_tag_name(i);
const char *field_value = mpd_song_get_tag(song, i, 0);
printf("%s: %s\n", field_name, field_value ? field_value : NULL_STRING);
}
mpd_check_error(connection, NULL, song);
mpd_song_free(song);
#ifdef DEBUG
log_info("Got current song metadata");
#endif
}
void loop_current_song(struct mpd_connection *connection, int loop_count) {
int i;
struct mpd_song *song;
if (loop_count < 0) {
die(connection, NULL, NULL, REMOVE_NEGATIVE_FAIL);
}
song = mpd_run_current_song(connection);
if (song == NULL) {
die(connection, NULL, NULL, RECV_SONG_FAIL);
}
mpd_check_error(connection, NULL, song);
const char *file_uri = mpd_song_get_uri(song);
if (file_uri) {
for (i = 0; i < loop_count; ++i) {
mpd_run_add(connection, file_uri);
mpd_check_error(connection, NULL, song);
}
}
mpd_song_free(song);
#ifdef DEBUG
log_info("Looped current song %d times", loop_count);
#endif
}