diff options
author | Jorg Schuler <jcsjcs@users.sourceforge.net> | 2008-04-19 09:13:33 +0000 |
---|---|---|
committer | Jorg Schuler <jcsjcs@users.sourceforge.net> | 2008-04-19 09:13:33 +0000 |
commit | d573e5c181ae8bcd9513fe10cbc939a749fb7a5f (patch) | |
tree | 9ed4f38c8360dd275ebea7fa7be2c28f48793ddf | |
parent | 72fab9b0f90099893bc28017af78eb54cc21563d (diff) | |
download | libgpod-d573e5c181ae8bcd9513fe10cbc939a749fb7a5f.tar.gz libgpod-d573e5c181ae8bcd9513fe10cbc939a749fb7a5f.tar.xz libgpod-d573e5c181ae8bcd9513fe10cbc939a749fb7a5f.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
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | bindings/python/examples/Makefile.am | 1 | ||||
-rw-r--r-- | bindings/python/examples/fix_empty_artist_field.py | 52 |
3 files changed, 58 insertions, 0 deletions
@@ -1,3 +1,8 @@ +2008-01-26 Jorg Schuler <jcsjcs at users.sourceforge.net> + + * bindings/python/examples/Makefile.am + Added fix_empty_artist_field.py provided by Thomas Perl. + 2008-03-29 Todd Zullinger <tmzullinger at users.sourceforge.net> * bindings/python/Makefile.am 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) + |