1
0
mirror of https://github.com/SuperBFG7/ympd synced 2024-12-27 03:10:26 +00:00

Fix: test of entity type in mympd_smartpls_update_newest

This commit is contained in:
jcorporation 2018-10-07 23:21:44 +01:00
parent 2a675bc4e8
commit dab83d0e5e

View File

@ -2325,6 +2325,7 @@ int mympd_smartpls_update(char *playlist, char *sticker, int maxentries) {
int mympd_smartpls_update_newest(char *playlist, int timerange, int maxentries) { int mympd_smartpls_update_newest(char *playlist, int timerange, int maxentries) {
struct mpd_song *song; struct mpd_song *song;
struct mpd_entity *entity;
char *uri; char *uri;
char *p_value; char *p_value;
char *name; char *name;
@ -2346,12 +2347,16 @@ int mympd_smartpls_update_newest(char *playlist, int timerange, int maxentries)
printf("Error opening %s\n", tmpfile); printf("Error opening %s\n", tmpfile);
return 1; return 1;
} }
while ((song = mpd_recv_song(mpd.conn)) != NULL) { while ((entity = mpd_recv_entity(mpd.conn)) != NULL) {
value = mpd_song_get_last_modified(song); if (mpd_entity_get_type(entity) == MPD_ENTITY_TYPE_SONG) {
if (value > value_max) song = mpd_entity_get_song(entity);
value_max = value; value = mpd_song_get_last_modified(song);
fprintf(fp, "%s::%ld\n", mpd_song_get_uri(song), value); if (value >= value_max) {
mpd_song_free(song); value_max = value;
fprintf(fp, "%s::%ld\n", mpd_song_get_uri(song), value);
}
mpd_entity_free(entity);
}
} }
mpd_response_finish(mpd.conn); mpd_response_finish(mpd.conn);
fclose(fp); fclose(fp);
@ -2360,31 +2365,36 @@ int mympd_smartpls_update_newest(char *playlist, int timerange, int maxentries)
value_max -= timerange; value_max -= timerange;
fp = fopen(tmpfile, "r"); if (value_max > 0) {
if (fp == NULL) { fp = fopen(tmpfile, "r");
printf("Error opening %s\n", tmpfile); if (fp == NULL) {
return 1; printf("Error opening %s\n", tmpfile);
} return 1;
while ((read = getline(&uri, &len, fp)) != -1) {
name = strtok(uri, "::");
p_value = strtok(NULL, "::");
value = strtol(p_value, &crap, 10);
if (value >= value_max)
continue;
if (!mpd_run_playlist_add(mpd.conn, playlist, name)) {
LOG_ERROR_AND_RECOVER("mpd_run_playlist_add");
fclose(fp);
unlink(tmpfile);
free(uri);
return 1;
} }
i++; while ((read = getline(&uri, &len, fp)) != -1) {
if (i >= maxentries) name = strtok(uri, "::");
break; p_value = strtok(NULL, "::");
value = strtol(p_value, &crap, 10);
if (value >= value_max)
continue;
if (!mpd_run_playlist_add(mpd.conn, playlist, name)) {
LOG_ERROR_AND_RECOVER("mpd_run_playlist_add");
fclose(fp);
unlink(tmpfile);
free(uri);
return 1;
}
i++;
if (i >= maxentries)
break;
}
fclose(fp);
free(uri);
printf("Updated %s with %ld songs, minValue: %ld\n", playlist, i, value_max);
}
else {
printf("Error updating %s\n", playlist);
} }
fclose(fp);
free(uri);
unlink(tmpfile); unlink(tmpfile);
printf("Updated %s with %ld songs, minValue: %ld\n", playlist, i, value_max);
return 0; return 0;
} }