예제 #1
0
    def remove(self, book):
        """
        Remove all tracks of the given book from the cache.
        """
        #self._stop_processing()
        tracks = get_tracks(book)
        ids = [t.id for t in tracks]
        offline_elements = OfflineCacheModel.select().where(
            OfflineCacheModel.track << ids)

        for element in offline_elements:
            file_path = os.path.join(self.cache_dir, element.file)
            if file_path == self.cache_dir:
                continue

            file = Gio.File.new_for_path(file_path)
            if file.query_exists():
                file.delete()

            for item in self.queue:
                if self.current and item.id == self.current.id:
                    self.filecopy_cancel.cancel()

        OfflineCacheModel.delete().where(
            OfflineCacheModel.track in ids).execute()

        if len(self.queue) > 0:
            self._start_processing()
예제 #2
0
 def update_cache(self, paths):
     """
     Update the cached version of the given files.
     """
     if OfflineCacheModel.select().count() > 0:
         OfflineCacheModel.update(copied=False).where(
             OfflineCacheModel.track.file in paths).execute()
         self._fill_queue_from_db()
예제 #3
0
 def get_cached_path(self, track):
     """
     """
     query = OfflineCacheModel.select().where(
         OfflineCacheModel.track == track.id,
         OfflineCacheModel.copied == True)
     if query.count() > 0:
         return os.path.join(self.cache_dir, query.get().file)
     else:
         return None
예제 #4
0
    def remove_all_for_storage(self, storage_path):
        """
        """
        for element in OfflineCacheModel.select().join(Track).where(
                storage_path in Track.file):
            file_path = os.path.join(self.cache_dir, element.file)
            if file_path == self.cache_dir:
                continue

            file = Gio.File.new_for_path(file_path)
            if file.query_exists():
                file.delete()

            if element.track.book.offline == True:
                element.track.book.update(offline=False,
                                          downloaded=False).execute()

        OfflineCacheModel.delete().where(
            storage_path in OfflineCacheModel.track.file).execute()
예제 #5
0
    def update_book_download_status(self, book):
        """
        Updates the downloaded status of a book.
        """
        downloaded = True
        tracks = get_tracks(book)
        offline_tracks = OfflineCacheModel.select().where(
            OfflineCacheModel.track in tracks)

        if offline_tracks.count() < 1:
            downloaded = False
        else:
            for track in offline_tracks:
                if not track.copied:
                    downloaded = False

        Book.update(downloaded=downloaded).where(Book.id == book.id).execute()
        if downloaded:
            self.emit_event("book-offline", book)
        else:
            self.emit_event("book-offline-removed", book)
예제 #6
0
 def _fill_queue_from_db(self):
     for item in OfflineCacheModel.select().where(
             OfflineCacheModel.copied == False):
         if not any(item.id == queued.id for queued in self.queue):
             self.queue.append(item)
             self.total_batch_count += 1