mirror of
https://github.com/nims11/IPod-Shuffle-4g.git
synced 2025-12-08 00:18:01 +09:00
unicode error resolved
This commit is contained in:
parent
68cb053ad4
commit
3ce4cd7db0
2 changed files with 31 additions and 2 deletions
|
|
@ -21,6 +21,7 @@ optional arguments:
|
||||||
#### Additions to the original
|
#### Additions to the original
|
||||||
* Option to disable voiceover
|
* Option to disable voiceover
|
||||||
* Initialize the IPod Directory tree
|
* Initialize the IPod Directory tree
|
||||||
|
* Instead of throwing an unicode error, renames the filename
|
||||||
|
|
||||||
##TODO
|
##TODO
|
||||||
* Last.fm Scrobbler
|
* Last.fm Scrobbler
|
||||||
|
|
|
||||||
28
shuffle.py
28
shuffle.py
|
|
@ -339,7 +339,11 @@ class Playlist(Record):
|
||||||
|
|
||||||
chunks = ""
|
chunks = ""
|
||||||
for i in self.listtracks:
|
for i in self.listtracks:
|
||||||
|
try:
|
||||||
position = tracks.index(self.ipod_to_path(i))
|
position = tracks.index(self.ipod_to_path(i))
|
||||||
|
except:
|
||||||
|
print tracks
|
||||||
|
raise
|
||||||
if position > -1:
|
if position > -1:
|
||||||
chunks += struct.pack("I", position)
|
chunks += struct.pack("I", position)
|
||||||
self["number_of_songs"] += 1
|
self["number_of_songs"] += 1
|
||||||
|
|
@ -406,12 +410,36 @@ def initialize(base_path):
|
||||||
for dirname in ('iPod_Control/iTunes', 'iPod_Control/Music', 'iPod_Control/Speakable/Playlists', 'iPod_Control/Speakable/Tracks'):
|
for dirname in ('iPod_Control/iTunes', 'iPod_Control/Music', 'iPod_Control/Speakable/Playlists', 'iPod_Control/Speakable/Tracks'):
|
||||||
make_dir_if_absent(os.path.join(base_path, dirname))
|
make_dir_if_absent(os.path.join(base_path, dirname))
|
||||||
|
|
||||||
|
def check_unicode(path):
|
||||||
|
for (dirpath, dirnames, filenames) in os.walk(path):
|
||||||
|
for dirname in dirnames:
|
||||||
|
try:
|
||||||
|
dirname.decode('utf-8').encode('latin-1')
|
||||||
|
except UnicodeEncodeError, UnicodeDecodeError:
|
||||||
|
src = os.path.join(dirpath, dirname)
|
||||||
|
new_name = "".join(["{0:02X}".format(ord(x)) for x in reversed(hashlib.md5(dirname).digest()[:8])])
|
||||||
|
dest = os.path.join(dirpath, new_name)
|
||||||
|
print 'Renaming %s -> %s' % (src, dest)
|
||||||
|
os.rename(src, dest)
|
||||||
|
dirnames[dirnames.index(dirname)] = new_name
|
||||||
|
for filename in filenames:
|
||||||
|
if os.path.splitext(filename)[1].lower() in (".mp3", ".m4a", ".m4b", ".m4p", ".aa", ".wav", ".pls", ".m3u"):
|
||||||
|
try:
|
||||||
|
filename.decode('utf-8').encode('latin-1')
|
||||||
|
except UnicodeEncodeError, UnicodeDecodeError:
|
||||||
|
src = os.path.join(dirpath, filename)
|
||||||
|
dest = os.path.join(dirpath,
|
||||||
|
"".join(["{0:02X}".format(ord(x)) for x in reversed(hashlib.md5(filename).digest()[:8])])) + os.path.splitext(filename)[1].lower()
|
||||||
|
print 'Renaming %s -> %s' % (src, dest)
|
||||||
|
os.rename(src , dest)
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('--disable-voiceover', action='store_true')
|
parser.add_argument('--disable-voiceover', action='store_true')
|
||||||
parser.add_argument('path')
|
parser.add_argument('path')
|
||||||
result = parser.parse_args()
|
result = parser.parse_args()
|
||||||
|
|
||||||
|
check_unicode(result.path)
|
||||||
|
|
||||||
initialize(result.path)
|
initialize(result.path)
|
||||||
shuffle = Shuffler(result.path, voiceover=not result.disable_voiceover)
|
shuffle = Shuffler(result.path, voiceover=not result.disable_voiceover)
|
||||||
shuffle.populate()
|
shuffle.populate()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue