Permalink
Browse files

Dump cover art command for simple client.

  • Loading branch information...
1 parent 47168d4 commit 3444c1bb5be3c95683e89affbec413e5d18b48cb dstien committed Dec 13, 2010
Showing with 46 additions and 5 deletions.
  1. +0 −1 src/clients/despotify/session.c
  2. +0 −1 src/clients/despotify/ui.c
  3. +46 −3 src/clients/simple/simple.c
@@ -196,7 +196,6 @@ void sess_password(const char *password)
{
free(g_session.password);
g_session.password = strdup(password);
-
sess_connect();
}
@@ -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);
@@ -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"
@@ -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");
@@ -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) {

0 comments on commit 3444c1b

Please sign in to comment.