From 4bd3e98a2dd2813f2c54bd001d6da6d6d562d33a Mon Sep 17 00:00:00 2001 From: Remy Date: Tue, 24 May 2011 03:26:57 -0700 Subject: [PATCH] pyItunes --- pyItunes/Library.py | 41 ++++++++++++++++++++++++++++++ pyItunes/Library.pyc | Bin 0 -> 1990 bytes pyItunes/Song.py | 46 ++++++++++++++++++++++++++++++++++ pyItunes/Song.pyc | Bin 0 -> 1236 bytes pyItunes/XMLLibraryParser.py | 42 +++++++++++++++++++++++++++++++ pyItunes/XMLLibraryParser.pyc | Bin 0 -> 2010 bytes pyItunes/__init__.py | 3 +++ pyItunes/__init__.pyc | Bin 0 -> 305 bytes 8 files changed, 132 insertions(+) create mode 100644 pyItunes/Library.py create mode 100644 pyItunes/Library.pyc create mode 100644 pyItunes/Song.py create mode 100644 pyItunes/Song.pyc create mode 100644 pyItunes/XMLLibraryParser.py create mode 100644 pyItunes/XMLLibraryParser.pyc create mode 100644 pyItunes/__init__.py create mode 100644 pyItunes/__init__.pyc diff --git a/pyItunes/Library.py b/pyItunes/Library.py new file mode 100644 index 00000000..460a1519 --- /dev/null +++ b/pyItunes/Library.py @@ -0,0 +1,41 @@ +from pyItunes.Song import Song +import time +class Library: + def __init__(self,dictionary): + self.songs = self.parseDictionary(dictionary) + + def parseDictionary(self,dictionary): + songs = [] + format = "%Y-%m-%dT%H:%M:%SZ" + for song,attributes in dictionary.iteritems(): + s = Song() + s.name = attributes.get('Name') + s.artist = attributes.get('Artist') + s.album_artist = attributes.get('Album Aritst') + s.composer = attributes.get('Composer') + s.album = attributes.get('Album') + s.genre = attributes.get('Genre') + s.kind = attributes.get('Kind') + if attributes.get('Size'): + s.size = int(attributes.get('Size')) + s.total_time = attributes.get('Total Time') + s.track_number = attributes.get('Track Number') + if attributes.get('Year'): + s.year = int(attributes.get('Year')) + if attributes.get('Date Modified'): + s.date_modified = time.strptime(attributes.get('Date Modified'),format) + if attributes.get('Date Added'): + s.date_added = time.strptime(attributes.get('Date Added'),format) + if attributes.get('Bit Rate'): + s.bit_rate = int(attributes.get('Bit Rate')) + if attributes.get('Sample Rate'): + s.sample_rate = int(attributes.get('Sample Rate')) + s.comments = attributes.get("Comments ") + if attributes.get('Rating'): + s.rating = int(attributes.get('Rating')) + if attributes.get('Play Count'): + s.play_count = int(attributes.get('Play Count')) + if attributes.get('Location'): + s.location = attributes.get('Location') + songs.append(s) + return songs \ No newline at end of file diff --git a/pyItunes/Library.pyc b/pyItunes/Library.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b8a8ca118591c3d3b67e3bba6ec4bab7d0f396fc GIT binary patch literal 1990 zcma)7U2hvj6uqleB@NN?4UF`K9dxZxupK6HyS2h1QW!BG78>ous39KiC;p z7$r~Tg`dYW|AIdN=ic3Mj0_0dJDz*y+^@4cv%me(+j;Zu_p=$*pBDaK;j*7$Nbpm1 zLo`=(sYtOM&`m&>0VNGeT9h>D7orbD7niUDnvB};Gk@YUQkc0WhDn}XkKGn#Z_Tuf z%jGH?Q(oh;pJ33$Nst2(If0T%gTl!u!19a-f1R+?5r$i2!>H(k;&~(iCX#zBZf*~( zA}*~yH8W@O4EY^*X;GD}C|sn~^DDQ5NwT7iV37>=5VKuxT)cPwHu8HoXue%2Q^gck*C>`3J{_rmNKA^iM-L=S}74X`0+ad#Y zAf2@-YIvmKk)}tQ9%*@`<&jmKwnw%+XUiko9@+Lt$0Hp^@+YJqOMn@QnLn;r z0hz~K34GO$kLkNx-lUK4SdQ%h#^J@YVft*CoDaWxIXrtgoLtJ59mlD5yp@kjXRNbb zp3bL>bZ}f6XPrFwCwW@rR+qA!WL0KwbXIDK@{P%o>I5)9Ys;JKJa_SYaBfm9A?hGdH~H}uXFxy=kaoIk}tBVgSYt%Yk4-}^T)BLaT*Qk)P^v~H85OjC$(i>lUOuy ztVzt8L^Z%=&DJ%MRng>nrO6Fz!eI?+kRt=y$id@So5(>M3GG;$D7)8Y32nqfD4fi? zvJit6OCUy+){0dp86z<(Cbw&fL#hPiSTQS#Rd!vsC?@&Q5LMDPZJY+$@)3?X8V+!0fPr2*J&;4ggErO@Eki;+2u6Fl%-`aovjiamYe?KSU{&T?pANg_w@=v zF^><~M;_+ZtlH2X8!q{BzZtX;i=I!g==%hVL*Nl`06Yes0EfT`I0Bvm$G}Ix$G|h- zIq(Ab1o#yA4EP*45jXR=@A-@vqoLqZ2pjH3 z%{L(F7~9k)y!LbMg~q}krvY0w!$Kp!3}b?%&4AER~)&jYA8`VCbCP#}q*-tgb literal 0 HcmV?d00001 diff --git a/pyItunes/XMLLibraryParser.py b/pyItunes/XMLLibraryParser.py new file mode 100644 index 00000000..7e4b239a --- /dev/null +++ b/pyItunes/XMLLibraryParser.py @@ -0,0 +1,42 @@ +import re +class XMLLibraryParser: + def __init__(self,xmlLibrary): + f = open(xmlLibrary) + s = f.read() + lines = s.split("\n") + self.dictionary = self.parser(lines) + + def getValue(self,restOfLine): + value = re.sub("<.*?>","",restOfLine) + u = unicode(value,"utf-8") + cleanValue = u.encode("ascii","xmlcharrefreplace") + return cleanValue + + def keyAndRestOfLine(self,line): + rawkey = re.search('(.*?)',line).group(0) + key = re.sub("","",rawkey) + restOfLine = re.sub(".*?","",line).strip() + return key,restOfLine + + def parser(self,lines): + dicts = 0 + songs = {} + inSong = False + for line in lines: + if re.search('',line): + dicts += 1 + if re.search('',line): + dicts -= 1 + inSong = False + songs[songkey] = temp + if dicts == 2 and re.search('(.*?)',line): + rawkey = re.search('(.*?)',line).group(0) + songkey = re.sub("","",rawkey) + inSong = True + temp = {} + if dicts == 3 and re.search('(.*?)',line): + key,restOfLine = self.keyAndRestOfLine(line) + temp[key] = self.getValue(restOfLine) + if len(songs) > 0 and dicts < 2: + return songs + return songs \ No newline at end of file diff --git a/pyItunes/XMLLibraryParser.pyc b/pyItunes/XMLLibraryParser.pyc new file mode 100644 index 0000000000000000000000000000000000000000..79cd2bce121fb05d208bdfb5e47a253e5ded02d5 GIT binary patch literal 2010 zcmb7FTW=dh6h7l??1mItS#1@lka%&c(ugN25Bij*Cb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unes/__init__.py new file mode 100644 index 00000000..bc7acfad --- /dev/null +++ b/pyItunes/__init__.py @@ -0,0 +1,3 @@ +from pyItunes.XMLLibraryParser import XMLLibraryParser +from pyItunes.Library import Library +from pyItunes.Song import Song \ No newline at end of file diff --git a/pyItunes/__init__.pyc b/pyItunes/__init__.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5090244ddebc2c0ca24516a87d3f66a2785eab20 GIT binary patch literal 305 zcmcckiI>YgBq-s=4F<|$LkeTmT&+iY;yBcN^?@}K;{*L+$O*%zz6_|+d?V; literal 0 HcmV?d00001