mirror of
https://github.com/owntone/owntone-server.git
synced 2025-05-05 01:06:39 -04:00
[db] Add function to get a human readable string for data and media kind
This commit is contained in:
parent
d59e62312a
commit
66bdb7c0a9
62
src/db.c
62
src/db.c
@ -333,6 +333,68 @@ static const struct browse_clause browse_clause[] =
|
|||||||
{ "f.path, f.path", "f.path", "f.path" },
|
{ "f.path, f.path", "f.path", "f.path" },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct media_kind_label {
|
||||||
|
enum media_kind type;
|
||||||
|
const char *label;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Keep in sync with enum media_kind */
|
||||||
|
static const struct media_kind_label media_kind_labels[] =
|
||||||
|
{
|
||||||
|
{ MEDIA_KIND_MUSIC, "music" },
|
||||||
|
{ MEDIA_KIND_MOVIE, "movie" },
|
||||||
|
{ MEDIA_KIND_PODCAST, "podcast" },
|
||||||
|
{ MEDIA_KIND_AUDIOBOOK, "audiobook" },
|
||||||
|
{ MEDIA_KIND_MUSICVIDEO, "musicvideo" },
|
||||||
|
{ MEDIA_KIND_TVSHOW, "tvshow" },
|
||||||
|
};
|
||||||
|
|
||||||
|
const char *
|
||||||
|
db_media_kind_label(enum media_kind media_kind)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < ARRAY_SIZE(media_kind_labels); i++)
|
||||||
|
{
|
||||||
|
if (media_kind == media_kind_labels[i].type)
|
||||||
|
return media_kind_labels[i].label;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum media_kind
|
||||||
|
db_media_kind_enum(const char *label)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (!label)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
for (i = 0; i < ARRAY_SIZE(media_kind_labels); i++)
|
||||||
|
{
|
||||||
|
if (strcmp(label, media_kind_labels[i].label) == 0)
|
||||||
|
return media_kind_labels[i].type;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Keep in sync with enum data_kind */
|
||||||
|
static char *data_kind_label[] = { "file", "url", "spotify", "pipe" };
|
||||||
|
|
||||||
|
const char *
|
||||||
|
db_data_kind_label(enum data_kind data_kind)
|
||||||
|
{
|
||||||
|
if (data_kind < ARRAY_SIZE(data_kind_label))
|
||||||
|
{
|
||||||
|
return data_kind_label[data_kind];
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* Shuffle RNG state */
|
/* Shuffle RNG state */
|
||||||
struct rng_ctx shuffle_rng;
|
struct rng_ctx shuffle_rng;
|
||||||
|
|
||||||
|
11
src/db.h
11
src/db.h
@ -105,6 +105,7 @@ struct pairing_info {
|
|||||||
char *guid;
|
char *guid;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Keep in sync with media_kind_labels[] */
|
||||||
enum media_kind {
|
enum media_kind {
|
||||||
MEDIA_KIND_MUSIC = 1,
|
MEDIA_KIND_MUSIC = 1,
|
||||||
MEDIA_KIND_MOVIE = 2,
|
MEDIA_KIND_MOVIE = 2,
|
||||||
@ -114,6 +115,13 @@ enum media_kind {
|
|||||||
MEDIA_KIND_TVSHOW = 64,
|
MEDIA_KIND_TVSHOW = 64,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const char *
|
||||||
|
db_media_kind_label(enum media_kind media_kind);
|
||||||
|
|
||||||
|
enum media_kind
|
||||||
|
db_media_kind_enum(const char *label);
|
||||||
|
|
||||||
|
/* Keep in sync with data_kind_label[] */
|
||||||
enum data_kind {
|
enum data_kind {
|
||||||
DATA_KIND_FILE = 0, /* normal file */
|
DATA_KIND_FILE = 0, /* normal file */
|
||||||
DATA_KIND_HTTP = 1, /* network stream (radio) */
|
DATA_KIND_HTTP = 1, /* network stream (radio) */
|
||||||
@ -121,6 +129,9 @@ enum data_kind {
|
|||||||
DATA_KIND_PIPE = 3, /* iTunes has no pipe data kind, but we use 3 */
|
DATA_KIND_PIPE = 3, /* iTunes has no pipe data kind, but we use 3 */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const char *
|
||||||
|
db_data_kind_label(enum data_kind data_kind);
|
||||||
|
|
||||||
/* Note that fields marked as integers in the metadata map in filescanner_ffmpeg must be uint32_t here */
|
/* Note that fields marked as integers in the metadata map in filescanner_ffmpeg must be uint32_t here */
|
||||||
struct media_file_info {
|
struct media_file_info {
|
||||||
char *path;
|
char *path;
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
#define STOB(s) ((s) * 4)
|
#define STOB(s) ((s) * 4)
|
||||||
#define BTOS(b) ((b) / 4)
|
#define BTOS(b) ((b) / 4)
|
||||||
|
|
||||||
|
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
|
||||||
|
|
||||||
struct onekeyval {
|
struct onekeyval {
|
||||||
char *name;
|
char *name;
|
||||||
@ -57,7 +58,6 @@ safe_strdup(const char *str);
|
|||||||
char *
|
char *
|
||||||
safe_asprintf(const char *fmt, ...);
|
safe_asprintf(const char *fmt, ...);
|
||||||
|
|
||||||
|
|
||||||
/* Key/value functions */
|
/* Key/value functions */
|
||||||
struct keyval *
|
struct keyval *
|
||||||
keyval_alloc(void);
|
keyval_alloc(void);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user