summaryrefslogtreecommitdiff
path: root/plugins/lastfm/lastfm.c
diff options
context:
space:
mode:
authorGravatar Viktor Semykin <thesame.ml@gmail.com>2010-05-25 03:37:44 +0300
committerGravatar Viktor Semykin <thesame.ml@gmail.com>2010-05-25 03:37:44 +0300
commit8c012917f5530d947c1a31adfc6aba4b0cf3853c (patch)
treef9183ee845fd497006dde0c5f80049714a15d9a4 /plugins/lastfm/lastfm.c
parentbe0f4b1926f7e77c7e03eae7b70ec12f1b905025 (diff)
Misc plugin actions
Diffstat (limited to 'plugins/lastfm/lastfm.c')
-rw-r--r--plugins/lastfm/lastfm.c62
1 files changed, 56 insertions, 6 deletions
diff --git a/plugins/lastfm/lastfm.c b/plugins/lastfm/lastfm.c
index 3ba8def8..02dff618 100644
--- a/plugins/lastfm/lastfm.c
+++ b/plugins/lastfm/lastfm.c
@@ -334,26 +334,31 @@ lfm_fetch_song_info (DB_playItem_t *song, const char **a, const char **t, const
static int
lfm_uri_encode (char *out, int outl, const char *str) {
int l = outl;
- static const char echars[] = " ;/?:@=#&+";
//trace ("lfm_uri_encode %p %d %s\n", out, outl, str);
while (*str) {
if (outl <= 1) {
//trace ("no space left for 1 byte in buffer\n");
return -1;
}
- if (strchr (echars, *str)) {
+
+ if (!(
+ (*str >= '0' && *str <= '9') ||
+ (*str >= 'a' && *str <= 'z') ||
+ (*str >= 'A' && *str <= 'Z') ||
+ (*str == ' ')
+ ))
+ {
if (outl <= 3) {
//trace ("no space left for 3 bytes in the buffer\n");
return -1;
}
- //trace ("adding escaped value for %c\n", *str);
- snprintf (out, outl, "%%%02x", (int)*str);
+ snprintf (out, outl, "%%%02x", (uint8_t)*str);
outl -= 3;
str++;
out += 3;
}
else {
- *out = *str;
+ *out = *str == ' ' ? '+' : *str;
out++;
str++;
outl--;
@@ -819,6 +824,50 @@ lastfm_stop (void) {
return 0;
}
+static int
+lfm_action_lookup (DB_playItem_t *it, void *data)
+{
+ const char *artist = deadbeef->pl_find_meta (it, "artist");
+ const char *title = deadbeef->pl_find_meta (it, "title");
+
+ if (!title || !artist)
+ return 0;
+
+ char eartist [strlen (artist) * 3 + 1];
+ char etitle [strlen (title) * 3 + 1];
+
+ if (-1 == lfm_uri_encode (eartist, sizeof (eartist), artist))
+ return 0;
+
+ if (-1 == lfm_uri_encode (etitle, sizeof (etitle), title))
+ return 0;
+
+ char *command = NULL;
+ if (-1 == asprintf (&command, "xdg-open http://www.last.fm/music/%s/_/%s", eartist, etitle))
+ return 0;
+ system (command);
+ free (command);
+}
+
+static DB_single_action_t lookup_action = {
+ .title = "Lookup at Last.fm",
+ .callback = lfm_action_lookup
+};
+
+static int
+lfm_get_single_actions (DB_playItem_t *it, DB_single_action_t *actions[], int *size)
+{
+ if (deadbeef->pl_find_meta (it, "artist") &&
+ deadbeef->pl_find_meta (it, "title"))
+ {
+ actions[0] = &lookup_action;
+ *size = 1;
+ }
+ else
+ *size = 0;
+ return 1;
+}
+
static const char settings_dlg[] =
"property \"Enable scrobbler\" checkbox lastfm.enable 0;"
"property \"Disable nowplaying\" checkbox lastfm.disable_np 0;"
@@ -840,5 +889,6 @@ static DB_misc_t plugin = {
.plugin.website = "http://deadbeef.sf.net",
.plugin.start = lastfm_start,
.plugin.stop = lastfm_stop,
- .plugin.configdialog = settings_dlg
+ .plugin.configdialog = settings_dlg,
+ .get_single_actions = lfm_get_single_actions
};