Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import plistlib | ||
import sys | ||
import os | ||
import urllib | ||
import re | ||
|
||
stripper = re.compile("^file://localhost(.*)") | ||
|
||
#file://localhost/Volumes/ntfs/Music/Music/Apple%20Computer/Developer%20Helper%20Volume%201-%20Phi/07%20Breaking%20Through.mp3 | ||
|
||
if len(sys.argv) < 3: | ||
print "Usage: itunes_diff.py iTunes\ Music\ Library.xml /path/to/itunesdir [--ignore-dotfiles]" | ||
sys.exit() | ||
|
||
ignore_dotfiles = False | ||
try: | ||
if sys.argv[3] == "--ignore-dotfiles": | ||
ignore_dotfiles = True | ||
except IndexError: | ||
pass | ||
|
||
countdict = plistlib.readPlist(sys.argv[1]) | ||
|
||
walker = os.walk(sys.argv[2]) | ||
|
||
hard_drive_paths = set() | ||
itunes_library_paths = set() | ||
|
||
for directory in walker: | ||
for filename in directory[2]: | ||
hard_drive_paths.add(os.path.join(directory[0], filename)) | ||
|
||
for track in countdict["Tracks"].iteritems(): | ||
if "Location" in track[1]: | ||
unquoted = urllib.unquote(track[1]["Location"]) | ||
match = stripper.search(unquoted) | ||
if match: | ||
itunes_library_paths.add(match.group(1)) | ||
|
||
hd_only = hard_drive_paths - itunes_library_paths | ||
|
||
for x in hd_only: | ||
if not ignore_dotfiles: | ||
print x | ||
else: | ||
if not os.path.basename(x).startswith('.'): | ||
print x | ||
|
||
#hopefully there aren't any newlines in your mp3 file names! | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/usr/bin/env python | ||
import re | ||
import fileinput | ||
import sys, os | ||
|
||
cheatsheet = """You need two args! | ||
pysed.py: regex replacement [file1, file2...] | ||
*: match 0 or more | ||
+: match 1 or more | ||
?: match 0 or 1 | ||
*?, +?, ??: non-greedy matching | ||
\d , \D: any digit, any not digit | ||
\s , \S: any whitespace, any not whitespace | ||
\w , \W: any number, letter or _, any not number, letter or _ | ||
{n}: match n repetitions | ||
{m,n}: match m to n repetitions | ||
(?iLmsux): one or more chars from set adjust group matching. | ||
i: ignore case | ||
L: locale dependent | ||
m: does not do what you might expect | ||
s: . also matches newlines | ||
u: unicode dependent | ||
x: ignore spaces except when escaped, comments after # | ||
(?:): group can't be backreferenced | ||
(?P<foo>): you can backreference group with \gfoo in substitution or (?P=foo) in regex | ||
(?(backref)regex|regex): ternary if backref exists""" | ||
|
||
if len(sys.argv) < 3: | ||
print >> sys.stderr, cheatsheet | ||
sys.exit() | ||
|
||
regex = re.compile(sys.argv[1]) | ||
replacement = sys.argv[2] | ||
|
||
sedfiles = [] | ||
if len(sys.argv) > 3: | ||
for sedfile in sys.argv[3:]: | ||
if os.path.isfile(sedfile): | ||
sedfiles.append(sedfile) | ||
|
||
for line in fileinput.input(sedfiles): | ||
sys.stdout.write(re.sub(regex, replacement, line)) |