commit 760b0fbd24e7eaefbe0946b55fc2a1afc8574214
Author: Christophe Fergeau <[email protected]>
Date: Tue Oct 20 00:53:45 2009 +0200
add test case to copy files to the iPod
tests/Makefile.am | 7 ++-
tests/test-cp.cc | 165 +++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 171 insertions(+), 1 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index b4bbcc6..a4ab57a 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -16,12 +16,17 @@ endif
TESTMISC=test-init-ipod
if HAVE_TAGLIB
+TESTCP=test-cp
+test_cp_SOURCES = test-cp.cc
+test_cp_LDADD = $(TAGLIB_LIBS)
+test_cp_CXXFLAGS = $(TAGLIB_CFLAGS)
TESTTAGLIB=test-rebuild-db
test_rebuild_db_SOURCES = test-rebuild-db.cc
test_rebuild_db_LDADD = $(TAGLIB_LIBS)
test_rebuild_db_CXXFLAGS = $(TAGLIB_CFLAGS)
else
TESTTAGLIB=
+TESTCP=
endif
test_itdb_SOURCES = itdb_main.c
@@ -48,7 +53,7 @@ get_timezone_SOURCES = get-timezone.c
noinst_PROGRAMS=test-itdb test-ls test-checksum test-firewire-id \
test-sysinfo-extended-parsing \
- $(TESTTHUMBS) $(TESTTAGLIB) $(TESTMISC)
+ $(TESTTHUMBS) $(TESTTAGLIB) $(TESTCP) $(TESTMISC)
INCLUDES=$(LIBGPOD_CFLAGS) -I$(top_srcdir)/src
-DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\"
LIBS=$(LIBGPOD_LIBS) $(top_builddir)/src/libgpod.la
diff --git a/tests/test-cp.cc b/tests/test-cp.cc
new file mode 100644
index 0000000..43d015d
--- /dev/null
+++ b/tests/test-cp.cc
@@ -0,0 +1,165 @@
+/*
+ * Copyright (C) 2006, 2009 Christophe Fergeau
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <typeinfo>
+#include <unistd.h>
+
+#include <glib/gstdio.h>
+
+#include <id3v2tag.h>
+#include <mpegfile.h>
+
+#include "itdb.h"
+
+static Itdb_Track *
+track_from_file (const char *filename)
+{
+ TagLib::MPEG::File file(filename);
+ TagLib::Tag *tag;
+ Itdb_Track *track;
+ struct stat st;
+
+ tag = file.tag();
+ if (tag == NULL) {
+ g_print ("Couldn't read tag\n");
+ return NULL;
+ }
+/* if (typeid (*tag) != typeid (TagLib::ID3v2::Tag)) {
+ g_print ("Unknown tag type\n");
+ return NULL;
+ }*/
+
+ /* FIXME: what happens if we try to open a non-MP3 file? */
+#ifdef VERBOSE
+ g_print ("%s:\n", filename);
+ g_print ("\t%s\n", tag->artist().toCString(true));
+ g_print ("\t%s\n", tag->album().toCString(true));
+ g_print ("\t%s\n", tag->title().toCString(true));
+ g_print ("\t%s\n", tag->genre().toCString(true));
+ g_print ("\t%d\n", tag->year());
+ g_print ("\t%d\n", tag->track());
+ g_print ("\n");
+#endif
+ track = itdb_track_new ();
+ track->title = g_strdup (tag->title().toCString(true));
+ track->album = g_strdup (tag->album().toCString(true));
+ track->artist = g_strdup (tag->artist().toCString(true));
+ track->genre = g_strdup (tag->genre().toCString(true));
+ track->comment = g_strdup (tag->comment().toCString(true));
+ track->filetype = g_strdup ("MP3-file");
+ if (g_stat (filename, &st) == 0) {
+ track->size = st.st_size;
+ }
+ track->tracklen = file.audioProperties()->length() * 1000;
+ track->track_nr = tag->track();
+ track->bitrate = file.audioProperties()->bitrate();
+ track->samplerate = file.audioProperties()->sampleRate();
+ track->year = tag->year();
+ return track;
+}
+
+
+static void
+copy_file (Itdb_iTunesDB *db, const char *filename, GError **error)
+{
+ Itdb_Track *track;
+
+ track = track_from_file (filename);
+ itdb_cp_track_to_ipod (track, filename, error);
+ if (track->ipod_path == NULL) {
+ itdb_track_free (track);
+ return;
+ }
+
+ itdb_track_add (db, track, -1);
+ itdb_playlist_add_track (itdb_playlist_mpl(db), track, -1);
+}
+
+static Itdb_iTunesDB *
+itdb_create (const char *mountpoint)
+{
+ Itdb_Playlist *mpl;
+ Itdb_iTunesDB *db;
+
+ db = itdb_new ();
+ if (db == NULL) {
+ return NULL;
+ }
+ itdb_set_mountpoint (db, mountpoint);
+ mpl = itdb_playlist_new ("iPod", FALSE);
+ itdb_playlist_set_mpl (mpl);
+ itdb_playlist_add (db, mpl, -1);
+
+ return db;
+}
+
+int main (int argc, char **argv)
+{
+ Itdb_iTunesDB *db;
+ GError *error;
+
+ if (argc != 3) {
+ g_print ("Usage:\n");
+ g_print ("%s <mountpoint> <filename>\n", g_basename (argv[0]));
+ exit (1);
+ }
+
+ db = itdb_create (argv[1]);
+
+ if (db == NULL) {
+ g_print ("Error creating iPod database\n");
+ exit (1);
+ }
+
+ error = NULL;
+ copy_file (db, argv[2], &error);
+ if (error) {
+ g_print ("Error reading music files\n");
+ if (error->message) {
+ g_print("%s\n", error->message);
+ }
+ g_error_free (error);
+ exit (1);
+ }
+
+ itdb_write (db, &error);
+ if (error) {
+ g_print ("Error writing iPod database\n");
+ if (error->message) {
+ g_print("%s\n", error->message);
+ }
+ g_error_free (error);
+ exit (1);
+ }
+
+ itdb_free (db);
+
+ return 0;
+}
------------------------------------------------------------------------------
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev
_______________________________________________
gtkpod-cvs2 mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gtkpod-cvs2