Esempio n. 1
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()
Esempio n. 2
0
 def _init_blacklist(self):
     """
     Init the Storage location list.
     """
     for file in StorageBlackList.select():
         self.blacklist_model.append([file.path, file.id])
     self.__on_blacklist_selection_changed(None)
Esempio n. 3
0
def is_blacklisted(path):
    """
    Tests whether a given path is blacklisted.
    """
    if StorageBlackList.select().where(
            StorageBlackList.path == path).count() > 0:
        return True
    else:
        return False
Esempio n. 4
0
    def __on_remove_blacklist_clicked(self, widget):
        """
        Remove the selected storage from the db and ui.
        TODO: Does this trigger a rescan?
        """
        model, pathlist = self.blacklist_tree_view.get_selection(
        ).get_selected_rows()
        if pathlist:
            ids = []
            for path in reversed(pathlist):
                treeiter = model.get_iter(path)
                ids.append(self.blacklist_model.get_value(treeiter, 1))
                self.blacklist_model.remove(treeiter)

            StorageBlackList.delete().where(
                StorageBlackList.id in ids).execute()

        self.__on_blacklist_selection_changed(
            self.blacklist_tree_view.get_selection())
Esempio n. 5
0
def rebase_location(ui, oldPath, newPath):
    """
    This gets called when a user changes the location of the audio book folder.
    Every file in the database updated with the new path.
    Note: This does not check for the existence of those files.
    """
    trackCount = Track.select().count()
    currentTrackCount = 0
    for track in Track.select():
        newFilePath = track.file.replace(oldPath, newPath)
        Track.update(file=newFilePath).where(Track.id == track.id).execute()
        StorageBlackList.update(path=newFilePath).where(
            StorageBlackList.path == track.file).execute()
        Gdk.threads_add_idle(GLib.PRIORITY_DEFAULT_IDLE,
                             ui.titlebar.update_progress_bar.set_fraction,
                             currentTrackCount / trackCount)
        currentTrackCount = currentTrackCount + 1

    Gdk.threads_add_idle(GLib.PRIORITY_DEFAULT_IDLE, ui.switch_to_playing)