summaryrefslogtreecommitdiff
path: root/plugins/flac
diff options
context:
space:
mode:
authorGravatar Ian Nartowicz <iann@crunchbang>2014-06-04 22:45:30 +0100
committerGravatar Ian Nartowicz <iann@crunchbang>2014-06-04 22:45:30 +0100
commit823a4064ebcd2662f8e480f99326ac75dd6404a7 (patch)
tree420f6df26d390479f5573acb4f922d62d458ae8c /plugins/flac
parent923bdcd04d441869dc0fc9350c5bfb856f6e5677 (diff)
Full release of oggedit
Diffstat (limited to 'plugins/flac')
-rw-r--r--plugins/flac/Makefile.am2
-rw-r--r--plugins/flac/flac.c119
2 files changed, 79 insertions, 42 deletions
diff --git a/plugins/flac/Makefile.am b/plugins/flac/Makefile.am
index 02e594d3..c87ca53d 100644
--- a/plugins/flac/Makefile.am
+++ b/plugins/flac/Makefile.am
@@ -2,7 +2,7 @@ if HAVE_FLAC
flacdir = $(libdir)/$(PACKAGE)
pkglib_LTLIBRARIES = flac.la
flac_la_SOURCES = flac.c
-flac_la_LDFLAGS = -module -avoid-version
+flac_la_LDFLAGS = -module -avoid-version -export-symbols-regex flac_load
flac_la_LIBADD = $(LDADD) $(FLAC_LIBS) ../liboggedit/liboggedit.a
AM_CFLAGS = $(CFLAGS) $(FLAC_CFLAGS) -std=c99
diff --git a/plugins/flac/flac.c b/plugins/flac/flac.c
index 9a823b9e..e48f30a4 100644
--- a/plugins/flac/flac.c
+++ b/plugins/flac/flac.c
@@ -1,49 +1,52 @@
/*
- DeaDBeeF - ultimate music player for GNU/Linux systems with X11
- Copyright (C) 2009-2013 Alexey Yakovenko <waker@users.sourceforge.net>
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions
- are met:
-
- - Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
-
- - Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
-
- - Neither the name of the DeaDBeeF Player nor the names of its
- contributors may be used to endorse or promote products derived from
- this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
- CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ DeaDBeeF - ultimate music player for GNU/Linux systems with X11
+ Copyright (C) 2009-2013 Alexey Yakovenko <waker@users.sourceforge.net>
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ - Neither the name of the DeaDBeeF Player nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
+#include <stdbool.h>
+#include <math.h>
#include <FLAC/stream_decoder.h>
#include <FLAC/metadata.h>
-#include <math.h>
#include "../../deadbeef.h"
#include "../artwork/artwork.h"
+#include "../liboggedit/oggedit.h"
static DB_decoder_t plugin;
static DB_functions_t *deadbeef;
static DB_artwork_plugin_t *coverart_plugin = NULL;
-//#define trace(...) { fprintf(stderr, __VA_ARGS__); }
+// #define trace(...) { fprintf(stderr, __VA_ARGS__); }
#define trace(fmt,...)
#define min(x,y) ((x)<(y)?(x):(y))
@@ -653,9 +656,9 @@ cflac_insert_with_embedded_cue (ddb_playlist_t *plt, DB_playItem_t *after, DB_pl
deadbeef->pl_item_unref (it);
}
deadbeef->pl_item_ref (after);
-
+
DB_playItem_t *first = deadbeef->pl_get_next (ins, PL_MAIN);
-
+
if (!first) {
first = deadbeef->plt_get_first (plt, PL_MAIN);
}
@@ -871,8 +874,11 @@ cflac_read_metadata (DB_playItem_t *it) {
FLAC__bool res = FLAC__metadata_chain_read (chain, deadbeef->pl_find_meta (it, ":URI"));
deadbeef->pl_unlock ();
if (!res) {
- trace ("cflac_read_metadata: FLAC__metadata_chain_read failed\n");
- goto error;
+ FLAC__bool res = FLAC__metadata_chain_read_ogg (chain, deadbeef->pl_find_meta (it, ":URI"));
+ if (!res) {
+ trace ("cflac_read_metadata: FLAC__metadata_chain_read failed\n");
+ goto error;
+ }
}
FLAC__metadata_chain_merge_padding (chain);
@@ -924,6 +930,27 @@ error:
}
int
+cflac_write_metadata_ogg (DB_playItem_t *it, FLAC__StreamMetadata_VorbisComment *vc)
+{
+ char fname[PATH_MAX];
+ deadbeef->pl_get_meta (it, ":URI", fname, sizeof (fname));
+
+ size_t num_tags = vc->num_comments;
+ char **tags = calloc(num_tags+1, sizeof(char **));
+ for (size_t i = 0; i < num_tags; i++)
+ tags[i] = vc->comments[i].entry;
+ const off_t file_size = oggedit_write_flac_metadata (deadbeef->fopen(fname), fname, 0, num_tags, tags);
+ if (file_size <= 0) {
+ trace ("cflac_write_metadata_ogg: oggedit_write_flac_metadata failed: code %d\n", file_size);
+ return -1;
+ }
+
+ free(tags);
+
+ return 0;
+}
+
+int
cflac_write_metadata (DB_playItem_t *it) {
int err = -1;
FLAC__Metadata_Chain *chain = NULL;
@@ -937,8 +964,13 @@ cflac_write_metadata (DB_playItem_t *it) {
deadbeef->pl_lock ();
FLAC__bool res = FLAC__metadata_chain_read (chain, deadbeef->pl_find_meta (it, ":URI"));
deadbeef->pl_unlock ();
+ FLAC__bool isogg = false;
+ if (!res && FLAC__metadata_chain_status(chain) == FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_A_FLAC_FILE) {
+ isogg = true;
+ res = FLAC__metadata_chain_read_ogg (chain, deadbeef->pl_find_meta (it, ":URI"));
+ }
if (!res) {
- trace ("cflac_write_metadata: FLAC__metadata_chain_read failed\n");
+ trace ("cflac_write_metadata: FLAC__metadata_chain_read(_ogg) failed\n");
goto error;
}
FLAC__metadata_chain_merge_padding (chain);
@@ -1128,10 +1160,15 @@ error2:
}
#endif
- if (!FLAC__metadata_chain_write (chain, 1, 0)) {
- trace ("cflac_write_metadata: FLAC__metadata_chain_write failed\n");
+ if (isogg)
+ res = cflac_write_metadata_ogg(it, &data->data.vorbis_comment);
+ else
+ res = FLAC__metadata_chain_write (chain, 1, 0);
+ if (res) {
+ trace ("cflac_write_metadata: failed to write tags: code %d\n", res);
goto error;
}
+
err = 0;
error:
FLAC__metadata_iterator_delete (iter);
@@ -1154,9 +1191,9 @@ static DB_decoder_t plugin = {
.plugin.id = "stdflac",
.plugin.name = "FLAC decoder",
.plugin.descr = "FLAC decoder using libFLAC",
- .plugin.copyright =
+ .plugin.copyright =
"Copyright (C) 2009-2013 Alexey Yakovenko et al.\n"
- "Uses libFLAC (C) Copyright (C) 2000,2001,2002,2003,2004,2005,2006,2007 Josh Coalson\n"
+ "Uses libFLAC (C) Copyright (C) 2000,2001,2002,2003,2004,2005,2006,2007 Josh Coalson\n"
"Uses libogg Copyright (c) 2002, Xiph.org Foundation\n"
"\n"
"Redistribution and use in source and binary forms, with or without\n"
@@ -1177,7 +1214,7 @@ static DB_decoder_t plugin = {
"THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n"
"``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n"
"LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n"
- "A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR\n"
+ "A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR\n"
"CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\n"
"EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\n"
"PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n"