Пример #1
0
    def _setScenarioFile(self, uri):
        if 'PITIVI_SCENARIO_FILE' in os.environ:
            uri = quote_uri(os.environ['PITIVI_SCENARIO_FILE'])
        else:
            cache_dir = get_dir(os.path.join(xdg_cache_home(), "scenarios"))
            scenario_name = str(time.strftime("%Y%m%d-%H%M%S"))
            project_path = None
            if uri:
                project_path = path_from_uri(uri)
                scenario_name += os.path.splitext(
                    project_path.replace(os.sep, "_"))[0]

            uri = os.path.join(cache_dir, scenario_name + ".scenario")
            uri = quote_uri(uri)

        self._scenario_file = open(path_from_uri(uri), "w")

        if project_path:
            f = open(project_path)
            content = f.read()
            if not uri.endswith(".scenario"):
                self.write_action(
                    "load-project",
                    {"serialized-content": "%s" % content.replace("\n", "")})
            f.close()
Пример #2
0
    def _setScenarioFile(self, uri):
        if uri:
            project_path = path_from_uri(uri)
        else:
            # New project.
            project_path = None
        if 'PITIVI_SCENARIO_FILE' in os.environ:
            scenario_path = os.environ['PITIVI_SCENARIO_FILE']
        else:
            cache_dir = get_dir(os.path.join(xdg_cache_home(), "scenarios"))
            scenario_name = str(time.strftime("%Y%m%d-%H%M%S"))
            if project_path:
                scenario_name += os.path.splitext(
                    project_path.replace(os.sep, "_"))[0]
            scenario_path = os.path.join(cache_dir,
                                         scenario_name + ".scenario")

        scenario_path = path_from_uri(quote_uri(scenario_path))
        self._scenario_file = open(scenario_path, "w")

        if project_path and not project_path.endswith(".scenario"):
            # It's an xges file probably.
            with open(project_path) as project:
                content = project.read().replace("\n", "")
                self.write_action("load-project", serialized_content=content)
Пример #3
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
Пример #5
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)")
Пример #6
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)")
Пример #7
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)
Пример #8
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)
Пример #9
0
 def __init__(self, uri, size=100):
     object.__init__(self)
     self.hash = utils.misc.hash_file(gst.uri_get_location(uri))
     self.cache = {}
     self.queue = collections.deque()
     dbfile = os.path.join(settings.get_dir(os.path.join(settings.xdg_cache_home(), "thumbs")), self.hash)
     self.conn = sqlite3.connect(dbfile)
     self.cur = self.conn.cursor()
     self.cur.execute("CREATE TABLE IF NOT EXISTS Thumbs (Time INTEGER NOT NULL PRIMARY KEY,\
         Data BLOB NOT NULL, Width INTEGER NOT NULL, Height INTEGER NOT NULL)")
     self.size = size
Пример #10
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()
Пример #11
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()
Пример #12
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)
Пример #14
0
    def _setScenarioFile(self, uri):
        if 'PITIVI_SCENARIO_FILE' in os.environ:
            uri = quote_uri(os.environ['PITIVI_SCENARIO_FILE'])
        else:
            cache_dir = get_dir(os.path.join(xdg_cache_home(), "scenarios"))
            scenario_name = str(time.strftime("%Y%m%d-%H%M%S"))
            project_path = None
            if uri:
                project_path = path_from_uri(uri)
                scenario_name += os.path.splitext(project_path.replace(os.sep, "_"))[0]

            uri = os.path.join(cache_dir, scenario_name + ".scenario")
            uri = quote_uri(uri)

        self._scenario_file = open(path_from_uri(uri), "w")

        if project_path:
            f = open(project_path)
            content = f.read()
            self.write_action("load-project",
                              {"serialized-content":
                               "%s" % content.replace("\n", "")})
            f.close()
Пример #15
0
    def _setScenarioFile(self, uri):
        if uri:
            project_path = path_from_uri(uri)
        else:
            # New project.
            project_path = None
        if 'PITIVI_SCENARIO_FILE' in os.environ:
            scenario_path = os.environ['PITIVI_SCENARIO_FILE']
        else:
            cache_dir = get_dir(os.path.join(xdg_cache_home(), "scenarios"))
            scenario_name = str(time.strftime("%Y%m%d-%H%M%S"))
            if project_path:
                scenario_name += os.path.splitext(project_path.replace(os.sep, "_"))[0]
            scenario_path = os.path.join(cache_dir, scenario_name + ".scenario")

        scenario_path = path_from_uri(quote_uri(scenario_path))
        self._scenario_file = open(scenario_path, "w")

        if project_path and not project_path.endswith(".scenario"):
            # It's an xges file probably.
            with open(project_path) as project:
                content = project.read().replace("\n", "")
                self.write_action("load-project",
                                  serialized_content=content)
Пример #16
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)
Пример #17
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)
 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)
Пример #19
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)