Ejemplo n.º 1
0
    def update_track(self,
                     gloc: Gio.File,
                     force_update: bool = False) -> Optional[trax.Track]:
        """
        Rescan the track at a given location

        :param gloc: the location
        :type gloc: :class:`Gio.File`
        :param force_update: Force update of file (default only updates file
                             when mtime has changed)

        returns: the Track object, None if it could not be updated
        """
        uri = gloc.get_uri()
        if not uri:  # we get segfaults if this check is removed
            return None

        tr = self.collection.get_track_by_loc(uri)
        if tr:
            tr.read_tags(force=force_update)
        else:
            tr = trax.Track(uri)
            if tr._scan_valid:
                self.collection.add(tr)

            # Track already existed. This fixes trax.get_tracks_from_uri
            # on windows, unknown why fix isnt needed on linux.
            elif not tr._init:
                self.collection.add(tr)
        return tr
Ejemplo n.º 2
0
    def open_local_file(self, file: Gio.File):
        self._notifications.clear()
        if file is None:
            return

        def error(e):
            self._notifications.add_simple(
                _('Cannot load project: ') + str(e), Gtk.MessageType.ERROR)
            self.buffer.load_from_file(None)

        ext = os.path.splitext(file.get_basename())[1]
        if ext != '.tcp':
            error(Exception(_('Wrong file extenstion')))
            return
        if not file.query_exists():
            error(
                Exception(
                    _('File "{}" is not available').format(file.get_uri())))
            return

        try:
            self.buffer.load_from_file(file)
        except lib.CorruptedFileException as e:
            error(e)
        except lib.MissingPluginException as e:
            error(e)
        except lib.UnavailableCommandException as e:
            error(e)
        except GLib.Error as e:
            error(e)
Ejemplo n.º 3
0
def recursive_tracks_from_file(gfile: Gio.File) -> Iterable[Track]:
    """
        Get recursive tracks from Gio.File
        If it's a directory, expands
        Gets only valid tracks
    """
    ftype = gfile.query_info('standard::type', Gio.FileQueryInfoFlags.NONE,
                             None).get_file_type()
    if ftype == Gio.FileType.DIRECTORY:
        file_infos = gfile.enumerate_children('standard::name',
                                              Gio.FileQueryInfoFlags.NONE,
                                              None)
        files = (gfile.get_child(fi.get_name()) for fi in file_infos)
        for sub_gfile in files:
            for i in recursive_tracks_from_file(sub_gfile):
                yield i
    else:
        uri = gfile.get_uri()
        if is_valid_track(uri):
            yield Track(uri)