def get_meta_data(lmaid): """Get the _meta.xml file with the concert description.""" # relative path is concertid/concertid_meta.xml reader = MetaXMLHandler() hand = lma.archive_open("%s/%s_meta.xml" % (lmaid, lmaid)) try: xml.sax.parse(hand, reader) finally: hand.close() return reader.getData()
def get_filelist_data(lmaid): """Get the _files.xml file with the song listing.""" # relative path is concertid/concertid_files.xml reader = FileXMLHandler() hand = lma.archive_open("%s/%s_files.xml" % (lmaid, lmaid)) try: xml.sax.parse(hand, reader) finally: hand.close() return reader.getData()
def download_one_file(concert, song, targetdir, progress_bar): """Download one file, updating callback as necessary.""" # if there's an extra subdirectory, create it filename = os.path.join(targetdir, os.path.normpath(song['name'])) (head, tail) = os.path.split(filename) if not os.path.isdir(head): os.mkdir(head) # make sure we don't already have this one filesize = int(song['size']) if os.path.exists(filename): # it's there--is it the right size? if os.stat(filename).st_size == filesize: return True # not right size, just remove it os.remove(filename) # don't use os.path.join here, because the name is for remote system downloaded = 0 chksum = hashlib.md5() path = "%s/%s" % (concert.lmaid, song['name']) rhand = lma.archive_open(path) lhand = open(filename, "wb") try: data = rhand.read(BUFFER_SIZE) while len(data) > 0: downloaded += len(data) lhand.write(data) chksum.update(data) if not progress_bar.update(downloaded): break data = rhand.read(BUFFER_SIZE) except IOError: # nothing really to do, but we want to catch this anyway. pass finally: lhand.close() rhand.close() # now, make sure our checksum matches if chksum.hexdigest() == song['md5']: return True # we failed, remove the partial download os.remove(filename) return False