Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' into dreambox

  • Loading branch information...
commit 3c1a68768d7408dae8cf5adead96ee9d9e6b8bda 2 parents c5e927f + 6971228
Jonas Kramer authored
View
2  source/include/playlist.h
@@ -19,7 +19,7 @@ struct playlist {
};
extern int expand(struct playlist *);
-extern int parsexspf(struct playlist *, const char *);
+extern int parsexspf(struct playlist *, char *);
extern void freelist(struct playlist *);
extern void freenode(struct tracknode **);
View
8 source/play.c
@@ -104,6 +104,8 @@ mkpath(char *path)
}
int playback(FILE * streamfd) {
+ const char * freetrack = NULL;
+
killed = 0;
signal(SIGUSR1, sighand);
@@ -161,8 +163,10 @@ int playback(FILE * streamfd) {
ioctl(data.audiofd, SOUND_PCM_WRITE_BITS, & arg);
#endif
- if(haskey(& track, "freeTrackURL") && haskey(& rc, "download")) {
- char *dnam;
+ freetrack = value(& track, "freeTrackURL");
+
+ if(freetrack && strlen(freetrack) > 0 && haskey(& rc, "download")) {
+ char * dnam;
int rv;
data.path = strdup(meta(value(& rc, "download"), M_RELAXPATH, & track));
View
119 source/playlist.c
@@ -65,109 +65,92 @@ void trim(char* string){
}
-int parsexspf(struct playlist * list, const char * xml) {
- char * ptr;
+int parsexspf(struct playlist * list, char * xml) {
+ char * ptr = xml;
unsigned i, tracks = 0;
+ char * track;
assert(list != NULL);
assert(xml != NULL);
- if((ptr = strcasestr(xml, "<title>")) != NULL) {
- char * track, * radio = NULL;
+ while((track = strcasestr(ptr, "<track>")) != NULL) {
+ struct tracknode * node = NULL;
+ char * next = strcasestr(track + 7, "<track>"), * duration;
- radio = strndup(ptr + 7, strcasestr(xml, "</title>") - ptr - 7);
- assert(radio != NULL);
+ const char * tags [] = {
+ "location", "title", "album", "creator", "duration", "image",
+ "lastfm:trackauth",
+ };
- if(list->title != NULL) {
- free(list->title);
- list->title = NULL;
- }
-
- decode(radio, & list->title);
- unhtml(list->title);
- free(radio);
-
- while((track = strcasestr(ptr, "<track>")) != NULL) {
- struct tracknode * node = NULL;
- char * next = strcasestr(track + 7, "<track>"), * duration;
+ const char * links [] = { "artistpage", "albumpage", "trackpage", "freeTrackURL", };
- const char * tags [] = {
- "location", "title", "album", "creator", "duration", "image",
- "lastfm:trackauth",
- };
- const char * links [] = { "artistpage", "albumpage", "trackpage", "freeTrackURL", };
+ if(next)
+ * (next - 1) = 0;
+ node = malloc(sizeof(struct tracknode));
+ assert(node != NULL);
- if(next)
- * (next - 1) = 0;
+ memset(node, 0, sizeof(struct tracknode));
- node = malloc(sizeof(struct tracknode));
- assert(node != NULL);
+ for(i = 0; i < (sizeof(tags) / sizeof(char *)); ++i) {
+ char begin[32] = { 0 }, end[32] = { 0 };
- memset(node, 0, sizeof(struct tracknode));
+ sprintf(begin, "<%s>", tags[i]);
+ sprintf(end, "</%s>", tags[i]);
- for(i = 0; i < (sizeof(tags) / sizeof(char *)); ++i) {
- char begin[32] = { 0 }, end[32] = { 0 };
-
- sprintf(begin, "<%s>", tags[i]);
- sprintf(end, "</%s>", tags[i]);
-
- if((ptr = strcasestr(track, begin)) != NULL) {
- char * text = strndup(
+ if((ptr = strcasestr(track, begin)) != NULL) {
+ char * text = strndup(
ptr + strlen(begin),
(strcasestr(ptr, end)) - (ptr + strlen(begin))
- );
+ );
- assert(text != NULL);
+ assert(text != NULL);
- unhtml(text);
- set(& node->track, tags[i], text);
- free(text);
- }
+ unhtml(text);
+ set(& node->track, tags[i], text);
+ free(text);
}
+ }
- for(i = 0; i < (sizeof(links) / sizeof(char *)); ++i) {
- char begin[64] = { 0 };
+ for(i = 0; i < (sizeof(links) / sizeof(char *)); ++i) {
+ char begin[64] = { 0 };
- sprintf(begin, "<link rel=\"http://www.last.fm/%s\">", links[i]);
+ sprintf(begin, "<link rel=\"http://www.last.fm/%s\">", links[i]);
- if((ptr = strcasestr(track, begin)) != NULL) {
- char * text = strndup(
+ if((ptr = strcasestr(track, begin)) != NULL) {
+ char * text = strndup(
ptr + strlen(begin),
(strcasestr(ptr, "</link>")) - (ptr + strlen(begin))
- );
+ );
- assert(text != NULL);
+ assert(text != NULL);
- set(& node->track, links[i], text);
- free(text);
- }
+ set(& node->track, links[i], text);
+ free(text);
}
+ }
- trim(list->title);
- set(& node->track, "station", list->title);
-
- duration = strdup(value(& node->track, "duration"));
- if(duration != NULL) {
- duration[strlen(duration) - 3] = 0;
- set(& node->track, "duration", duration);
- }
+ trim(list->title);
+ set(& node->track, "station", list->title);
- push(list, node);
+ duration = strdup(value(& node->track, "duration"));
+ if(duration != NULL) {
+ duration[strlen(duration) - 3] = 0;
+ set(& node->track, "duration", duration);
+ }
- ++tracks;
+ push(list, node);
- if(!next)
- break;
+ ++tracks;
- ptr = next;
- }
+ if(!next)
+ break;
- return !0;
+ ptr = next;
}
- return 0;
+ return 1;
}
View
24 source/service.c
@@ -36,7 +36,6 @@ pid_t playfork = 0; /* PID of the decoding & playing process, if running */
struct playlist playlist;
char * currentStation = NULL;
-
int authenticate(const char * username, const char * password) {
const unsigned char * md5;
char hexmd5[32 + 1] = { 0 }, url[512] = { 0 }, ** response;
@@ -93,7 +92,7 @@ int authenticate(const char * username, const char * password) {
int station(const char * stationURL) {
- char url[512] = { 0 }, * encodedURL = NULL, ** response;
+ char url[512] = { 0 }, * encodedURL = NULL, ** response, name[512];
unsigned i = 0, retval = !0, regular = !0;
const char * fmt;
const char * types[4] = {"play", "preview", "track", "playlist"};
@@ -115,12 +114,22 @@ int station(const char * stationURL) {
}
}
+ /* Do nothing if the station is already played. */
+ else if(currentStation && !strcmp(currentStation, stationURL)) {
+ return 0;
+ }
+
puts("\rDelayed.");
nextstation = strdup(stationURL);
return 0;
}
+ /* Do nothing if the station is already played. */
+ else if(currentStation && !strcmp(currentStation, stationURL)) {
+ return 0;
+ }
+
freelist(& playlist);
if(!haskey(& data, "session")) {
@@ -128,7 +137,7 @@ int station(const char * stationURL) {
return 0;
}
- if(!stationURL)
+ if(!stationURL || !strlen(stationURL))
return 0;
if(!strncasecmp(stationURL, "lastfm://", 9))
@@ -166,9 +175,18 @@ int station(const char * stationURL) {
if(regular) {
for(i = 0; response[i]; ++i) {
char status[64] = { 0 };
+
if(sscanf(response[i], "response=%63[^\r\n]", status) > 0)
if(!strncmp(status, "FAILED", 6))
retval = 0;
+
+ if(sscanf(response[i], "stationname=%127[^\r\n]", name) > 0) {
+ if(playlist.title != NULL)
+ free(playlist.title);
+
+ decode(name, & playlist.title);
+ unhtml(playlist.title);
+ }
}
purge(response);
Please sign in to comment.
Something went wrong with that request. Please try again.