summaryrefslogtreecommitdiffstats
path: root/demux/demux_cue.c
diff options
context:
space:
mode:
authorwnoun <wnoun@outlook.com>2019-04-07 21:10:52 +0800
committerwm4 <1387750+wm4@users.noreply.github.com>2019-09-21 15:18:20 +0200
commit1c43920fb85387aaf7267b4b79dc829896bd610d (patch)
treebff1cfc4a593fe44660e0775d1b26abc5ad84459 /demux/demux_cue.c
parenta35da6612e8aed997da1c5322df0c8f0b88ff3e3 (diff)
downloadmpv-1c43920fb85387aaf7267b4b79dc829896bd610d.tar.bz2
mpv-1c43920fb85387aaf7267b4b79dc829896bd610d.tar.xz
demux_cue: auto-detect CUE sheet charset
Diffstat (limited to 'demux/demux_cue.c')
-rw-r--r--demux/demux_cue.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/demux/demux_cue.c b/demux/demux_cue.c
index 708b742e8f..59628c74b4 100644
--- a/demux/demux_cue.c
+++ b/demux/demux_cue.c
@@ -28,8 +28,11 @@
#include "mpv_talloc.h"
#include "misc/bstr.h"
+#include "misc/charset_conv.h"
#include "common/msg.h"
#include "demux/demux.h"
+#include "options/m_config.h"
+#include "options/m_option.h"
#include "options/path.h"
#include "common/common.h"
#include "stream/stream.h"
@@ -39,8 +42,25 @@
#define PROBE_SIZE 512
+#define OPT_BASE_STRUCT struct demux_cue_opts
+struct demux_cue_opts {
+ char *cue_cp;
+};
+
+const struct m_sub_options demux_cue_conf = {
+ .opts = (const m_option_t[]) {
+ OPT_STRING("codepage", cue_cp, 0),
+ {0}
+ },
+ .size = sizeof(struct demux_cue_opts),
+ .defaults = &(const struct demux_cue_opts) {
+ .cue_cp = "auto"
+ }
+};
+
struct priv {
struct cue_file *f;
+ struct demux_cue_opts *opts;
};
static void add_source(struct timeline *tl, struct demuxer *d)
@@ -252,10 +272,21 @@ static int try_open_file(struct demuxer *demuxer, enum demux_check check)
struct priv *p = talloc_zero(demuxer, struct priv);
demuxer->priv = p;
demuxer->fully_read = true;
+ p->opts = mp_get_config_group(p, demuxer->global, &demux_cue_conf);
+ struct demux_cue_opts *cue_opts = p->opts;
bstr data = stream_read_complete(s, p, 1000000);
if (data.start == NULL)
return -1;
+ const char *charset = mp_charset_guess(p, demuxer->log, data, cue_opts->cue_cp, 0);
+ if (charset && !mp_charset_is_utf8(charset)) {
+ MP_INFO(demuxer, "Using CUE charset: %s\n", charset);
+ bstr utf8 = mp_iconv_to_utf8(demuxer->log, data, charset, MP_ICONV_VERBOSE);
+ if (utf8.start && utf8.start != data.start) {
+ ta_steal(data.start, utf8.start);
+ data = utf8;
+ }
+ }
p->f = mp_parse_cue(data);
talloc_steal(p, p->f);
if (!p->f) {