mirror of
https://github.com/owntone/owntone-server.git
synced 2025-02-04 18:36:02 -05:00
[scan] Change library_playlist_save return + fix Spotify
* fix Spotify invalid mem access * fix clearing of Spotify files
This commit is contained in:
parent
da29fa5f93
commit
5295d787ad
10
src/db.c
10
src/db.c
@ -3495,16 +3495,16 @@ db_pl_add(struct playlist_info *pli)
|
||||
if (ret < 0)
|
||||
return -1;
|
||||
|
||||
pli->id = (int)sqlite3_last_insert_rowid(hdl);
|
||||
if (pli->id == 0)
|
||||
ret = (int)sqlite3_last_insert_rowid(hdl);
|
||||
if (ret == 0)
|
||||
{
|
||||
DPRINTF(E_LOG, L_DB, "Successful playlist insert but no last_insert_rowid!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
DPRINTF(E_DBG, L_DB, "Added playlist %s (path %s) as id %d\n", pli->title, pli->path, pli->id);
|
||||
DPRINTF(E_DBG, L_DB, "Added playlist %s (path %s) as id %d\n", pli->title, pli->path, ret);
|
||||
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
@ -3527,7 +3527,7 @@ db_pl_update(struct playlist_info *pli)
|
||||
if (ret < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
return pli->id;
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -97,6 +97,12 @@ struct library_source
|
||||
int
|
||||
library_media_save(struct media_file_info *mfi);
|
||||
|
||||
/*
|
||||
* Adds a playlist if pli->id == 0, otherwise updates.
|
||||
*
|
||||
* @param pli Playlist to save
|
||||
* @return playlist id if operation succeeded, -1 on failure.
|
||||
*/
|
||||
int
|
||||
library_playlist_save(struct playlist_info *pli);
|
||||
|
||||
|
@ -470,7 +470,6 @@ playlist_add(const char *path)
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = pli.id;
|
||||
free_pli(&pli, 1);
|
||||
|
||||
return ret;
|
||||
|
@ -850,9 +850,9 @@ process_pls(plist_t playlists, const char *file)
|
||||
continue;
|
||||
}
|
||||
|
||||
DPRINTF(E_INFO, L_SCAN, "Added playlist as id %d\n", pli.id);
|
||||
DPRINTF(E_INFO, L_SCAN, "Added playlist as id %d\n", ret);
|
||||
|
||||
process_pl_items(items, pli.id, name);
|
||||
process_pl_items(items, ret, name);
|
||||
|
||||
free_pli(&pli, 1);
|
||||
free(name);
|
||||
|
@ -208,7 +208,7 @@ process_nested_playlist(int parent_id, const char *path)
|
||||
|
||||
free_pli(pli, 0);
|
||||
|
||||
return ret;
|
||||
return 0;
|
||||
|
||||
error:
|
||||
DPRINTF(E_LOG, L_SCAN, "Error processing nested playlist '%s' in playlist %d\n", path, parent_id);
|
||||
|
@ -84,7 +84,7 @@ scan_smartpl(const char *file, time_t mtime, int dir_id)
|
||||
goto free_pli;
|
||||
}
|
||||
|
||||
DPRINTF(E_INFO, L_SCAN, "Added or updated smart playlist '%s'\n", file);
|
||||
DPRINTF(E_INFO, L_SCAN, "Added or updated smart playlist '%s' with id %d\n", file, ret);
|
||||
|
||||
free_pli:
|
||||
free_pli(pli, 0);
|
||||
|
@ -1438,6 +1438,22 @@ track_add(struct spotify_track *track, struct spotify_album *album, const char *
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
playlist_add_or_update(struct playlist_info *pli)
|
||||
{
|
||||
int pl_id;
|
||||
|
||||
pl_id = db_pl_id_bypath(pli->path);
|
||||
if (pl_id < 0)
|
||||
return library_playlist_save(pli);
|
||||
|
||||
pli->id = pl_id;
|
||||
|
||||
db_pl_clear_items(pli->id);
|
||||
|
||||
return library_playlist_save(pli);
|
||||
}
|
||||
|
||||
/*
|
||||
* Add a saved album to the library
|
||||
*/
|
||||
@ -1574,6 +1590,7 @@ scan_playlist_tracks(const char *playlist_tracks_endpoint_uri, int plid)
|
||||
static void
|
||||
map_playlist_to_pli(struct playlist_info *pli, struct spotify_playlist *playlist)
|
||||
{
|
||||
memset(pli, 0, sizeof(struct playlist_info));
|
||||
|
||||
pli->type = PL_PLAIN;
|
||||
pli->path = strdup(playlist->uri);
|
||||
@ -1609,12 +1626,9 @@ saved_playlist_add(json_object *item, int index, int total, void *arg)
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(&pli, 0, sizeof(struct playlist_info));
|
||||
|
||||
map_playlist_to_pli(&pli, &playlist);
|
||||
|
||||
library_playlist_save(&pli);
|
||||
pl_id = db_pl_id_bypath(pli.path);
|
||||
pl_id = playlist_add_or_update(&pli);
|
||||
|
||||
free_pli(&pli, 1);
|
||||
|
||||
@ -1648,22 +1662,22 @@ create_saved_tracks_playlist()
|
||||
{
|
||||
struct playlist_info pli =
|
||||
{
|
||||
.path = "spotify:savedtracks",
|
||||
.title = "Spotify Saved",
|
||||
.virtual_path = "/spotify:/Spotify Saved",
|
||||
.path = strdup("spotify:savedtracks"),
|
||||
.title = strdup("Spotify Saved"),
|
||||
.virtual_path = strdup("/spotify:/Spotify Saved"),
|
||||
.type = PL_PLAIN,
|
||||
.parent_id = spotify_base_plid,
|
||||
.directory_id = DIR_SPOTIFY,
|
||||
};
|
||||
|
||||
library_playlist_save(&pli);
|
||||
|
||||
spotify_saved_plid = db_pl_id_bypath(pli.path);
|
||||
if (spotify_saved_plid <= 0)
|
||||
spotify_saved_plid = playlist_add_or_update(&pli);
|
||||
if (spotify_saved_plid < 0)
|
||||
{
|
||||
DPRINTF(E_LOG, L_SPOTIFY, "Error adding playlist for saved tracks\n");
|
||||
spotify_saved_plid = 0;
|
||||
}
|
||||
|
||||
free_pli(&pli, 1);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1675,24 +1689,27 @@ create_base_playlist()
|
||||
cfg_t *spotify_cfg;
|
||||
struct playlist_info pli =
|
||||
{
|
||||
.path = "spotify:playlistfolder",
|
||||
.title = "Spotify",
|
||||
.path = strdup("spotify:playlistfolder"),
|
||||
.title = strdup("Spotify"),
|
||||
.type = PL_FOLDER,
|
||||
};
|
||||
|
||||
spotify_base_plid = 0;
|
||||
spotify_cfg = cfg_getsec(cfg, "spotify");
|
||||
if (cfg_getbool(spotify_cfg, "base_playlist_disable"))
|
||||
return;
|
||||
{
|
||||
free_pli(&pli, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
library_playlist_save(&pli);
|
||||
|
||||
spotify_base_plid = db_pl_id_bypath(pli.path);
|
||||
spotify_base_plid = playlist_add_or_update(&pli);
|
||||
if (spotify_base_plid < 0)
|
||||
{
|
||||
DPRINTF(E_LOG, L_SPOTIFY, "Error adding base playlist\n");
|
||||
spotify_base_plid = 0;
|
||||
}
|
||||
|
||||
free_pli(&pli, 1);
|
||||
}
|
||||
|
||||
static void
|
||||
|
Loading…
x
Reference in New Issue
Block a user