Exemplo n.º 1
0
static int
lfm_action_lookup (DB_plugin_action_t *action, DB_playItem_t *it)
{
    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);
    return 0;
}
Exemplo n.º 2
0
// returns number of encoded chars on success
// or -1 on error
static int
lfm_add_keyvalue_uri_encoded (char **out, int *outl, const char *key, const char *value) {
    int ll = *outl;
    int keyl = strlen (key);
    if (*outl <= keyl+1) {
        return -1;
    }
    // append key and '=' sign
    memcpy (*out, key, keyl);
    (*out)[keyl] = '=';
    *out += keyl+1;
    *outl -= keyl+1;
    // encode and append value
    int l = lfm_uri_encode (*out, *outl, value);
    if (l < 0) {
        return -1;
    }
    *out += l;
    *outl -= l;
    // append '&'
    if (*outl <= 1) {
        return -1;
    }
    strcpy (*out, "&");
    *out += 1;
    *outl -= 1;
    return ll - *outl;
}
Exemplo n.º 3
0
static int
lfm_action_lookup (DB_plugin_action_t *action, int ctx)
{
    char *command = NULL;
    DB_playItem_t *it = NULL;
    char artist[META_FIELD_SIZE];
    char title[META_FIELD_SIZE];

    if (ctx == DDB_ACTION_CTX_SELECTION) {
        // find first selected
        ddb_playlist_t *plt = deadbeef->plt_get_curr ();
        if (plt) {
            it = deadbeef->plt_get_first (plt, PL_MAIN);
            while (it) {
                if (deadbeef->pl_is_selected (it)) {
                    break;
                }
                DB_playItem_t *next = deadbeef->pl_get_next (it, PL_MAIN);
                deadbeef->pl_item_unref (it);
                it = next;
            }
            deadbeef->plt_unref (plt);
        }
    }
    else if (ctx == DDB_ACTION_CTX_NOWPLAYING) {
        it = deadbeef->streamer_get_playing_track ();
    }
    if (!it) {
        goto out;
    }

    if (!deadbeef->pl_get_meta (it, "artist", artist, sizeof (artist))) {
        goto out;
    }
    if (!deadbeef->pl_get_meta (it, "title", title, sizeof (title))) {
        goto out;
    }

    int la = strlen (artist) * 3 + 1;
    int lt = strlen (title) * 3 + 1;
    char *eartist = alloca (la);
    char *etitle = alloca (lt);

    if (-1 == lfm_uri_encode (eartist, la, artist)) {
        goto out;
    }

    if (-1 == lfm_uri_encode (etitle, lt, title)) {
        goto out;
    }

    if (-1 == asprintf (&command, "xdg-open 'http://www.last.fm/music/%s/_/%s' &", eartist, etitle)) {
        goto out;
    }

    int res = system (command);
out:
    if (it) {
        deadbeef->pl_item_unref (it);
    }
    if (command) {
        free (command);
    }
    return 0;
}