mirror of
https://github.com/owntone/owntone-server.git
synced 2025-01-12 15:33:23 -05:00
Merge pull request #1259 from owntone/fix_add_spotify_queue1
[db] Fix error where adding e.g. Spotify track to queue returns "0 tracks added"
This commit is contained in:
commit
e8619d8322
21
src/db.c
21
src/db.c
@ -4943,20 +4943,21 @@ db_queue_add_end(struct db_queue_add_info *queue_add_info, char reshuffle, uint3
|
||||
{
|
||||
char *query;
|
||||
|
||||
if (ret < 0)
|
||||
goto end;
|
||||
|
||||
// Update pos for all items from the given position
|
||||
if (ret == 0)
|
||||
{
|
||||
query = sqlite3_mprintf("UPDATE queue SET pos = pos + %d, queue_version = %d WHERE pos >= %d AND queue_version < %d;",
|
||||
queue_add_info->count, queue_add_info->queue_version, queue_add_info->start_pos, queue_add_info->queue_version);
|
||||
ret = db_query_run(query, 1, 0);
|
||||
}
|
||||
query = sqlite3_mprintf("UPDATE queue SET pos = pos + %d, queue_version = %d WHERE pos >= %d AND queue_version < %d;",
|
||||
queue_add_info->count, queue_add_info->queue_version, queue_add_info->start_pos, queue_add_info->queue_version);
|
||||
ret = db_query_run(query, 1, 0);
|
||||
if (ret < 0)
|
||||
goto end;
|
||||
|
||||
// Reshuffle after adding new items
|
||||
if (ret == 0 && reshuffle)
|
||||
{
|
||||
ret = queue_reshuffle(item_id, queue_add_info->queue_version);
|
||||
}
|
||||
if (reshuffle)
|
||||
ret = queue_reshuffle(item_id, queue_add_info->queue_version);
|
||||
|
||||
end:
|
||||
queue_transaction_end(ret, queue_add_info->queue_version);
|
||||
return ret;
|
||||
}
|
||||
|
@ -1741,35 +1741,37 @@ filescanner_fullrescan()
|
||||
static int
|
||||
queue_item_stream_add(const char *path, int position, char reshuffle, uint32_t item_id, int *count, int *new_item_id)
|
||||
{
|
||||
struct media_file_info mfi;
|
||||
struct media_file_info mfi = { 0 };
|
||||
struct db_queue_item qi;
|
||||
struct db_queue_add_info queue_add_info;
|
||||
int ret;
|
||||
|
||||
memset(&mfi, 0, sizeof(struct media_file_info));
|
||||
|
||||
scan_metadata_stream(&mfi, path);
|
||||
|
||||
db_queue_item_from_mfi(&qi, &mfi);
|
||||
|
||||
ret = db_queue_add_start(&queue_add_info, position);
|
||||
if (ret == 0)
|
||||
{
|
||||
ret = db_queue_add_next(&queue_add_info, &qi);
|
||||
ret = db_queue_add_end(&queue_add_info, reshuffle, item_id, ret);
|
||||
if (ret == 0)
|
||||
{
|
||||
if (count)
|
||||
*count = queue_add_info.count;
|
||||
if (new_item_id)
|
||||
*new_item_id = queue_add_info.new_item_id;
|
||||
}
|
||||
}
|
||||
if (ret < 0)
|
||||
goto error;
|
||||
|
||||
ret = db_queue_add_next(&queue_add_info, &qi);
|
||||
ret = db_queue_add_end(&queue_add_info, reshuffle, item_id, ret);
|
||||
if (ret < 0)
|
||||
goto error;
|
||||
|
||||
if (count)
|
||||
*count = queue_add_info.count;
|
||||
if (new_item_id)
|
||||
*new_item_id = queue_add_info.new_item_id;
|
||||
|
||||
free_queue_item(&qi, 1);
|
||||
free_mfi(&mfi, 1);
|
||||
|
||||
return 0;
|
||||
|
||||
error:
|
||||
free_queue_item(&qi, 1);
|
||||
free_mfi(&mfi, 1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -1061,15 +1061,15 @@ map_track_to_queueitem(struct db_queue_item *item, const struct spotify_track *t
|
||||
static int
|
||||
queue_add_track(const char *uri, int position, char reshuffle, uint32_t item_id, int *count, int *new_item_id)
|
||||
{
|
||||
json_object *response;
|
||||
json_object *response = NULL;
|
||||
struct spotify_track track;
|
||||
struct db_queue_item item;
|
||||
struct db_queue_item item = { 0 };
|
||||
struct db_queue_add_info queue_add_info;
|
||||
int ret;
|
||||
|
||||
response = request_track(uri);
|
||||
if (!response)
|
||||
return -1;
|
||||
goto error;
|
||||
|
||||
parse_metadata_track(response, &track, ART_DEFAULT_WIDTH);
|
||||
|
||||
@ -1078,23 +1078,27 @@ queue_add_track(const char *uri, int position, char reshuffle, uint32_t item_id,
|
||||
map_track_to_queueitem(&item, &track, NULL);
|
||||
|
||||
ret = db_queue_add_start(&queue_add_info, position);
|
||||
if (ret == 0)
|
||||
{
|
||||
ret = db_queue_add_next(&queue_add_info, &item);
|
||||
ret = db_queue_add_end(&queue_add_info, reshuffle, item_id, ret);
|
||||
if (ret == 0)
|
||||
{
|
||||
if (count)
|
||||
*count = queue_add_info.count;
|
||||
if (new_item_id)
|
||||
*new_item_id = queue_add_info.new_item_id;
|
||||
}
|
||||
}
|
||||
if (ret < 0)
|
||||
goto error;
|
||||
|
||||
ret = db_queue_add_next(&queue_add_info, &item);
|
||||
ret = db_queue_add_end(&queue_add_info, reshuffle, item_id, ret);
|
||||
if (ret < 0)
|
||||
goto error;
|
||||
|
||||
if (count)
|
||||
*count = queue_add_info.count;
|
||||
if (new_item_id)
|
||||
*new_item_id = queue_add_info.new_item_id;
|
||||
|
||||
free_queue_item(&item, 1);
|
||||
jparse_free(response);
|
||||
|
||||
return 0;
|
||||
|
||||
error:
|
||||
free_queue_item(&item, 1);
|
||||
jparse_free(response);
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct queue_add_album_param {
|
||||
@ -1151,7 +1155,10 @@ queue_add_album(const char *uri, int position, char reshuffle, uint32_t item_id,
|
||||
ret = request_pagingobject_endpoint(endpoint_uri, queue_add_album_tracks, NULL, NULL, true, SPOTIFY_REQUEST_TYPE_DEFAULT, ¶m);
|
||||
|
||||
ret = db_queue_add_end(¶m.queue_add_info, reshuffle, item_id, ret);
|
||||
if (ret == 0 && count)
|
||||
if (ret < 0)
|
||||
goto out;
|
||||
|
||||
if (count)
|
||||
*count = param.queue_add_info.count;
|
||||
|
||||
out:
|
||||
@ -1194,15 +1201,19 @@ queue_add_artist(const char *uri, int position, char reshuffle, uint32_t item_id
|
||||
|
||||
ret = db_queue_add_start(&queue_add_info, position);
|
||||
if (ret < 0)
|
||||
return -1;
|
||||
goto out;
|
||||
|
||||
endpoint_uri = get_artist_albums_endpoint_uri(uri);
|
||||
ret = request_pagingobject_endpoint(endpoint_uri, queue_add_albums, NULL, NULL, true, SPOTIFY_REQUEST_TYPE_DEFAULT, &queue_add_info);
|
||||
|
||||
ret = db_queue_add_end(&queue_add_info, reshuffle, item_id, ret);
|
||||
if (ret == 0 && count)
|
||||
if (ret < 0)
|
||||
goto out;
|
||||
|
||||
if (count)
|
||||
*count = queue_add_info.count;
|
||||
|
||||
out:
|
||||
free(endpoint_uri);
|
||||
return ret;
|
||||
}
|
||||
@ -1246,24 +1257,27 @@ queue_add_playlist_tracks(json_object *item, int index, int total, enum spotify_
|
||||
static int
|
||||
queue_add_playlist(const char *uri, int position, char reshuffle, uint32_t item_id, int *count, int *new_item_id)
|
||||
{
|
||||
char *endpoint_uri;
|
||||
char *endpoint_uri = NULL;
|
||||
struct db_queue_add_info queue_add_info;
|
||||
int ret;
|
||||
|
||||
ret = db_queue_add_start(&queue_add_info, position);
|
||||
if (ret < 0)
|
||||
return -1;
|
||||
goto out;
|
||||
|
||||
endpoint_uri = get_playlist_tracks_endpoint_uri(uri);
|
||||
|
||||
ret = request_pagingobject_endpoint(endpoint_uri, queue_add_playlist_tracks, NULL, NULL, true, SPOTIFY_REQUEST_TYPE_DEFAULT, &queue_add_info);
|
||||
|
||||
ret = db_queue_add_end(&queue_add_info, reshuffle, item_id, ret);
|
||||
if (ret == 0 && count)
|
||||
if (ret < 0)
|
||||
goto out;
|
||||
|
||||
if (count)
|
||||
*count = queue_add_info.count;
|
||||
|
||||
out:
|
||||
free(endpoint_uri);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user