utils: Move duration formatting to shared function
We'll be using this a few different places.
This commit is contained in:
parent
49aa42d893
commit
2b3bdb8373
19
metadata.c
19
metadata.c
@ -1,5 +1,5 @@
|
||||
/* MiniDLNA media server
|
||||
* Copyright (C) 2008-2009 Justin Maggard
|
||||
* Copyright (C) 2008-2017 Justin Maggard
|
||||
*
|
||||
* This file is part of MiniDLNA.
|
||||
*
|
||||
@ -363,11 +363,7 @@ GetAudioMetadata(const char *path, char *name)
|
||||
m.dlna_pn = strdup(song.dlna_pn);
|
||||
if( song.year )
|
||||
xasprintf(&m.date, "%04d-01-01", song.year);
|
||||
xasprintf(&m.duration, "%d:%02d:%02d.%03d",
|
||||
(song.song_length/3600000),
|
||||
(song.song_length/60000%60),
|
||||
(song.song_length/1000%60),
|
||||
(song.song_length%1000));
|
||||
m.duration = duration_str(song.song_length);
|
||||
if( song.title && *song.title )
|
||||
{
|
||||
m.title = trim(song.title);
|
||||
@ -806,20 +802,13 @@ GetVideoMetadata(const char *path, char *name)
|
||||
if( vstream )
|
||||
{
|
||||
int off;
|
||||
int duration, hours, min, sec, ms;
|
||||
ts_timestamp_t ts_timestamp = NONE;
|
||||
DPRINTF(E_DEBUG, L_METADATA, "Container: '%s' [%s]\n", ctx->iformat->name, basepath);
|
||||
xasprintf(&m.resolution, "%dx%d", lav_width(vstream), lav_height(vstream));
|
||||
if( ctx->bit_rate > 8 )
|
||||
m.bitrate = ctx->bit_rate / 8;
|
||||
if( ctx->duration > 0 ) {
|
||||
duration = (int)(ctx->duration / AV_TIME_BASE);
|
||||
hours = (int)(duration / 3600);
|
||||
min = (int)(duration / 60 % 60);
|
||||
sec = (int)(duration % 60);
|
||||
ms = (int)(ctx->duration / (AV_TIME_BASE/1000) % 1000);
|
||||
xasprintf(&m.duration, "%d:%02d:%02d.%03d", hours, min, sec, ms);
|
||||
}
|
||||
if( ctx->duration > 0 )
|
||||
m.duration = duration_str(ctx->duration / (AV_TIME_BASE/1000));
|
||||
|
||||
/* NOTE: The DLNA spec only provides for ASF (WMV), TS, PS, and MP4 containers.
|
||||
* Skip DLNA parsing for everything else. */
|
||||
|
16
utils.c
16
utils.c
@ -1,5 +1,5 @@
|
||||
/* MiniDLNA media server
|
||||
* Copyright (C) 2008-2009 Justin Maggard
|
||||
* Copyright (C) 2008-2017 Justin Maggard
|
||||
*
|
||||
* This file is part of MiniDLNA.
|
||||
*
|
||||
@ -230,6 +230,20 @@ escape_tag(const char *tag, int force_alloc)
|
||||
return esc_tag;
|
||||
}
|
||||
|
||||
char *
|
||||
duration_str(int msec)
|
||||
{
|
||||
char *str;
|
||||
|
||||
xasprintf(&str, "%d:%02d:%02d.%03d",
|
||||
(msec / 3600000),
|
||||
(msec / 60000 % 60),
|
||||
(msec / 1000 % 60),
|
||||
(msec % 1000));
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
char *
|
||||
strip_ext(char *name)
|
||||
{
|
||||
|
3
utils.h
3
utils.h
@ -5,7 +5,7 @@
|
||||
* Author : Justin Maggard
|
||||
*
|
||||
* MiniDLNA media server
|
||||
* Copyright (C) 2008-2009 Justin Maggard
|
||||
* Copyright (C) 2008-2017 Justin Maggard
|
||||
*
|
||||
* This file is part of MiniDLNA.
|
||||
*
|
||||
@ -80,6 +80,7 @@ char *strcasestrc(const char *s, const char *p, const char t);
|
||||
char *modifyString(char *string, const char *before, const char *after, int noalloc);
|
||||
char *escape_tag(const char *tag, int force_alloc);
|
||||
char *unescape_tag(const char *tag, int force_alloc);
|
||||
char *duration_str(int msec);
|
||||
char *strip_ext(char *name);
|
||||
|
||||
/* Metadata functions */
|
||||
|
Loading…
x
Reference in New Issue
Block a user