Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Miscellaneous Despotify fixes
From 37075ed12045c9a45526799d3bf7e564c2536711 Mon Sep 17 00:00:00 2001
Message-Id: <37075ed12045c9a45526799d3bf7e564c2536711.1338408558.git.chris@arachsys.com>
From: Chris Webb <chris@arachsys.com>
Date: Mon, 21 May 2012 10:54:06 +0100
Subject: [PATCH 1/5] Simple handling of multi-disc albums
We append the tracks from any additional discs to treat multi-disc albums
as though they were one large disc.
Signed-off-by: Chris Webb <chris@arachsys.com>
---
lib/xml.c | 15 ++++++++++++++-
1 files changed, 14 insertions(+), 1 deletions(-)
diff --git a/lib/xml.c b/lib/xml.c
index 000e9d4..69832e0 100644
--- a/lib/xml.c
+++ b/lib/xml.c
@@ -376,11 +376,24 @@ static void parse_browse_album(ezxml_t top, struct album_browse* a, bool high_bi
xmlatoi(&a->year, top, "year", -1);
xmlatof(&a->popularity, top, "popularity", -1);
- /* TODO: support multiple discs per album */
a->tracks = calloc(1, sizeof(struct track));
ezxml_t disc = ezxml_get(top, "discs",0,"disc", -1);
a->num_tracks = parse_tracks(disc, a->tracks, false, high_bitrate);
+ /* Append extra discs to album */
+ struct track *last = a->tracks;
+ while (last->next)
+ last = last->next;
+ while ((disc = disc->next)) {
+ int offset = last->tracknumber;
+ last->next = calloc(1, sizeof(struct track));
+ a->num_tracks += parse_tracks(disc, last->next, false, high_bitrate);
+ do {
+ last = last->next;
+ last->tracknumber += offset;
+ } while (last->next);
+ }
+
/* Copy missing metadata from album to tracks */
int count = 0;
for (struct track *t = a->tracks; t; t = t->next) {
--
1.7.7.3
From 65b0021eabbef9a795ea31cfdf9114818b0adef9 Mon Sep 17 00:00:00 2001
Message-Id: <65b0021eabbef9a795ea31cfdf9114818b0adef9.1338408558.git.chris@arachsys.com>
In-Reply-To: <37075ed12045c9a45526799d3bf7e564c2536711.1338408558.git.chris@arachsys.com>
References: <37075ed12045c9a45526799d3bf7e564c2536711.1338408558.git.chris@arachsys.com>
From: Chris Webb <chris@arachsys.com>
Date: Mon, 21 May 2012 10:52:03 +0100
Subject: [PATCH 2/5] Ensure that hanging login attempts time-out after ten
seconds
Signed-off-by: Chris Webb <chris@arachsys.com>
---
lib/despotify.c | 11 +++++++++++
1 files changed, 11 insertions(+), 0 deletions(-)
diff --git a/lib/despotify.c b/lib/despotify.c
index 3201af5..56667c1 100644
--- a/lib/despotify.c
+++ b/lib/despotify.c
@@ -115,6 +115,12 @@ bool despotify_authenticate(struct despotify_session* ds,
}
DSFYDEBUG("session_connect() completed\n");
+ struct timeval timeout;
+ timeout.tv_sec = 10;
+ timeout.tv_usec = 0;
+ setsockopt(ds->session->ap_sock, SOL_SOCKET, SO_RCVTIMEO,
+ &timeout, sizeof(timeout));
+
switch (do_key_exchange(ds->session))
{
case 0: /* all ok */
@@ -160,6 +166,11 @@ bool despotify_authenticate(struct despotify_session* ds,
}
DSFYDEBUG("%s", "do_auth() completed\n");
+ timeout.tv_sec = 0;
+ timeout.tv_usec = 0;
+ setsockopt(ds->session->ap_sock, SOL_SOCKET, SO_RCVTIMEO,
+ &timeout, sizeof(timeout));
+
pthread_create(&ds->thread, NULL, &despotify_thread, ds);
pthread_mutex_lock(&ds->session->login_mutex);
--
1.7.7.3
From 9777a8206ab77812f6b88c8f7bd25cca104ddbc7 Mon Sep 17 00:00:00 2001
Message-Id: <9777a8206ab77812f6b88c8f7bd25cca104ddbc7.1338408558.git.chris@arachsys.com>
In-Reply-To: <37075ed12045c9a45526799d3bf7e564c2536711.1338408558.git.chris@arachsys.com>
References: <37075ed12045c9a45526799d3bf7e564c2536711.1338408558.git.chris@arachsys.com>
From: Chris Webb <chris@arachsys.com>
Date: Mon, 21 May 2012 13:29:53 +0100
Subject: [PATCH 3/5] Add artist info to struct album_browse
Signed-off-by: Chris Webb <chris@arachsys.com>
---
lib/despotify.h | 2 ++
lib/xml.c | 2 ++
2 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/lib/despotify.h b/lib/despotify.h
index 4e69a0a..8de46cc 100644
--- a/lib/despotify.h
+++ b/lib/despotify.h
@@ -77,6 +77,8 @@ struct album_browse
{
char name[STRING_LENGTH];
char id[33];
+ char artist[STRING_LENGTH];
+ char artist_id[33];
int num_tracks;
struct track* tracks;
int year;
diff --git a/lib/xml.c b/lib/xml.c
index 69832e0..547460d 100644
--- a/lib/xml.c
+++ b/lib/xml.c
@@ -372,6 +372,8 @@ static void parse_browse_album(ezxml_t top, struct album_browse* a, bool high_bi
{
xmlstrncpy(a->name, sizeof a->name, top, "name", -1);
xmlstrncpy(a->id, sizeof a->id, top, "id", -1);
+ xmlstrncpy(a->artist, sizeof a->artist, top, "artist", -1);
+ xmlstrncpy(a->artist_id, sizeof a->artist_id, top, "artist-id", -1);
xmlstrncpy(a->cover_id, sizeof a->cover_id, top, "cover", -1);
xmlatoi(&a->year, top, "year", -1);
xmlatof(&a->popularity, top, "popularity", -1);
--
1.7.7.3
From 56ca68d6110d8fc9a6e27fe585e06a2cee1f14f6 Mon Sep 17 00:00:00 2001
Message-Id: <56ca68d6110d8fc9a6e27fe585e06a2cee1f14f6.1338408558.git.chris@arachsys.com>
In-Reply-To: <37075ed12045c9a45526799d3bf7e564c2536711.1338408558.git.chris@arachsys.com>
References: <37075ed12045c9a45526799d3bf7e564c2536711.1338408558.git.chris@arachsys.com>
From: Chris Webb <chris@arachsys.com>
Date: Wed, 23 May 2012 17:17:13 +0100
Subject: [PATCH 4/5] Improve portability to BSD and Mac OS
Signed-off-by: Chris Webb <chris@arachsys.com>
---
lib/sndqueue.h | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/lib/sndqueue.h b/lib/sndqueue.h
index 932bef5..0f7b192 100644
--- a/lib/sndqueue.h
+++ b/lib/sndqueue.h
@@ -14,7 +14,8 @@
#if defined(__linux__)
#include <endian.h>
#endif
-#if defined(__FreeBSD__)
+#if defined(__FreeBSD__) | defined(__NetBSD__) || defined(__OpenBSD__) \
+ || defined(__DragonFly__) || defined(__APPLE__)
#include <machine/endian.h>
#define __BYTE_ORDER _BYTE_ORDER
#define __LITTLE_ENDIAN _LITTLE_ENDIAN
--
1.7.7.3
From c764dd60ad2837c5c53c7c92a92c964e50226e22 Mon Sep 17 00:00:00 2001
Message-Id: <c764dd60ad2837c5c53c7c92a92c964e50226e22.1338408558.git.chris@arachsys.com>
In-Reply-To: <37075ed12045c9a45526799d3bf7e564c2536711.1338408558.git.chris@arachsys.com>
References: <37075ed12045c9a45526799d3bf7e564c2536711.1338408558.git.chris@arachsys.com>
From: Chris Webb <chris@arachsys.com>
Date: Sat, 26 May 2012 10:03:31 +0100
Subject: [PATCH 5/5] Fix track georestriction and add playable_tracks to
struct album_browse
The despotify library already marks georestricted tracks as unplayable in
despotify_get_tracks() but doesn't do this in despotify_get_album(), leading
to hung connections when playing albums containing georestricted tracks. As
well as fixing this, we add a count of playable tracks to struct album_browse
so album listings can conveniently identify albums containing unplayable
tracks.
Signed-off-by: Chris Webb <chris@arachsys.com>
---
lib/despotify.c | 11 ++++++++++-
lib/despotify.h | 1 +
2 files changed, 11 insertions(+), 1 deletions(-)
diff --git a/lib/despotify.c b/lib/despotify.c
index 56667c1..1d2577b 100644
--- a/lib/despotify.c
+++ b/lib/despotify.c
@@ -1307,7 +1307,7 @@ struct album_browse* despotify_get_album(struct despotify_session* ds,
xml_parse_browse_album(ds->album_browse, data, len, ds->high_bitrate);
free(data);
- return ds->album_browse;
+ goto out;
}
}
@@ -1342,6 +1342,15 @@ struct album_browse* despotify_get_album(struct despotify_session* ds,
}
buf_free(ds->response);
+out:
+ ds->album_browse->playable_tracks = 0;
+ for (struct track *t = ds->album_browse->tracks; t; t = t->next) {
+ t->geo_restricted = despotify_is_track_restricted(t, ds->user_info->country);
+ if (t->geo_restricted)
+ t->playable = false;
+ if (t->playable)
+ ds->album_browse->playable_tracks++;
+ }
return ds->album_browse;
}
diff --git a/lib/despotify.h b/lib/despotify.h
index 8de46cc..c018742 100644
--- a/lib/despotify.h
+++ b/lib/despotify.h
@@ -80,6 +80,7 @@ struct album_browse
char artist[STRING_LENGTH];
char artist_id[33];
int num_tracks;
+ int playable_tracks;
struct track* tracks;
int year;
char cover_id[41];
--
1.7.7.3
Owner

arachsys commented Jun 16, 2012

I use the Despotify lib/*.[ch] library files directly in my own (private) Spotify command line client, and as well as some modifications which aren't suitable for upstream, I've accumulated these fixes which are more generally applicable. I'd love to contribute them back to Despotify, but I've completely failed to contact the upstream maintainers. The Sourceforge project appears to be dead, as does #despotify on EFnet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment