summaryrefslogtreecommitdiffstats
path: root/bindings
diff options
context:
space:
mode:
authorJorg Schuler <jcsjcs@users.sourceforge.net>2008-04-19 09:13:33 +0000
committerJorg Schuler <jcsjcs@users.sourceforge.net>2008-04-19 09:13:33 +0000
commitfb856c205d073c28199dc9a6726c997115f35dda (patch)
tree9ed4f38c8360dd275ebea7fa7be2c28f48793ddf /bindings
parentd8c6a34e936083f3781984fe726bcf2be916f560 (diff)
downloadlibgpod-tmz-fb856c205d073c28199dc9a6726c997115f35dda.tar.gz
libgpod-tmz-fb856c205d073c28199dc9a6726c997115f35dda.tar.xz
libgpod-tmz-fb856c205d073c28199dc9a6726c997115f35dda.zip
* bindings/python/examples/Makefile.am
Added fix_empty_artist_field.py provided by Thomas Perl. git-svn-id: https://gtkpod.svn.sf.net/svnroot/gtkpod/libgpod/trunk@1963 f01d2545-417e-4e96-918e-98f8d0dbbcb6
Diffstat (limited to 'bindings')
-rw-r--r--bindings/python/examples/Makefile.am1
-rw-r--r--bindings/python/examples/fix_empty_artist_field.py52
2 files changed, 53 insertions, 0 deletions
diff --git a/bindings/python/examples/Makefile.am b/bindings/python/examples/Makefile.am
index 1565df4..993c665 100644
--- a/bindings/python/examples/Makefile.am
+++ b/bindings/python/examples/Makefile.am
@@ -2,6 +2,7 @@ EXTRA_DIST = \
add_song.py \
coverart_fetch.py \
create_mp3_tags_from_itdb.py \
+ fix_empty_artist_field.py \
play_with_ipod_api.py \
play_with_smart_playlists.py \
save_photos.py \
diff --git a/bindings/python/examples/fix_empty_artist_field.py b/bindings/python/examples/fix_empty_artist_field.py
new file mode 100644
index 0000000..f1832be
--- /dev/null
+++ b/bindings/python/examples/fix_empty_artist_field.py
@@ -0,0 +1,52 @@
+#!/usr/bin/python
+"""
+Fix iTunesDB tracks that have filename-like titles, but no artist
+-----------------------------------------------------------------
+
+Edit tracks that have no artist, but a title that looks like a
+MP3 filename, by trying to split the title into Artist and Title
+fields and then updating the fields in the iTunesDB.
+
+Author: Thomas Perl <thpinfo.com>, 2008-03-28
+"""
+
+import gpod
+import os.path
+import sys
+
+if len(sys.argv) == 1:
+ print 'Usage: python %s /path/to/ipod' % os.path.basename(sys.argv[0])
+ print __doc__
+ sys.exit(-1)
+else:
+ mount_point = sys.argv[-1]
+
+try:
+ db = gpod.Database(mount_point)
+except gpod.ipod.DatabaseException, dbe:
+ print 'Error opening your iPod database: %s' % dbe
+ sys.exit(-2)
+
+(updated, count) = (0, len(db))
+
+print 'Database opened: %d tracks to consider' % count
+for track in db:
+ # If the track has a ".mp3" title and no artist, try to fix it
+ if track['title'].lower().endswith('.mp3') and track['artist'] is None:
+ # Assume "Artist - Title.mp3" file names
+ items = os.path.splitext(track['title'])[0].split(' - ')
+ if len(items) == 2:
+ (artist, title) = items
+ print 'Correcting: %s' % track['title']
+ track['artist'] = artist
+ track['title'] = artist
+ updated += 1
+ else:
+ # Doesn't look like "Artist - Title.mp3", leave untouched
+ print 'Leaving untouched: %s' % repr(items)
+
+print 'Saving iPod database...'
+db.close()
+
+print 'Finished. %d tracks updated, %d tracks untouched' % (updated, count-updated)
+