Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 48 additions & 29 deletions src/inputs/librespot-c/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,63 @@ SUBDIRS = tests
noinst_LIBRARIES = librespot-c.a

SHANNON_SRC = \
src/shannon/ShannonFast.c src/shannon/Shannon.h src/shannon/ShannonInternal.h
src/shannon/ShannonFast.c \
src/shannon/Shannon.h \
src/shannon/ShannonInternal.h

PROTO_SRC = \
src/proto/keyexchange.pb-c.c src/proto/keyexchange.pb-c.h \
src/proto/authentication.pb-c.c src/proto/authentication.pb-c.h \
src/proto/mercury.pb-c.c src/proto/mercury.pb-c.h \
src/proto/metadata.pb-c.c src/proto/metadata.pb-c.h

HTTP_PROTO_SRC = \
src/proto/connectivity.pb-c.c src/proto/connectivity.pb-c.h \
src/proto/clienttoken.pb-c.c src/proto/clienttoken.pb-c.h \
src/proto/login5_user_info.pb-c.h src/proto/login5_user_info.pb-c.c \
src/proto/login5.pb-c.h src/proto/login5.pb-c.c \
src/proto/login5_identifiers.pb-c.h src/proto/login5_identifiers.pb-c.c \
src/proto/login5_credentials.pb-c.h src/proto/login5_credentials.pb-c.c \
src/proto/login5_client_info.pb-c.h src/proto/login5_client_info.pb-c.c \
src/proto/login5_challenges_hashcash.pb-c.h src/proto/login5_challenges_hashcash.pb-c.c \
src/proto/login5_challenges_code.pb-c.h src/proto/login5_challenges_code.pb-c.c \
src/proto/google_duration.pb-c.h src/proto/google_duration.pb-c.c \
src/proto/storage_resolve.pb-c.h src/proto/storage_resolve.pb-c.c \
src/proto/extended_metadata.pb-c.h src/proto/extended_metadata.pb-c.c \
src/proto/extension_kind.pb-c.h src/proto/extension_kind.pb-c.c \
src/proto/entity_extension_data.pb-c.h src/proto/entity_extension_data.pb-c.c \
src/proto/google_any.pb-c.h src/proto/google_any.pb-c.c
PROTO_FILES = \
src/proto/keyexchange.proto \
src/proto/authentication.proto \
src/proto/mercury.proto \
src/proto/metadata.proto \
src/proto/connectivity.proto \
src/proto/clienttoken.proto \
src/proto/login5_user_info.proto \
src/proto/login5.proto \
src/proto/login5_identifiers.proto \
src/proto/login5_credentials.proto \
src/proto/login5_client_info.proto \
src/proto/login5_challenges_hashcash.proto \
src/proto/login5_challenges_code.proto \
src/proto/google_duration.proto \
src/proto/storage_resolve.proto \
src/proto/extended_metadata.proto \
src/proto/extension_kind.proto \
src/proto/entity_extension_data.proto \
src/proto/google_any.proto

PROTO_SRC = \
$(PROTO_FILES:.proto=.pb-c.c) $(PROTO_FILES:.proto=.pb-c.h)

CORE_SRC = \
src/librespot-c.c src/connection.c src/channel.c src/crypto.c src/commands.c \
src/librespot-c.c \
src/connection.c \
src/channel.c \
src/crypto.c \
src/commands.c \
src/http.c

BUILT_SOURCES = \
$(PROTO_SRC)

librespot_c_a_SOURCES = \
$(CORE_SRC) \
$(SHANNON_SRC) \
$(PROTO_SRC) \
$(HTTP_PROTO_SRC)
$(PROTO_SRC)

noinst_HEADERS = \
librespot-c.h src/librespot-c-internal.h src/connection.h \
src/channel.h src/crypto.h src/commands.h src/http.h
librespot-c.h \
src/librespot-c-internal.h \
src/connection.h \
src/channel.h \
src/crypto.h \
src/commands.h \
src/http.h

EXTRA_DIST = \
README.md \
LICENSE \
$(PROTO_FILES)

EXTRA_DIST = README.md LICENSE
%.pb-c.c %.pb-c.h: %.proto
$(AM_V_GEN)$(PROTOC) --proto_path=src/proto --c_out=src/proto $<
4 changes: 3 additions & 1 deletion src/inputs/librespot-c/configure.ac
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
AC_INIT([librespot-c], [0.6])
AC_INIT([librespot-c], [0.7])
AC_CONFIG_AUX_DIR([.])
AM_INIT_AUTOMAKE([foreign subdir-objects])
AM_SILENT_RULES([yes])
Expand All @@ -10,6 +10,8 @@ AC_PROG_CC
AM_PROG_AR
AC_PROG_RANLIB

AC_PATH_PROG([PROTOC], [protoc-c])

AM_CPPFLAGS="-Wall"
AC_SUBST([AM_CPPFLAGS])

Expand Down
38 changes: 19 additions & 19 deletions src/inputs/librespot-c/src/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,11 @@ system_info_from_uname(SystemInfo *system_info)
// Returns true if format of a is preferred over b (and is valid). According to
// librespot comment most podcasts are 96 kbit.
static bool
format_is_preferred(AudioFile *a, AudioFile *b, enum sp_bitrates bitrate_preferred)
format_is_preferred(Spotify__Metadata__AudioFile *a, Spotify__Metadata__AudioFile *b, enum sp_bitrates bitrate_preferred)
{
if (a->format != AUDIO_FILE__FORMAT__OGG_VORBIS_96 &&
a->format != AUDIO_FILE__FORMAT__OGG_VORBIS_160 &&
a->format != AUDIO_FILE__FORMAT__OGG_VORBIS_320)
if (a->format != SPOTIFY__METADATA__AUDIO_FILE__FORMAT__OGG_VORBIS_96 &&
a->format != SPOTIFY__METADATA__AUDIO_FILE__FORMAT__OGG_VORBIS_160 &&
a->format != SPOTIFY__METADATA__AUDIO_FILE__FORMAT__OGG_VORBIS_320)
return false;

if (!b)
Expand All @@ -184,9 +184,9 @@ format_is_preferred(AudioFile *a, AudioFile *b, enum sp_bitrates bitrate_preferr
case SP_BITRATE_96:
return (a->format < b->format); // Prefer lowest
case SP_BITRATE_160:
if (b->format == AUDIO_FILE__FORMAT__OGG_VORBIS_160)
if (b->format == SPOTIFY__METADATA__AUDIO_FILE__FORMAT__OGG_VORBIS_160)
return false;
else if (a->format == AUDIO_FILE__FORMAT__OGG_VORBIS_160)
else if (a->format == SPOTIFY__METADATA__AUDIO_FILE__FORMAT__OGG_VORBIS_160)
return true;
else
return (a->format < b->format); // Prefer lowest
Expand All @@ -200,10 +200,10 @@ format_is_preferred(AudioFile *a, AudioFile *b, enum sp_bitrates bitrate_preferr
}

int
file_select(uint8_t *out, size_t out_len, Track *track, enum sp_bitrates bitrate_preferred)
file_select(uint8_t *out, size_t out_len, Spotify__Metadata__Track *track, enum sp_bitrates bitrate_preferred)
{
AudioFile *selected = NULL;
AudioFile *file;
Spotify__Metadata__AudioFile *selected = NULL;
Spotify__Metadata__AudioFile *file;
int i;

for (i = 0; i < track->n_file; i++)
Expand Down Expand Up @@ -461,7 +461,7 @@ mercury_free(struct sp_mercury *mercury, int content_only)
free(mercury->parts[i].data);

if (mercury->parts[i].track)
track__free_unpacked(mercury->parts[i].track, NULL);
spotify__metadata__track__free_unpacked(mercury->parts[i].track, NULL);
}

if (content_only)
Expand Down Expand Up @@ -546,7 +546,7 @@ mercury_parse(struct sp_mercury *mercury, uint8_t *payload, size_t payload_len)
memcpy(mercury->parts[i].data, ptr, mercury->parts[i].len);
ptr += mercury->parts[i].len; // 5: length += mercury->parts[i].len

mercury->parts[i].track = track__unpack(NULL, mercury->parts[i].len, mercury->parts[i].data);
mercury->parts[i].track = spotify__metadata__track__unpack(NULL, mercury->parts[i].len, mercury->parts[i].data);
}

header__free_unpacked(header, NULL);
Expand Down Expand Up @@ -1056,28 +1056,28 @@ handle_metadata_get(struct sp_message *msg, struct sp_session *session)
{
struct http_response *hres = &msg->payload.hres;
struct sp_channel *channel = session->now_streaming_channel;
Track *response = NULL;
Spotify__Metadata__Track *response = NULL;
int ret;

if (hres->code != HTTP_OK)
goto fallback;

// Also works for Episode response
response = track__unpack(NULL, hres->body_len, hres->body);
response = spotify__metadata__track__unpack(NULL, hres->body_len, hres->body);
if (!response)
goto fallback;

ret = file_select(channel->file.id, sizeof(channel->file.id), response, session->bitrate_preferred);
if (ret < 0)
goto fallback;

track__free_unpacked(response, NULL);
spotify__metadata__track__free_unpacked(response, NULL);
return SP_OK_DONE;

fallback:
sp_cb.logmsg("Couldn't find file id in metadata response, will request extended metadata\n");

track__free_unpacked(response, NULL);
spotify__metadata__track__free_unpacked(response, NULL);
return SP_OK_DONE;
}

Expand All @@ -1093,7 +1093,7 @@ handle_extended_metadata_get(struct sp_message *msg, struct sp_session *session)
struct sp_channel *channel = session->now_streaming_channel;
Spotify__Extendedmetadata__BatchedExtensionResponse *response = NULL;
Spotify__Extendedmetadata__EntityExtensionData *entity_extension_data = NULL;
Track *track = NULL;
Spotify__Metadata__Track *track = NULL;
int i, j;
int ret;

Expand Down Expand Up @@ -1128,7 +1128,7 @@ handle_extended_metadata_get(struct sp_message *msg, struct sp_session *session)
// .Episode. If we get something else we will fail later anyway.

// This also works for episodes
track = track__unpack(NULL, entity_extension_data->extension_data->value.len, entity_extension_data->extension_data->value.data);
track = spotify__metadata__track__unpack(NULL, entity_extension_data->extension_data->value.len, entity_extension_data->extension_data->value.data);
if (!track)
RETURN_ERROR(SP_ERR_INVALID, "Could not parse track data in extended metadata response");

Expand All @@ -1137,12 +1137,12 @@ handle_extended_metadata_get(struct sp_message *msg, struct sp_session *session)
RETURN_ERROR(SP_ERR_INVALID, "Could not find track data in extended metadata response");

spotify__extendedmetadata__batched_extension_response__free_unpacked(response, NULL);
track__free_unpacked(track, NULL);
spotify__metadata__track__free_unpacked(track, NULL);
return SP_OK_DONE;

error:
spotify__extendedmetadata__batched_extension_response__free_unpacked(response, NULL);
track__free_unpacked(track, NULL);
spotify__metadata__track__free_unpacked(track, NULL);
return ret;
}

Expand Down
2 changes: 1 addition & 1 deletion src/inputs/librespot-c/src/librespot-c-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ struct sp_mercury
uint8_t *data;
size_t len;

Track *track;
Spotify__Metadata__Track *track;
} parts[SP_MERCURY_MAX_PARTS];
};

Expand Down
2 changes: 1 addition & 1 deletion src/inputs/librespot-c/src/proto/authentication.pb-c.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Generated by the protocol buffer compiler. DO NOT EDIT! */
/* Generated from: proto/authentication.proto */
/* Generated from: authentication.proto */

/* Do not generate deprecated warnings for self */
#ifndef PROTOBUF_C__NO_DEPRECATED
Expand Down
Loading
Loading