Esempio n. 1
0
 def __upgrade_18(self, db):
     """
         Upgrade history
     """
     with SqlCursor(History()) as sql:
         sql.execute("ALTER TABLE history ADD loved_album\
                     INT NOT NULL DEFAULT 0")
Esempio n. 2
0
    def __init__(self):
        """
            Init collection scanner
        """
        GObject.GObject.__init__(self)
        TagReader.__init__(self)

        self.__thread = None
        self.__history = History()
        self.__disable_compilations = True
        if App().settings.get_value("auto-update"):
            self.__inotify = Inotify()
        else:
            self.__inotify = None
        App().albums.update_max_count()
        create_dir(self._WEB_COLLECTION)
Esempio n. 3
0
 def __upgrade_19(self, db):
     """
         Upgrade history
     """
     with SqlCursor(History()) as sql:
         try:
             sql.execute("ALTER TABLE history ADD album_rate\
                         INT NOT NULL DEFAULT -1")
             sql.execute("ALTER TABLE history ADD rate\
                         INT NOT NULL DEFAULT -1")
         except:
             pass  # May fails if History was non existent
     with SqlCursor(db, True) as sql:
         sql.execute("ALTER TABLE tracks ADD rate\
                     INT NOT NULL DEFAULT -1")
         sql.execute("ALTER TABLE albums ADD rate\
                     INT NOT NULL DEFAULT -1")
 def _on_confirm_button_clicked(self, button):
     """
         Reset database
         @param button as Gtk.Button
     """
     try:
         App().player.stop(True)
         App().cursors = {}
         uris = App().tracks.get_uris()
         self.__progress.show()
         history = History()
         self.__reset_button.get_toplevel().set_deletable(False)
         self.__reset_button.set_sensitive(False)
         self.__infobar.hide()
         self.__reset_database(uris, len(uris), history)
     except Exception as e:
         Logger.error("SettingsDialog::_on_confirm_button_clicked(): %s" %
                      e)
 def __init__(self):
     """
         Init collection scanner
     """
     GObject.GObject.__init__(self)
     self.__thread = None
     self.__tags = {}
     self.__items = []
     self.__pending_new_artist_ids = []
     self.__history = History()
     self.__progress_total = 1
     self.__progress_count = 0
     self.__progress_fraction = 0
     self.__disable_compilations = not App().settings.get_value(
         "show-compilations")
     if App().settings.get_value("auto-update"):
         self.__inotify = Inotify()
     else:
         self.__inotify = None
     App().albums.update_max_count()
Esempio n. 6
0
 def _on_confirm_button_clicked(self, button):
     """
         Reset database
         @param button as Gtk.Button
     """
     try:
         Lp().player.stop()
         Lp().player.reset_pcn()
         Lp().player.emit("current-changed")
         Lp().player.emit("prev-changed")
         Lp().player.emit("next-changed")
         Lp().cursors = {}
         track_ids = Lp().tracks.get_ids()
         self.__progress.show()
         history = History()
         self.__reset_button.get_toplevel().set_deletable(False)
         self.__reset_button.set_sensitive(False)
         self.__infobar.hide()
         self.__reset_database(track_ids, len(track_ids), history)
     except Exception as e:
         print("Application::_on_confirm_button_clicked():", e)
Esempio n. 7
0
 def __on_reset_clicked(self, widget, progress):
     """
         Reset database
         @param widget as Gtk.Widget
         @param progress as Gtk.ProgressBar
     """
     try:
         Lp().player.stop()
         Lp().player.reset_pcn()
         Lp().player.emit('current-changed')
         Lp().player.emit('prev-changed')
         Lp().player.emit('next-changed')
         Lp().cursors = {}
         track_ids = Lp().tracks.get_ids()
         progress.show()
         history = History()
         widget.get_toplevel().set_deletable(False)
         widget.set_sensitive(False)
         self.___reset_database(track_ids, len(track_ids), history,
                                progress)
     except Exception as e:
         print("Application::_on_reset_clicked():", e)
    def __scan(self, uris, saved):
        """
            Scan music collection for music files
            @param uris as [str]
            @param saved as bool
            @thread safe
        """
        modifications = False
        if self.__history is None:
            self.__history = History()
        mtimes = App().tracks.get_mtimes()
        (new_tracks, new_dirs) = self.__get_objects_for_uris(uris)
        orig_tracks = App().tracks.get_uris()
        was_empty = len(orig_tracks) == 0

        count = len(new_tracks) + len(orig_tracks)
        # Add monitors on dirs
        if self.__inotify is not None:
            for d in new_dirs:
                if d.startswith("file://"):
                    self.__inotify.add_monitor(d)

        i = 0
        # Look for new files/modified file
        SqlCursor.add(App().db)
        try:
            to_add = []
            for uri in new_tracks:
                if self.__thread is None:
                    SqlCursor.remove(App().db)
                    return
                try:
                    GLib.idle_add(self.__update_progress, i, count)
                    f = Gio.File.new_for_uri(uri)
                    # We do not use time::modified because many tag editors
                    # just preserve this setting
                    try:
                        info = f.query_info("time::changed",
                                            Gio.FileQueryInfoFlags.NONE, None)
                        mtime = int(
                            info.get_attribute_as_string("time::changed"))
                    except:  # Fallback for remote fs
                        info = f.query_info("time::modified",
                                            Gio.FileQueryInfoFlags.NONE, None)
                        mtime = int(
                            info.get_attribute_as_string("time::modified"))
                    # If songs exists and mtime unchanged, continue,
                    # else rescan
                    if uri in orig_tracks:
                        orig_tracks.remove(uri)
                        i += 1
                        if not saved or mtime <= mtimes.get(uri, mtime + 1):
                            i += 1
                            continue
                        else:
                            SqlCursor.allow_thread_execution(App().db)
                            self.__del_from_db(uri)
                    # If not saved, use 0 as mtime, easy delete on quit
                    if not saved:
                        mtime = 0
                    # On first scan, use modification time
                    # Else, use current time
                    elif not was_empty:
                        mtime = int(time())
                    to_add.append((uri, mtime))
                except Exception as e:
                    Logger.error("CollectionScanner::__scan(mtime): %s" % e)
            if to_add or orig_tracks:
                modifications = True
            # Clean deleted files
            # Now because we need to populate history
            # Only if we are saving
            if saved:
                for uri in orig_tracks:
                    i += 1
                    GLib.idle_add(self.__update_progress, i, count)
                    self.__del_from_db(uri)
                    SqlCursor.allow_thread_execution(App().db)
            # Add files to db
            for (uri, mtime) in to_add:
                try:
                    Logger.debug("Adding file: %s" % uri)
                    i += 1
                    GLib.idle_add(self.__update_progress, i, count)
                    self.__add2db(uri, mtime)
                    SqlCursor.allow_thread_execution(App().db)
                except Exception as e:
                    Logger.error("CollectionScanner::__scan(add): %s, %s" %
                                 (e, uri))
        except Exception as e:
            Logger.error("CollectionScanner::__scan(): %s" % e)
        SqlCursor.commit(App().db)
        SqlCursor.remove(App().db)
        GLib.idle_add(self.__finish, modifications and saved)
        if not saved:
            self.__play_new_tracks(new_tracks)
        del self.__history
        self.__history = None
Esempio n. 9
0
    def __scan(self, uris):
        """
            Scan music collection for music files
            @param uris as [string], uris to scan
            @thread safe
        """
        gst_message = None
        if self.__history is None:
            self.__history = History()
        mtimes = Lp().tracks.get_mtimes()
        (new_tracks, new_dirs, ignore_dirs) = self.__get_objects_for_uris(
                                                                         uris)
        orig_tracks = Lp().tracks.get_uris(ignore_dirs)
        was_empty = len(orig_tracks) == 0

        if ignore_dirs:
            if Lp().notify is not None:
                Lp().notify.send(_("Lollypop is detecting an empty folder."),
                                 _("Check your music settings."))
        count = len(new_tracks) + len(orig_tracks)
        # Add monitors on dirs
        if self.__inotify is not None:
            for d in new_dirs:
                self.__inotify.add_monitor(d)

        with SqlCursor(Lp().db) as sql:
            i = 0
            # Look for new files/modified files
            try:
                to_add = []
                for uri in new_tracks:
                    if self.__thread is None:
                        return
                    GLib.idle_add(self.__update_progress, i, count)
                    f = Gio.File.new_for_uri(uri)
                    info = f.query_info('time::modified',
                                        Gio.FileQueryInfoFlags.NONE,
                                        None)
                    mtime = int(info.get_attribute_as_string('time::modified'))
                    # If songs exists and mtime unchanged, continue,
                    # else rescan
                    if uri in orig_tracks:
                        orig_tracks.remove(uri)
                        i += 1
                        if mtime <= mtimes[uri]:
                            i += 1
                            continue
                        else:
                            self.__del_from_db(uri)
                    # On first scan, use modification time
                    # Else, use current time
                    if not was_empty:
                        mtime = int(time())
                    to_add.append((uri, mtime))
                # Clean deleted files
                # Now because we need to populate history
                for uri in orig_tracks:
                    i += 1
                    GLib.idle_add(self.__update_progress, i, count)
                    if uri.startswith('file:'):
                        self.__del_from_db(uri)
                # Add files to db
                for (uri, mtime) in to_add:
                    try:
                        debug("Adding file: %s" % uri)
                        i += 1
                        GLib.idle_add(self.__update_progress, i, count)
                        self.__add2db(uri, mtime)
                    except GLib.GError as e:
                        print("CollectionScanner::__scan:", e)
                        if e.message != gst_message:
                            gst_message = e.message
                            if Lp().notify is not None:
                                Lp().notify.send(gst_message)
                sql.commit()
            except Exception as e:
                print("CollectionScanner::__scan()", e)
        GLib.idle_add(self.__finish)
        del self.__history
        self.__history = None
Esempio n. 10
0
    def __scan(self, paths):
        """
            Scan music collection for music files
            @param paths as [string], paths to scan
            @thread safe
        """
        gst_message = None
        if self.__history is None:
            self.__history = History()
        mtimes = Lp().tracks.get_mtimes()
        orig_tracks = Lp().tracks.get_uris()
        was_empty = len(orig_tracks) == 0

        (new_tracks, new_dirs) = self.__get_objects_for_paths(paths)
        count = len(new_tracks) + len(orig_tracks)
        # Add monitors on dirs
        if self.__inotify is not None:
            for d in new_dirs:
                self.__inotify.add_monitor(d)

        with SqlCursor(Lp().db) as sql:
            i = 0
            for uri in new_tracks:
                if self.__thread is None:
                    return
                GLib.idle_add(self.__update_progress, i, count)
                try:
                    f = Gio.File.new_for_uri(uri)
                    info = f.query_info('time::modified',
                                        Gio.FileQueryInfoFlags.NONE, None)
                    mtime = info.get_attribute_as_string('time::modified')
                    # If songs exists and mtime unchanged, continue,
                    # else rescan
                    if uri in orig_tracks:
                        orig_tracks.remove(uri)
                        i += 1
                        if mtime <= mtimes[uri]:
                            i += 1
                            continue
                        else:
                            self.__del_from_db(uri)
                    info = self.get_info(uri)
                    # On first scan, use modification time
                    # Else, use current time
                    if not was_empty:
                        mtime = int(time())
                    debug("Adding file: %s" % uri)
                    self.__add2db(uri, info, mtime)
                except GLib.GError as e:
                    print(e, uri)
                    if e.message != gst_message:
                        gst_message = e.message
                        if Lp().notify is not None:
                            Lp().notify.send(gst_message)
                except:
                    pass
                i += 1

            # Clean deleted files
            for uri in orig_tracks:
                i += 1
                GLib.idle_add(self.__update_progress, i, count)
                if uri.startswith('file:'):
                    self.__del_from_db(uri)

            sql.commit()
        GLib.idle_add(self.__finish)
        del self.__history
        self.__history = None
Esempio n. 11
0
    def _scan(self, paths):
        """
            Scan music collection for music files
            @param paths as [string], paths to scan
            @thread safe
        """
        if self._history is None:
            self._history = History()
        mtimes = Lp().tracks.get_mtimes()
        orig_tracks = Lp().tracks.get_paths()
        was_empty = len(orig_tracks) == 0

        (new_tracks, new_dirs, count) = self._get_objects_for_paths(paths)
        count += len(orig_tracks)

        # Add monitors on dirs
        if self._inotify is not None:
            for d in new_dirs:
                self._inotify.add_monitor(d)

        with SqlCursor(Lp().db) as sql:
            i = 0
            for filepath in new_tracks:
                if self._thread is None:
                    return
                GLib.idle_add(self._update_progress, i, count)
                try:
                    # If songs exists and mtime unchanged, continue,
                    # else rescan
                    if filepath in orig_tracks:
                        orig_tracks.remove(filepath)
                        i += 1
                        mtime = int(os.path.getmtime(filepath))
                        if mtime <= mtimes[filepath]:
                            i += 1
                            continue
                        else:
                            self._del_from_db(filepath)
                    infos = self.get_infos(filepath)
                    # On first scan, use modification time
                    # Else, use current time
                    if was_empty:
                        mtime = int(os.path.getmtime(filepath))
                    else:
                        mtime = int(time())
                    debug("Adding file: %s" % filepath)
                    self._add2db(filepath, infos, mtime)
                except Exception as e:
                    debug("Error scanning: %s, %s" % (filepath, e))
                    string = "%s" % e
                    if string.startswith('gst-core-error-quark'):
                        self._missing_codecs = filepath
                i += 1

            # Clean deleted files
            for filepath in orig_tracks:
                i += 1
                GLib.idle_add(self._update_progress, i, count)
                self._del_from_db(filepath)

            sql.commit()
        GLib.idle_add(self._finish)
        del self._history
        self._history = None