def unzip_album(): # just use the first library location library_location = gio.File(uri=self.__client.get_list("/apps/rhythmbox/library_locations", gconf.VALUE_STRING)[0]) album = zipfile.ZipFile(dest.get_path()) for track in album.namelist(): track_uri = library_location.resolve_relative_path(track).get_uri() track_uri = rb.sanitize_uri_for_filesystem(track_uri) rb.uri_create_parent_dirs(track_uri) track_out = gio.File(uri=track_uri).create() if track_out is not None: track_out.write(album.read(track)) track_out.close() self.__db.add_uri(track_uri) album.close() remove_download_files()
def unzip_album(): # just use the first library location library_location = gio.File(uri=self.__client.get_list( "/apps/rhythmbox/library_locations", gconf.VALUE_STRING)[0]) album = zipfile.ZipFile(dest.get_path()) for track in album.namelist(): track_uri = library_location.resolve_relative_path( track).get_uri() track_uri = rb.sanitize_uri_for_filesystem(track_uri) rb.uri_create_parent_dirs(track_uri) track_out = gio.File(uri=track_uri).create() if track_out is not None: track_out.write(album.read(track)) track_out.close() self.__db.add_uri(track_uri) album.close() remove_download_files()
def __download_finished (self, total, audio_dl_uri, dest, out): try: del self.__downloads[audio_dl_uri] except: return 0 out.close() self.purchase_filesize -= total # just use the first library location # not quite prepared to use gio here directly yet, so we can only deal with # local libraries here. library_location = self.__client.get_list("/apps/rhythmbox/library_locations", gconf.VALUE_STRING)[0] if library_location.startswith("file://"): urlpath = urlparse.urlparse(library_location).path library_dir = urllib.url2pathname(urlpath) else: library_dir = rb.music_dir () album = zipfile.ZipFile(dest) for track in album.namelist(): track_uri = "file://" + urllib.pathname2url(os.path.join(library_dir, track)) track_uri = rb.sanitize_uri_for_filesystem(track_uri) rb.uri_create_parent_dirs(track_uri) track_path = urllib.url2pathname(urlparse.urlparse(track_uri).path) track_out = open(track_path, 'w') track_out.write(album.read(track)) track_out.close() album.close() self.__remove_download_files (dest) if self.purchase_filesize == 0: self.__downloading = False self.__db.add_uri(os.path.split(track_path)[0])