Ejemplo n.º 1
0
def get_wavefile_location_for_uri(uri):
    """
    Compute the URI where the pickled wave file should be stored
    """
    filename = hash_file(Gst.uri_get_location(uri)) + ".wave"
    cache_dir = get_dir(os.path.join(xdg_cache_home(), "waves"))

    return os.path.join(cache_dir, filename)
 def __load_from_cache(self, filename):
     filename = hash_file(filename) + '.analysis'
     cache_dir = get_dir(os.path.join(xdg_cache_home(), "echonest"))
     filename = os.path.join(cache_dir, filename)
     try:
         with open(filename, 'rb') as f:
             return pickle.load(f)
     except IOError:
         return None
Ejemplo n.º 3
0
 def __init__(self, uri):
     Loggable.__init__(self)
     self._filehash = hash_file(Gst.uri_get_location(uri))
     thumbs_cache_dir = get_dir(os.path.join(xdg_cache_home(), "thumbs"))
     self._dbfile = os.path.join(thumbs_cache_dir, self._filehash)
     self._db = sqlite3.connect(self._dbfile)
     self._cur = self._db.cursor()  # Use this for normal db operations
     self._cur.execute("CREATE TABLE IF NOT EXISTS Thumbs\
                       (Time INTEGER NOT NULL PRIMARY KEY,\
                       Jpeg BLOB NOT NULL)")
Ejemplo n.º 4
0
 def __init__(self, uri):
     Loggable.__init__(self)
     self._filehash = hash_file(Gst.uri_get_location(uri))
     thumbs_cache_dir = get_dir(os.path.join(xdg_cache_home(), "thumbs"))
     self._dbfile = os.path.join(thumbs_cache_dir, self._filehash)
     self._db = sqlite3.connect(self._dbfile)
     self._cur = self._db.cursor()  # Use this for normal db operations
     self._cur.execute("CREATE TABLE IF NOT EXISTS Thumbs\
                       (Time INTEGER NOT NULL PRIMARY KEY,\
                       Jpeg BLOB NOT NULL)")
Ejemplo n.º 5
0
    def copy(self, uri):
        """Copies `self` to the specified `uri`.

        Args:
            uri (str): The place where to copy/save the ThumbnailCache
        """
        filehash = hash_file(Gst.uri_get_location(uri))
        thumbs_cache_dir = get_dir(os.path.join(xdg_cache_home(), "thumbs"))
        dbfile = os.path.join(thumbs_cache_dir, filehash)

        os.symlink(self._dbfile, dbfile)
Ejemplo n.º 6
0
    def copy(self, uri):
        """Copies `self` to the specified `uri`.

        Args:
            uri (str): The place where to copy/save the ThumbnailCache
        """
        filehash = hash_file(Gst.uri_get_location(uri))
        thumbs_cache_dir = get_dir(os.path.join(xdg_cache_home(), "thumbs"))
        dbfile = os.path.join(thumbs_cache_dir, filehash)

        os.symlink(self._dbfile, dbfile)
Ejemplo n.º 7
0
    def _startLevelsDiscovery(self):
        self.log('Preparing waveforms for "%s"' % filename_from_uri(self._uri))
        filename = hash_file(Gst.uri_get_location(self._uri)) + ".wave"
        cache_dir = get_dir(os.path.join(xdg_cache_home(), "waves"))
        filename = cache_dir + "/" + filename

        if os.path.exists(filename):
            self.samples = pickle.load(open(filename, "rb"))
            self._startRendering()
        else:
            self.wavefile = filename
            self._launchPipeline()
Ejemplo n.º 8
0
    def _startLevelsDiscovery(self):
        self.log('Preparing waveforms for "%s"' % filename_from_uri(self._uri))
        filename = hash_file(Gst.uri_get_location(self._uri)) + ".wave"
        cache_dir = get_dir(os.path.join(xdg_cache_home(), "waves"))
        filename = cache_dir + "/" + filename

        if os.path.exists(filename):
            self.samples = pickle.load(open(filename, "rb"))
            self._startRendering()
        else:
            self.wavefile = filename
            self._launchPipeline()
Ejemplo n.º 9
0
 def __init__(self, uri):
     Loggable.__init__(self)
     self._filehash = hash_file(Gst.uri_get_location(uri))
     thumbs_cache_dir = get_dir(os.path.join(xdg_cache_home(), "thumbs"))
     self._dbfile = os.path.join(thumbs_cache_dir, self._filehash)
     self._db = sqlite3.connect(self._dbfile)
     self._cur = self._db.cursor()
     self._cur.execute("CREATE TABLE IF NOT EXISTS Thumbs "
                       "(Time INTEGER NOT NULL PRIMARY KEY, "
                       " Jpeg BLOB NOT NULL)")
     # The cached (width, height) of the images.
     self._image_size = (0, 0)
     # The cached positions available in the database.
     self.positions = self.__existing_positions()
     # The ID of the autosave event.
     self.__autosave_id = None
    def __init__(self, track, darea, clip_filename):
        filename = hash_file(clip_filename) + ".wave"
        cache_dir = get_dir(os.path.join(xdg_cache_home(), "waves"))
        filename = os.path.join(cache_dir, filename)

        self.darea = darea

        try:
            with open(filename, "rb") as samples:
                self.__peaks = pickle.load(samples)
        except IOError:
            print ("THERE SHOULD BE A WAVEFORM YOU SHOULD HAVE WAITED")
            self.__peaks = [42.22]

        self.__nb_peaks = len(self.__peaks)
        self.__max_peak = max(self.__peaks)
        self.__track = track
        self.__surface = None
        self.__markers = []
        self.selected_section = None
        self.position = 0.0

        darea.connect('draw', self.draw_cb)
Ejemplo n.º 11
0
def get_wavefile_location_for_uri(uri):
    """Computes the URI where the wave.npy file should be stored."""
    filename = hash_file(Gst.uri_get_location(uri)) + ".wave.npy"
    cache_dir = get_dir(os.path.join(xdg_cache_home(), "waves"))

    return os.path.join(cache_dir, filename)
Ejemplo n.º 12
0
 def setUp(self):
     self.tmpfile = tempfile.NamedTemporaryFile()
     self.uri = unquote(Gst.uri_construct("file", self.tmpfile.name))
     self.hash = hash_file(self.tmpfile.name)
 def __save_to_cache(self, filename, track):
     filename = hash_file(filename) + '.analysis'
     cache_dir = get_dir(os.path.join(xdg_cache_home(), "echonest"))
     filename = os.path.join(cache_dir, filename)
     with open(filename, 'wb') as f:
         pickle.dump(track, f)
Ejemplo n.º 14
0
def get_wavefile_location_for_uri(uri):
    filename = hash_file(Gst.uri_get_location(uri)) + ".wave"
    cache_dir = get_dir(os.path.join(xdg_cache_home(), "waves"))

    return os.path.join(cache_dir, filename)
Ejemplo n.º 15
0
    def copy(self, uri):
        filehash = hash_file(Gst.uri_get_location(uri))
        thumbs_cache_dir = get_dir(os.path.join(xdg_cache_home(), "thumbs"))
        dbfile = os.path.join(thumbs_cache_dir, filehash)

        os.symlink(self._dbfile, dbfile)
Ejemplo n.º 16
0
 def setUp(self):
     self.tmpfile = tempfile.NamedTemporaryFile()
     self.uri = unquote(Gst.uri_construct("file", self.tmpfile.name))
     self.hash = hash_file(self.tmpfile.name)