diff --git a/docs/iTunesSD3gen.md b/docs/iTunesSD3gen.md index 9e1900b..61b2b47 100644 --- a/docs/iTunesSD3gen.md +++ b/docs/iTunesSD3gen.md @@ -931,4 +931,5 @@ It seems to be ignored when shuffling within a playlist!
A dbid of all zeros yields a voiceover of All songs. Also playlist dbids without a corresponding voiceover file will yield a voiceover of playlist n or audiobook n where n is the playlist number. The shuffle assumes the podcast playlist is last.

The iTunesStats file is also different in the 3gen iPod. +

Original Source: http://shuffle3db.wikispaces.com/iTunesSD3gen (expired)

diff --git a/docs/iTunesStats3gen.md b/docs/iTunesStats3gen.md index b8a60b9..bc6816e 100644 --- a/docs/iTunesStats3gen.md +++ b/docs/iTunesStats3gen.md @@ -108,4 +108,8 @@ Here's the general layout of an iTunesSD file:

- 00 00 00 00 + 00 00 00 00
+ + + +

Original Source: http://shuffle3db.wikispaces.com/iTunesStats3gen (expired)

diff --git a/shuffle.py b/shuffle.py index 5b41d5b..186f157 100755 --- a/shuffle.py +++ b/shuffle.py @@ -14,6 +14,7 @@ import argparse import shutil import re import tempfile +import signal audio_ext = (".mp3", ".m4a", ".m4b", ".m4p", ".aa", ".wav") list_ext = (".pls", ".m3u") @@ -439,9 +440,8 @@ class Playlist(Record): return fullPath def populate(self, filename): - f = open(filename, "rb") - data = f.readlines() - f.close() + with open(filename, 'rb') as f: + data = f.readlines() extension = os.path.splitext(filename)[1].lower() if extension == '.pls': @@ -528,9 +528,8 @@ class Shuffler(object): self.lists.append(os.path.abspath(os.path.join(dirpath, filename))) def write_database(self): - f = open(os.path.join(self.base, "iPod_Control", "iTunes", "iTunesSD"), "wb") - f.write(self.tunessd.construct()) - f.close() + with open(os.path.join(self.base, "iPod_Control", "iTunes", "iTunesSD"), "wb") as f: + f.write(self.tunessd.construct()) # # Read all files from the directory @@ -571,7 +570,21 @@ def nonnegative_int(string): raise argparse.ArgumentTypeError("Track gain value should be in range 0-99") return intval +def checkPathValidity(path): + if not os.path.isdir(result.path): + print "Error finding IPod directory. Maybe it is not connected or mounted?" + sys.exit(1) + + if not os.access(result.path, os.W_OK): + print 'Unable to get write permissions in the IPod directory' + sys.exit(1) + +def handle_interrupt(signal, frame): + print "Interrupt detected, exiting..." + sys.exit(1) + if __name__ == '__main__': + signal.signal(signal.SIGINT, handle_interrupt) parser = argparse.ArgumentParser() parser.add_argument('--disable-voiceover', action='store_true', help='Disable voiceover feature') parser.add_argument('--rename-unicode', action='store_true', help='Rename files causing unicode errors, will do minimal required renaming') @@ -579,9 +592,7 @@ if __name__ == '__main__': parser.add_argument('path', help='Path to the IPod\'s root directory') result = parser.parse_args() - if not os.path.isdir(result.path): - print "Error finding IPod directory. Maybe it is not connected or mounted?" - sys.exit() + checkPathValidity(result.path) if result.rename_unicode: check_unicode(result.path)