Пример #1
0
static PyObject *
User_picture(User *self)
{
    const char *picture;

    picture = sp_user_picture(self->_user);
    if (!picture)
        Py_RETURN_NONE;
    return PyUnicode_FromString(picture);
}
Пример #2
0
JNIEXPORT jobject JNICALL Java_jahspotify_impl_JahSpotifyImpl_retrieveUser (JNIEnv *env, jobject obj)
{
    sp_user *user = sp_session_user(g_sess);
    const char *value = NULL;
    int country = 0;

    while (!sp_user_is_loaded(user))
    {
        fprintf ( stderr, "jahspotify::Java_jahspotify_impl_JahSpotifyImpl_retrieveUser: waiting for user to load\n" );
        sleep(1);
    }

    jclass jClass = (*env)->FindClass(env, "jahspotify/media/User");
    if (jClass == NULL)
    {
        fprintf(stderr,"jahspotify::Java_jahspotify_impl_JahSpotifyImpl_retrieveUser: could not load jahnotify.media.User\n");
        return NULL;
    }

    jobject userInstance = (*env)->AllocObject(env,jClass);
    if (!userInstance)
    {
        fprintf(stderr,"jahspotify::Java_jahspotify_impl_JahSpotifyImpl_retrieveUser: could not create instance of jahspotify.media.User\n");
        return NULL;
    }

    while (!sp_user_is_loaded(user))
    {
        sleep(1);
    }

    if (sp_user_is_loaded(user))
    {
        fprintf ( stderr, "jahspotify::Java_jahspotify_impl_JahSpotifyImpl_retrieveUser: user is loaded\n" );
        value = sp_user_full_name(user);
        if (value)
        {
            setObjectStringField(env,userInstance,"fullName",value);
        }
        value = sp_user_canonical_name(user);
        if (value)
        {
            setObjectStringField(env,userInstance,"userName",value);
        }
        value = sp_user_display_name(user);
        if (value)
        {
            setObjectStringField(env,userInstance,"displayName",value);
        }
        value = sp_user_picture(user);
        if (value)
        {
            setObjectStringField(env,userInstance,"imageURL",value);
        }

        // Country encoded in an integer 'SE' = 'S' << 8 | 'E'
        country = sp_session_user_country(g_sess);
        char countryStr[] = "  ";
        countryStr[0] = (byte)(country >> 8);
        countryStr[1] = (byte)country;
        setObjectStringField(env,userInstance,"country",countryStr);

        return userInstance;
    }

    return NULL;

}