Skip to content

Commit

Permalink
Dump cover art command for simple client.
Browse files Browse the repository at this point in the history
  • Loading branch information
dstien committed Dec 13, 2010
1 parent 47168d4 commit 3444c1b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/clients/despotify/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ void sess_password(const char *password)
{
free(g_session.password);
g_session.password = strdup(password);

sess_connect();
}

Expand Down
1 change: 0 additions & 1 deletion src/clients/despotify/ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,6 @@ void ui_show(ui_set_t show)
}
g_ui_elements[i].flags |= UI_FLAG_DIRTY;
g_ui_elements[i].flags &= ~UI_FLAG_OFFSCREEN;

}
else if (g_ui_elements[i].set != UI_SET_NONE) {
g_ui_elements[i].flags &= ~(UI_FLAG_FOCUS | UI_FLAG_DIRTY);
Expand Down
49 changes: 46 additions & 3 deletions src/clients/simple/simple.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ void print_help(void)
"album [num] List album for track [num]\n"
"uri [string] Display info about Spotify URI\n"
"portrait [num] Save artist portrait to portrait.jpg\n"
"cover [num] Save album cover art to cover.jpg\n"
"\n"
"play [num] Play track [num] in the last viewed list\n"
"playalbum [num] Play album for track [num]\n"
Expand Down Expand Up @@ -554,9 +555,9 @@ void command_loop(struct despotify_session* ds)
/* portrait */
else if (!strncmp(buf, "portrait", 8)) {
int num = 0;
if(strlen(buf) > 9)
num = atoi(buf + 9);

if(strlen(buf) > 9)
num = atoi(buf + 9);

if (!num) {
wrapper_wprintf(L"usage: portrait [num]\n");
Expand Down Expand Up @@ -590,6 +591,48 @@ void command_loop(struct despotify_session* ds)
despotify_free_artist_browse(a);
}

/* cover */
else if (!strncmp(buf, "cover", 5)) {
int num = 0;

if(strlen(buf) > 6)
num = atoi(buf + 6);

if (!num) {
wrapper_wprintf(L"usage: cover [num]\n");
continue;
}
if (!lastlist) {
wrapper_wprintf(L"No playlist\n");
continue;
}

/* find the requested album */
struct track* t = lastlist->tracks;
for (int i=1; i<num; i++)
t = t->next;

if (t) {
struct album_browse* a = despotify_get_album(ds, t->album_id);
if (a && a->cover_id[0]) {
int len;
void* cover = despotify_get_image(ds, a->cover_id, &len);
if (cover && len) {
wrapper_wprintf(L"Writing %d bytes into cover.jpg\n", len);
FILE* f = fopen("cover.jpg", "w");
if (f) {
fwrite(cover, len, 1, f);
fclose(f);
}
free(cover);
}
}
else
wrapper_wprintf(L"Album %s has no cover.\n", t->album);
despotify_free_album_browse(a);
}
}

/* play */
else if (!strncmp(buf, "play", 4) || !strncmp(buf, "next", 4)) {
if (!lastlist) {
Expand Down

0 comments on commit 3444c1b

Please sign in to comment.