From: <gea...@us...> - 2009-01-27 13:55:12
|
Revision: 319 http://mypyspace.svn.sourceforge.net/mypyspace/?rev=319&view=rev Author: gearmonkey Date: 2009-01-27 13:55:06 +0000 (Tue, 27 Jan 2009) Log Message: ----------- fixed the image url problem, now actually point to song images not myspace default filler images. added a bit more inline documentation to the api examples code. Modified Paths: -------------- myspaceCrawler/trunk/examples.py myspaceCrawler/trunk/mpsUser.py Modified: myspaceCrawler/trunk/examples.py =================================================================== --- myspaceCrawler/trunk/examples.py 2009-01-27 12:43:42 UTC (rev 318) +++ myspaceCrawler/trunk/examples.py 2009-01-27 13:55:06 UTC (rev 319) @@ -6,7 +6,7 @@ some simple functions demonstrating mpsUser and mpsSong functionality Created by Benjamin Fields on 2008-11-09. -Copyright (c) 2008 __MyCompanyName__. All rights reserved. +Copyright (c) 2008 Goldsmiths. All rights reserved. """ import sys @@ -36,7 +36,7 @@ return 0 def socialCharts(initArtist, radius, chartLength=1): - '''breadth first crawl of width radius to find most chartLength popular songs from the center initArtist.''' + '''breadth first crawl of width radius to find at most chartLength popular songs from the center initArtist.''' songQueue = [] visitedArtists = [] artistsInThisLevel = [initArtist] Modified: myspaceCrawler/trunk/mpsUser.py =================================================================== --- myspaceCrawler/trunk/mpsUser.py 2009-01-27 12:43:42 UTC (rev 318) +++ myspaceCrawler/trunk/mpsUser.py 2009-01-27 13:55:06 UTC (rev 319) @@ -46,11 +46,13 @@ isArtist -- Boolean, True means instance describes a MySpace artist with media rdfprefix -- prefix for all rdf UIRs page -- locally loaded copy of html pointed to by source + The following are only set if user is found to be an artist mediaXML -- locally loaded (via miniDom) copy of xml describing playlist of media assciated - with myspace Artist (not set in non artists) + with myspace Artist totalPlays -- sum of playcounts of all songs associated with myspace Artist - (not set in non Artist) - artist -- self declared name of artist (not set in non Artist) + artist -- self declared name of artist + artistID -- unique ID possessed by artists only, needed to retrieve media and media related meta data + playlistID -- unique ID used to retrieve playlist found on page ''' @@ -342,7 +344,7 @@ else: self.extractionprefix = extractionprefix self.title = self.exhaustiveXML.getElementsByTagName('title')[0].firstChild.nodeValue - self.image = self.exhaustiveXML.getElementsByTagName('small')[0].firstChild.nodeValue + self.getimage() self.playcount = xmlNode.getElementsByTagName('stats')[0].getAttribute('plays') self.comments = "" #this is a blank string hold for the comments fields. Might be used later. self.trackNum, self.totalTracks = None, None @@ -357,10 +359,31 @@ try: self.uri = self.exhaustiveXML.getElementsByTagName('link')[0].firstChild.nodeValue except AttributeError, err: - logging.info("mpsUser::getUri ran into a problem finding the download link for a song by artist with uid: " + + logging.info("mpsUser::mpsSong::getUri ran into a problem finding the download link for a song by artist with uid: " + str(self.parent().uid) + " link will be left blank.\n\tError msg: " + str(err)) self.uri = '' - + def getimage(self): + '''find an image associated with the song, getting the largest resolution available''' + try: + self.image = self.exhaustiveXML.getElementsByTagName('track')[0].getElementsByTagName('large')[0].firstChild.nodeValue + except AttributeError: + try: + self.image = self.exhaustiveXML.getElementsByTagName('track')[0].getElementsByTagName('medium')[0].firstChild.nodeValue + except AttributeError: + try: + self.image = self.exhaustiveXML.getElementsByTagName('track')[0].getElementsByTagName('small')[0].firstChild.nodeValue + except Exception, err: + logging.info("mpsUser::mpsSong::getimage ran into a problem finding an image for a song by artist with uid: " + + str(self.parent().uid) + " image will be left blank.\n\tError msg: " + str(err)) + self.image = '' + except Exception, err: + logging.info("mpsUser::mpsSong::getimage ran into a problem finding an image for a song by artist with uid: " + + str(self.parent().uid) + " image will be left blank.\n\tError msg: " + str(err)) + self.image = '' + except Exception, err: + logging.info("mpsUser::mpsSong::getimage ran into a problem finding an image for a song by artist with uid: " + + str(self.parent().uid) + " image will be left blank.\n\tError msg: " + str(err)) + self.image = '' def setTrackNum(self, trackNumber, totalTracks): '''set the track number for this song and the number of tracks in the album it is in.''' self.trackNum = trackNumber This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |