[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" },
|
||||
};
|
||||
|
||||
|
||||
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 */
|
||||
struct rng_ctx shuffle_rng;
|
||||
|
||||
|
|
11
src/db.h
11
src/db.h
|
@ -105,6 +105,7 @@ struct pairing_info {
|
|||
char *guid;
|
||||
};
|
||||
|
||||
/* Keep in sync with media_kind_labels[] */
|
||||
enum media_kind {
|
||||
MEDIA_KIND_MUSIC = 1,
|
||||
MEDIA_KIND_MOVIE = 2,
|
||||
|
@ -114,6 +115,13 @@ enum media_kind {
|
|||
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 {
|
||||
DATA_KIND_FILE = 0, /* normal file */
|
||||
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 */
|
||||
};
|
||||
|
||||
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 */
|
||||
struct media_file_info {
|
||||
char *path;
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#define STOB(s) ((s) * 4)
|
||||
#define BTOS(b) ((b) / 4)
|
||||
|
||||
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
|
||||
|
||||
struct onekeyval {
|
||||
char *name;
|
||||
|
@ -57,7 +58,6 @@ safe_strdup(const char *str);
|
|||
char *
|
||||
safe_asprintf(const char *fmt, ...);
|
||||
|
||||
|
||||
/* Key/value functions */
|
||||
struct keyval *
|
||||
keyval_alloc(void);
|
||||
|
|
Loading…
Reference in New Issue