From 47070a38332e1b7a13f2695183e9834957e90432 Mon Sep 17 00:00:00 2001 From: Nimesh Ghelani Date: Sun, 17 Jan 2016 16:49:18 +0530 Subject: [PATCH 1/5] Original Source added --- docs/iTunesSD3gen.md | 1 + docs/iTunesStats3gen.md | 1 + 2 files changed, 2 insertions(+) diff --git a/docs/iTunesSD3gen.md b/docs/iTunesSD3gen.md index 913189c..8580603 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..2bc62b6 100644 --- a/docs/iTunesStats3gen.md +++ b/docs/iTunesStats3gen.md @@ -109,3 +109,4 @@ Here's the general layout of an iTunesSD file:

00 00 00 00 +

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

From 54c09fca0248e37d6297eda7d7fcc7618b45f42e Mon Sep 17 00:00:00 2001 From: Nimesh Ghelani Date: Sun, 17 Jan 2016 16:54:22 +0530 Subject: [PATCH 2/5] missing end tags --- docs/iTunesStats3gen.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/iTunesStats3gen.md b/docs/iTunesStats3gen.md index 2bc62b6..bc6816e 100644 --- a/docs/iTunesStats3gen.md +++ b/docs/iTunesStats3gen.md @@ -108,5 +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)

From 395dd597184a0fb594f4f756ca02e497d57a6ece Mon Sep 17 00:00:00 2001 From: Nimesh Ghelani Date: Sun, 17 Jan 2016 17:14:46 +0530 Subject: [PATCH 3/5] directory permission check, non zero return status --- shuffle.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/shuffle.py b/shuffle.py index e1fa0e9..e8870f9 100755 --- a/shuffle.py +++ b/shuffle.py @@ -547,6 +547,15 @@ 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) + if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('--disable-voiceover', action='store_true', help='Disable Voiceover Feature') @@ -555,9 +564,7 @@ if __name__ == '__main__': parser.add_argument('path') 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) From fd80fdb221a8ef1b189ef9cab0ea355ed75fc7b0 Mon Sep 17 00:00:00 2001 From: Nimesh Ghelani Date: Sat, 23 Jan 2016 22:25:59 +0530 Subject: [PATCH 4/5] handle keyboard interrupt --- shuffle.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/shuffle.py b/shuffle.py index e8870f9..1caca0f 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") @@ -556,7 +557,12 @@ def checkPathValidity(path): 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') From e02ef0fff658990238625c10bb0150be4d60e3a0 Mon Sep 17 00:00:00 2001 From: Nimesh Ghelani Date: Sat, 23 Jan 2016 23:02:19 +0530 Subject: [PATCH 5/5] Safe file handling, closes #18 --- shuffle.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/shuffle.py b/shuffle.py index 1caca0f..20e73f4 100755 --- a/shuffle.py +++ b/shuffle.py @@ -420,9 +420,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': @@ -505,9 +504,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