def organize_single_entry(self, entry): """We're needed because RhythmDB doesn't support the iteration protocol.""" s = _EscapedRDBEntry(self.rdb, entry) uri = entry.get_playback_uri() if not uri or not uri.startswith("file://"): return src = unquote_url( uri.partition("://")[2] ) dst = os.path.join(rb.music_dir(), self.new_path.format(s)) try: if src != dst: print("%s -> %s" % (src, dst)) super_rename(src, dst) except OSError as err: print( str(err) )
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])