summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJorg Schuler <jcsjcs@users.sourceforge.net>2005-09-23 03:00:27 +0000
committerJorg Schuler <jcsjcs@users.sourceforge.net>2005-09-23 03:00:27 +0000
commit4736ad7ce4ec22c710d1519b2d80b972de9774b8 (patch)
treed592aa23cee73677bd17a1c33c4a2f0d931be45a
parenta0b713da025da8d0a44af6ad2e81f7f1830fecc8 (diff)
downloadlibgpod-tmz-4736ad7ce4ec22c710d1519b2d80b972de9774b8.tar.gz
libgpod-tmz-4736ad7ce4ec22c710d1519b2d80b972de9774b8.tar.xz
libgpod-tmz-4736ad7ce4ec22c710d1519b2d80b972de9774b8.zip
* added python bindings provided by Nicholas Piper
<nick at nickpiper co uk> git-svn-id: https://gtkpod.svn.sf.net/svnroot/gtkpod/libgpod/trunk@1099 f01d2545-417e-4e96-918e-98f8d0dbbcb6
-rw-r--r--ChangeLog5
-rw-r--r--bindings/python/Makefile20
-rw-r--r--bindings/python/gpod.i40
-rwxr-xr-xbindings/python/play.py44
4 files changed, 109 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 5734f85..7777a8f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
2005-09-22 Jorg Schuler <jcsjcs at users.sourceforge.net>
+ * added python bindings provided by Nicholas Piper
+ <nick at nickpiper co uk>
+
+2005-09-22 Jorg Schuler <jcsjcs at users.sourceforge.net>
+
* applied Christophe Fergeau's patch which adds cover art writing
support to libgpod -> bump to version 104
diff --git a/bindings/python/Makefile b/bindings/python/Makefile
new file mode 100644
index 0000000..573cc8d
--- /dev/null
+++ b/bindings/python/Makefile
@@ -0,0 +1,20 @@
+all: _gpod.so
+
+gpod_wrap.c: gpod.i
+ swig -python gpod.i
+
+gpod.py: gpod.i
+ swig -python gpod.i
+
+gpod_wrap.o: gpod_wrap.c
+ gcc -c -fpic gpod_wrap.c -I /usr/include/python2.3/ `pkg-config glib-2.0 --cflags`
+
+_gpod.so: gpod_wrap.o
+ gcc -shared gpod_wrap.o -o _gpod.so -L../../src/.libs -lgpod `pkg-config glib-2.0 --libs`
+
+
+clean:
+ rm gpod.py gpod.pyc _gpod.so gpod_wrap.c gpod_wrap.o
+
+test: _gpod.so play.py
+ LD_LIBRARY_PATH=../../src/.libs ./play.py
diff --git a/bindings/python/gpod.i b/bindings/python/gpod.i
new file mode 100644
index 0000000..7bfab55
--- /dev/null
+++ b/bindings/python/gpod.i
@@ -0,0 +1,40 @@
+/* File : gpod.i */
+%module gpod
+%{
+#include "../../src/db-artwork-debug.h"
+#include "../../src/db-artwork-parser.h"
+#include "../../src/db-image-parser.h"
+#include "../../src/db-itunes-parser.h"
+#include "../../src/db-parse-context.h"
+#include "../../src/itdb.h"
+#include "../../src/itdb_private.h"
+
+PyObject* sw_get_tracks(Itdb_iTunesDB *itdb) {
+ PyObject *list;
+ gint i;
+ GList *l;
+ list = PyList_New(g_list_length(itdb->tracks));
+ for (l = itdb->tracks, i = 0; l; l = l->next, ++i) {
+ PyList_SET_ITEM(list, i, SWIG_NewPointerObj((void*)(l->data), SWIGTYPE_p_Itdb_Track, 0));
+ }
+ return list;
+ }
+
+PyObject* sw_get_playlists(Itdb_iTunesDB *itdb) {
+ PyObject *list;
+ gint i;
+ GList *l;
+ list = PyList_New(g_list_length(itdb->playlists));
+ for (l = itdb->playlists, i = 0; l; l = l->next, ++i) {
+ PyList_SET_ITEM(list, i, SWIG_NewPointerObj((void*)(l->data), SWIGTYPE_p_Itdb_Playlist, 0));
+ }
+ return list;
+ }
+%}
+
+typedef char gchar;
+typedef int gboolean;
+
+PyObject* sw_get_tracks(Itdb_iTunesDB *itdb);
+PyObject* sw_get_playlists(Itdb_iTunesDB *itdb);
+%include "../../src/itdb.h"
diff --git a/bindings/python/play.py b/bindings/python/play.py
new file mode 100755
index 0000000..6ad6f60
--- /dev/null
+++ b/bindings/python/play.py
@@ -0,0 +1,44 @@
+#!/usr/bin/python
+
+import os, os.path
+import gpod
+import sys
+
+ipod_mount = '/mnt/ipod'
+
+remove_track = "The Dancer"
+
+#dbname = os.path.join(os.environ['HOME'],".gtkpod/iTunesDB")
+dbname = os.path.join(ipod_mount,"iPod_Control/iTunes/iTunesDB")
+
+itdb = gpod.itdb_parse_file(dbname, None)
+if not itdb:
+ print "Failed to read %s" % dbname
+ sys.exit(2)
+itdb.mountpoint = ipod_mount
+
+
+for track in gpod.sw_get_tracks(itdb):
+ lists = []
+ for playlist in gpod.sw_get_playlists(itdb):
+ if gpod.itdb_playlist_contains_track(playlist, track):
+ lists.append(playlist)
+
+ print "%-25s %-20s %-20s %-30s %s" % (track.title,
+ track.album,
+ track.artist,
+ gpod.itdb_filename_on_ipod(track),
+ repr(",".join([l.name for l in lists])))
+
+ if track.title == remove_track:
+ print "Removing track.."
+ print "..disk"
+ os.unlink(gpod.itdb_filename_on_ipod(track))
+ for l in lists:
+ print "..playlist %s" % l.name
+ gpod.itdb_playlist_remove_track(l, track)
+ print "..db"
+ gpod.itdb_track_unlink(track)
+ print "Track removed."
+
+gpod.itdb_write_file(itdb, dbname, None)