[db] Add function to get a human readable string for data and media kind

This commit is contained in:
chme 2018-02-24 11:28:42 +01:00
parent d59e62312a
commit 66bdb7c0a9
3 changed files with 74 additions and 1 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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);