mirror of
https://github.com/SuperBFG7/ympd
synced 2024-12-28 03:40:26 +00:00
Fix: test of entity type in mympd_smartpls_update_newest
This commit is contained in:
parent
2a675bc4e8
commit
dab83d0e5e
@ -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) {
|
||||||
|
if (mpd_entity_get_type(entity) == MPD_ENTITY_TYPE_SONG) {
|
||||||
|
song = mpd_entity_get_song(entity);
|
||||||
value = mpd_song_get_last_modified(song);
|
value = mpd_song_get_last_modified(song);
|
||||||
if (value > value_max)
|
if (value >= value_max) {
|
||||||
value_max = value;
|
value_max = value;
|
||||||
fprintf(fp, "%s::%ld\n", mpd_song_get_uri(song), value);
|
fprintf(fp, "%s::%ld\n", mpd_song_get_uri(song), value);
|
||||||
mpd_song_free(song);
|
}
|
||||||
|
mpd_entity_free(entity);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
mpd_response_finish(mpd.conn);
|
mpd_response_finish(mpd.conn);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
@ -2360,6 +2365,7 @@ int mympd_smartpls_update_newest(char *playlist, int timerange, int maxentries)
|
|||||||
|
|
||||||
value_max -= timerange;
|
value_max -= timerange;
|
||||||
|
|
||||||
|
if (value_max > 0) {
|
||||||
fp = fopen(tmpfile, "r");
|
fp = fopen(tmpfile, "r");
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
printf("Error opening %s\n", tmpfile);
|
printf("Error opening %s\n", tmpfile);
|
||||||
@ -2384,7 +2390,11 @@ int mympd_smartpls_update_newest(char *playlist, int timerange, int maxentries)
|
|||||||
}
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
free(uri);
|
free(uri);
|
||||||
unlink(tmpfile);
|
|
||||||
printf("Updated %s with %ld songs, minValue: %ld\n", playlist, i, value_max);
|
printf("Updated %s with %ld songs, minValue: %ld\n", playlist, i, value_max);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printf("Error updating %s\n", playlist);
|
||||||
|
}
|
||||||
|
unlink(tmpfile);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user