summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicholas Piper <nicholas@users.sourceforge.net>2006-05-14 14:25:17 +0000
committerNicholas Piper <nicholas@users.sourceforge.net>2006-05-14 14:25:17 +0000
commit728f3b6e7f906b3e1734e0f8bd7db25ca9bf6bdd (patch)
tree94a61ce65656c30df5a3de0f16ab7af11ee0401c
parent303a09d9da9aeb679a627d88887db3f04a0d7baa (diff)
downloadlibgpod-728f3b6e7f906b3e1734e0f8bd7db25ca9bf6bdd.tar.gz
libgpod-728f3b6e7f906b3e1734e0f8bd7db25ca9bf6bdd.tar.xz
libgpod-728f3b6e7f906b3e1734e0f8bd7db25ca9bf6bdd.zip
Add missing gtkpod.py ; rename playwith_ipod_api.py to use an underscore.
git-svn-id: https://gtkpod.svn.sf.net/svnroot/gtkpod/libgpod/trunk@1261 f01d2545-417e-4e96-918e-98f8d0dbbcb6
-rw-r--r--bindings/python/examples/Makefile.am2
-rwxr-xr-xbindings/python/examples/play_with_ipod_api.py (renamed from bindings/python/examples/playwith_ipod_api.py)0
-rw-r--r--bindings/python/gtkpod.py99
3 files changed, 100 insertions, 1 deletions
diff --git a/bindings/python/examples/Makefile.am b/bindings/python/examples/Makefile.am
index 5e6100f..c61802e 100644
--- a/bindings/python/examples/Makefile.am
+++ b/bindings/python/examples/Makefile.am
@@ -1,4 +1,4 @@
EXTRA_DIST = coverart_fetch.py toy_around.py \
tag_genre_from_audioscrobber.py add_song.py \
- playwith_ipod_api.py create_mp3_tags_from_itdb.py \
+ play_with_ipod_api.py create_mp3_tags_from_itdb.py \
play_with_smart_playlists.py
diff --git a/bindings/python/examples/playwith_ipod_api.py b/bindings/python/examples/play_with_ipod_api.py
index 4780f73..4780f73 100755
--- a/bindings/python/examples/playwith_ipod_api.py
+++ b/bindings/python/examples/play_with_ipod_api.py
diff --git a/bindings/python/gtkpod.py b/bindings/python/gtkpod.py
new file mode 100644
index 0000000..f9d044a
--- /dev/null
+++ b/bindings/python/gtkpod.py
@@ -0,0 +1,99 @@
+#!/usr/bin/env python
+import sha
+import os
+import socket
+
+# This file is originally stolen from pypod-0.5.0
+# http://superduper.net/index.py?page=pypod
+# I hope that's ok, both works are GPL.
+
+hostname = socket.gethostname()
+
+class ParseError(Exception):
+ pass
+
+class SyncError(Exception):
+ pass
+
+def sha1_hash(filename):
+ import struct
+ # only hash the first 16k
+ hash_len = 4*4096
+ hash = sha.sha()
+ size = os.path.getsize(filename)
+ hash.update(struct.pack("<L", size))
+ hash.update(open(filename).read(hash_len))
+ return hash.hexdigest()
+
+def write(filename, db, itunesdb_file):
+ file = open(filename, "w")
+
+ def write_pair(name, value):
+ value = unicode(value).encode("utf-8")
+ file.write("=".join([name, value]))
+ file.write('\n')
+
+ write_pair("itunesdb_hash", sha1_hash(itunesdb_file))
+ write_pair("version", "0.88.1")
+
+ for track in db:
+ write_pair("id", track['id'])
+ if not track['userdata']:
+ track['userdata'] = {}
+ track['userdata']['filename_ipod'] = track.ipod_filename()
+ try:
+ del track['userdata']['md5_hash']
+ except IndexError:
+ pass
+ if track['userdata'].has_key('filename_locale') and not track['userdata'].has_key('md5_hash'):
+ if os.path.exists(track['userdata']['filename_locale']):
+ track['userdata']['md5_hash'] = sha1_hash(
+ track['userdata']['filename_locale'])
+ [write_pair(i[0],i[1]) for i in track['userdata'].items()]
+
+ write_pair("id", "xxx")
+
+def parse(filename, db, itunesdb_file=None):
+ tracks_by_id = {}
+ tracks_by_sha = {}
+ id = 0
+ ext_hash_valid = True
+
+ for track in db:
+ track['userdata'] = {}
+
+ for track in db:
+ tracks_by_id[track['id']] = track
+
+ track = None
+ file = open(filename)
+ ext_data = {}
+ ext_block = None
+ for line in file:
+ parts = line.strip().split("=", 1)
+ if len(parts) != 2:
+ print parts
+ name, value = parts
+ if name == "id":
+ if ext_block:
+ ext_data[id] = ext_block
+ if value != 'xxx':
+ id = int(value)
+ ext_block = {}
+ elif name == "version":
+ pass
+ elif name == "itunesdb_hash":
+ if itunesdb_file and sha1_hash(itunesdb_file) != value:
+ ext_hash_valid = False
+ else:
+ ext_block[name] = value
+
+ if ext_hash_valid:
+ for id,ext_block in ext_data.items():
+ tracks_by_id[id]['userdata'] = ext_block
+ else:
+ for track in db:
+ tracks_by_sha[sha1_hash(track.ipod_filename())] = track
+ for ext_block in ext_data.values():
+ tracks_by_sha[ext_block['md5_hash']]['userdata'] = ext_block
+