Ejemplo n.º 1
0
int cmd_playlist(int argc, char **argv)
{
	int index, i;
	sp_track *track;
	sp_playlist *playlist;
	sp_playlistcontainer *pc = sp_session_playlistcontainer(g_session);

	if (argc < 1) {
		printf("playlist [playlist index]\n");
		return 0;
	}

	index = atoi(argv[1]);
	if (index < 0 || index > sp_playlistcontainer_num_playlists(pc)) {
		printf("invalid index\n");
		return 0;
	}
	playlist = sp_playlistcontainer_playlist(pc, index);
	printf("Playlist %s by %s%s%s\n",
		   sp_playlist_name(playlist),
		   sp_user_display_name(sp_playlist_owner(playlist)),
		   sp_playlist_is_collaborative(playlist) ? " (collaborative)" : "",
		   sp_playlist_has_pending_changes(playlist) ? " with pending changes" : ""
		   );
	for (i = 0; i < sp_playlist_num_tracks(playlist); ++i) {
		track = sp_playlist_track(playlist, i);
		printf("%d. %c %s%s %s\n", i,
			   sp_track_is_starred(g_session, track) ? '*' : ' ',
			   sp_track_is_local(g_session, track) ? "local" : "     ",
			   sp_track_is_autolinked(g_session, track) ? "autolinked" : "          ",
			   sp_track_name(track));
	}
	return 1;
}
Ejemplo n.º 2
0
const char* SxPlaylist::getOwnerName() {
    sp_user* user = sp_playlist_owner(m_spPlaylist);
    if (user != sp_session_user(Session::getInstance()->getSpSession())) {
        return sp_user_display_name(user);
    }
    return NULL;
}
Ejemplo n.º 3
0
PHP_METHOD(SpotifyPlaylist, getOwner)
{
	sp_user *user;
	zval temp, *spotifyobject;
	spotifyplaylist_object *p = (spotifyplaylist_object*)zend_object_store_get_object(getThis() TSRMLS_CC);

	spotifyobject = zend_read_property(spotifyplaylist_ce, getThis(), "spotify", strlen("spotify"), NOISY TSRMLS_CC);

	user = sp_playlist_owner(p->playlist);

	object_init_ex(return_value, spotifyuser_ce);
	SPOTIFY_METHOD2(SpotifyUser, __construct, &temp, return_value, spotifyobject, user);
}
Ejemplo n.º 4
0
json_t *playlist_to_json(sp_playlist *playlist, json_t *object) {
  assert(sp_playlist_is_loaded(playlist));

  // Owner
  sp_user *owner = sp_playlist_owner(playlist);
  const char *username = sp_user_display_name(owner);
  sp_user_release(owner);
  json_object_set_new_nocheck(object, "creator",
                              json_string_nocheck(username));

  // URI
  size_t playlist_uri_len = strlen("spotify:user:"******":playlist:") +
                            strlen("284on3DVWeAxWkgVuzZKGt");
  char *playlist_uri = malloc(playlist_uri_len);

  if (playlist_uri == NULL) {
    return NULL;
  }

  sp_link *playlist_link = sp_link_create_from_playlist(playlist);
  sp_link_as_string(playlist_link, playlist_uri, playlist_uri_len);
  sp_link_release(playlist_link);
  json_object_set_new(object, "uri", 
                      json_string_nocheck(playlist_uri));
  free(playlist_uri);

  // Title
  const char *title = sp_playlist_name(playlist);
  json_object_set_new(object, "title",
                      json_string_nocheck(title));

  // Collaborative
  playlist_to_json_set_collaborative(playlist, object);

  // Description
  const char *description = sp_playlist_get_description(playlist);

  if (description != NULL) {
    json_object_set_new(object, "description",
                        json_string_nocheck(description));
  }

  // Number of subscribers
  int num_subscribers = sp_playlist_num_subscribers(playlist);
  json_object_set_new(object, "subscriberCount",
                      json_integer(num_subscribers));

  // Tracks
  json_t *tracks = json_array();
  json_object_set_new(object, "tracks", tracks);
  char track_uri[kTrackLinkLength];

  for (int i = 0; i < sp_playlist_num_tracks(playlist); i++) {
    sp_track *track = sp_playlist_track(playlist, i);
    sp_link *track_link = sp_link_create_from_track(track, 0);
    sp_link_as_string(track_link, track_uri, kTrackLinkLength);
    json_array_append(tracks, json_string_nocheck(track_uri));
    sp_link_release(track_link);
  }

  return object;
}
Ejemplo n.º 5
0
jobject createJPlaylist(JNIEnv *env, sp_playlist *playlist)
{
    jclass jClass;
    jobject playlistInstance;
    jmethodID jMethod;

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

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

    sp_link *playlistLink = sp_link_create_from_playlist(playlist);
    if (playlistLink)
    {
        jobject playlistJLink = createJLinkInstance(env,playlistLink);
        setObjectObjectField(env,playlistInstance,"id","Ljahspotify/media/Link;",playlistJLink);
        sp_link_release(playlistLink);
    }

    setObjectStringField(env,playlistInstance,"name",sp_playlist_name(playlist));

    sp_user *owner = sp_playlist_owner(playlist);
    if (owner)
    {
        setObjectStringField(env,playlistInstance,"author",sp_user_display_name(owner));
        sp_user_release(owner);
    }

    // Lookup the method now - saves us looking it up for each iteration of the loop
    jMethod = (*env)->GetMethodID(env,jClass,"addTrack","(Ljahspotify/media/Link;)V");

    if (jMethod == NULL)
    {
        fprintf(stderr,"jahspotify::createJPlaylist: could not load method addTrack(track) on class Playlist\n");
        return NULL;
    }

    int numTracks = sp_playlist_num_tracks(playlist);
    int trackCounter = 0;
    for (trackCounter = 0 ; trackCounter < numTracks; trackCounter++)
    {
        sp_track *track = sp_playlist_track(playlist,trackCounter);
        if (track)
        {
            sp_track_add_ref(track);
            sp_link *trackLink = sp_link_create_from_track(track, 0);
            if (trackLink)
            {
                sp_link_add_ref(trackLink);
                jobject trackJLink = createJLinkInstance(env,trackLink);
                // Add it to the playlist
                (*env)->CallVoidMethod(env,playlistInstance,jMethod,trackJLink);
                sp_link_release(trackLink);
            }
            sp_track_release(track);

        }
    }

    return playlistInstance;

}