def get_duration(iso_8601_duration): seconds = 0 intervals = {'D': 86400, 'H': 3600, 'M': 60, 'S': 1} for num, designator in re.findall(r'(\d+)([DHMS])', iso_8601_duration): seconds += intervals[designator] * int(num) return human_length(seconds)
def update_title(self): index = self.current_index + 1 total_files = len(self.properties) total_size = str(human_size(self.total_size)) if self.total_length: self.dialog.set_title(_("File Properties (%(num)i of %(total)i / %(size)s / %(length)s)") % { 'num': index, 'total': total_files, 'size': total_size, 'length': str(human_length(self.total_length)) }) return self.dialog.set_title(_("File Properties (%(num)i of %(total)i / %(size)s)") % { 'num': index, 'total': total_files, 'size': total_size})
def get_hleft(left): return human_length(left) if left >= 1 else ""
def mpris(self, player): """ Function to get the currently playing song via DBus MPRIS v2 interface """ # https://media.readthedocs.org/pdf/mpris2/latest/mpris2.pdf from gi.repository import Gio # pylint: disable=import-error self.bus = Gio.bus_get_sync(Gio.BusType.SESSION, None) dbus_mpris_service = 'org.mpris.MediaPlayer2.' dbus_mpris_player_service = 'org.mpris.MediaPlayer2.Player' dbus_mpris_path = '/org/mpris/MediaPlayer2' dbus_property = 'org.freedesktop.DBus.Properties' if not player: dbus_proxy = Gio.DBusProxy.new_sync(self.bus, Gio.DBusProxyFlags.NONE, None, 'org.freedesktop.DBus', '/org/freedesktop/DBus', 'org.freedesktop.DBus', None) names = dbus_proxy.ListNames() players = [] for name in names: if name.startswith(dbus_mpris_service): players.append(name[len(dbus_mpris_service):]) if not players: log.add_important_error( _("MPRIS: Could not find a suitable MPRIS player")) return None player = players[0] if len(players) > 1: log.add( _("Found multiple MPRIS players: %(players)s. Using: %(player)s" ), { 'players': players, 'player': player }) else: log.add(_("Auto-detected MPRIS player: %s"), player) try: dbus_proxy = Gio.DBusProxy.new_sync(self.bus, Gio.DBusProxyFlags.NONE, None, dbus_mpris_service + player, dbus_mpris_path, dbus_property, None) metadata = dbus_proxy.Get('(ss)', dbus_mpris_player_service, 'Metadata') except Exception as error: log.add_important_error( _("MPRIS: Something went wrong while querying %(player)s: %(exception)s" ), { 'player': player, 'exception': error }) return None self.title['program'] = player list_mapping = [('xesam:artist', 'artist')] for source, dest in list_mapping: try: self.title[dest] = '+'.join(metadata[source]) except KeyError: self.title[dest] = '?' mapping = [('xesam:title', 'title'), ('xesam:album', 'album'), ('xesam:contentCreated', 'year'), ('xesam:comment', 'comment'), ('xesam:audioBitrate', 'bitrate'), ('xesam:url', 'filename'), ('xesak:trackNumber', 'track')] for source, dest in mapping: try: self.title[dest] = str(metadata[source]) except KeyError: self.title[dest] = '?' # The length is in microseconds, and be represented as a signed 64-bit integer. try: self.title['length'] = human_length(metadata['mpris:length'] // 1000000) except KeyError: self.title['length'] = '?' if self.title['artist'] != "": self.title['nowplaying'] += self.title['artist'] if self.title['title'] != "": self.title['nowplaying'] += " - " + self.title['title'] return True
def get_helapsed(elapsed): return human_length(elapsed) if elapsed >= 1 else ""