Exemplo n.º 1
0
    def add_book(self, book: Book):
        book_tracks = [
            TrackModel.get_by_id(chapter.id) for chapter in book.chapters
        ]

        data = list((t.file, ) for t in book_tracks)
        chunks = [data[x:x + 500] for x in range(0, len(data), 500)]
        for chunk in chunks:
            StorageBlackList.insert_many(chunk, fields=[StorageBlackList.path
                                                        ]).execute()
Exemplo n.º 2
0
def blacklist_book(book):
    """
    Removes a book from the library and adds the path(s) to the track list.
    """
    book_tracks = get_tracks(book)
    data = list((t.file, ) for t in book_tracks)
    chunks = [data[x:x + 500] for x in range(0, len(data), 500)]
    for chunk in chunks:
        StorageBlackList.insert_many(chunk,
                                     fields=[StorageBlackList.path]).execute()
    ids = list(t.id for t in book_tracks)
    Track.delete().where(Track.id << ids).execute()
    book.delete_instance()
Exemplo n.º 3
0
 def blacklist(self):
     with self._db:
         book_tracks = [
             TrackModel.get_by_id(chapter.id) for chapter in self._chapters
         ]
         data = list((t.file, ) for t in book_tracks)
         chunks = [data[x:x + 500] for x in range(0, len(data), 500)]
         for chunk in chunks:
             StorageBlackList.insert_many(chunk,
                                          fields=[StorageBlackList.path
                                                  ]).execute()
         ids = list(t.id for t in book_tracks)
         TrackModel.delete().where(TrackModel.id << ids).execute()
         self._db_object.delete_instance()
Exemplo n.º 4
0
Arquivo: book.py Projeto: foliva/cozy
    def remove(self):
        if self._settings.last_played_book and self._settings.last_played_book.id == self._db_object.id:
            self._settings.last_played_book = None

        book_tracks = [
            TrackModel.get_by_id(chapter.id) for chapter in self.chapters
        ]
        data = list((t.file, ) for t in book_tracks)
        chunks = [data[x:x + 500] for x in range(0, len(data), 500)]
        for chunk in chunks:
            StorageBlackList.insert_many(chunk, fields=[StorageBlackList.path
                                                        ]).execute()
        ids = list(t.id for t in book_tracks)
        TrackModel.delete().where(TrackModel.id << ids).execute()
        self._db_object.delete_instance(recursive=True)