Exemple #1
0
    def notify(self, title, body, actions, icon, replace=True):
        """
        Create new or update existing notification.

        Args:
           track (`clay.gp.Track`): The track that you want to send the notification for
           actions (`list`): A list with the actions that you want the notification to react to.
        """
        if not ENABLED:
            return

        actions_ = []
        for action in actions:
            if action not in self._actions:
                logger.error("Can't find action: {}".format(action))
                continue

            actions_.append(action)
            actions_.append(self._actions[action][0])

        self._notify(
            title,
            body,
            replace,
            actions=actions_,
            hints={"action-icons": Variant('b', 1)},  # only display icons
            icon=icon if icon is not None else 'audio-headphones')
Exemple #2
0
    def _download_track(self, url, error, track):
        if error:
            logger.error("failed to request media URL for track %s: %s",
                         track.original_data, str(error))
            return

        response = urlopen(url)
        path = settings_manager.save_file_to_cache(track.filename,
                                                   response.read())
        self._play_ready(path, None, track)
Exemple #3
0
Fichier : mpv.py Projet : thor/clay
 def seek_absolute(self, position):
     """
     Seek to absolute position.
     *position* must be a ``float`` in range ``[0;1]``.
     """
     try:
         self.media_player.seek(int(self.length_seconds * position), reference='absolute')
     # properly handle this
     except Exception as e:
         logger.error(e)
Exemple #4
0
Fichier : mpv.py Projet : thor/clay
 def seek(self, delta):
     """
     Seek to relative position.
     *delta* must be a ``float`` in range ``[-1;1]``.
     """
     try:
         self.media_player.seek(int(self.length_seconds * delta))
     # properly handle this
     except Exception as e:
         logger.error(e)
Exemple #5
0
    def _register_bus_name(self, name_owner):
        """
        Registers a bus for sending notifications over dbus

        Args:
            name_owner (`str`) (unused): The owner of the bus

        Returns:
            Nothing.
        """
        try:
            self.notifications = self.bus.get(NOTIFICATION_BUS_NAME)
            self.notifications.onActionInvoked = self._on_action
        except GLib.Error:
            # Bus name did not exist
            logger.error('Attempted bus name registration failed, %s',
                         NOTIFICATION_BUS_NAME)
Exemple #6
0
    def _play_ready(self, url, error, track):
        """
        Called once track's media stream URL request completes.
        If *error* is ``None``, tell libVLC to play media by *url*.
        """
        self._loading = False
        if error:
            #notification_area.notify('Failed to request media URL: {}'.format(str(error)))
            logger.error('Failed to request media URL for track %s: %s',
                         track.original_data, str(error))
            return
        assert track

        self.media_player.play(url)

        osd_manager.notify(
            track.title, "by {}\nfrom {}\n".format(track.artist,
                                                   track.album_name),
            ("media-skip-backward", "media-playback-pause",
             "media-skip-forward"), track.get_artist_art_filename())
Exemple #7
0
    def set_page(self, slug):
        """
        Switch to a different tab.
        """
        try:
            self.current_page.songlist.end_filtering()
        except AttributeError as e:
            logger.error(str(e))

        page = [page for page in self.pages if page.slug == slug][0]
        self.current_page = page
        self.contents['body'] = (page, None)

        for tab in self.tabs:
            tab.set_active(False)
            if tab.page == page:
                tab.set_active(True)

        self.redraw()

        page.activate()
Exemple #8
0
    def _notify(self,
                summary,
                body,
                replace=True,
                actions=None,
                hints=None,
                expiration=5000,
                icon='audio-headphones'):
        """
        An implementation of Desktop Notifications Specification 1.2.
        For a detailed explanation see: https://developer.gnome.org/notification-spec/

        Does not fire if notifications were not properly set up
        Args:
           summary (`str`): A single line overview of the notification
           body (`str`): A mutli-line body of the text
           replace (`bool`): Should the notification be updated or should a new one be made
           actions (`list`): The actions a notification can perform, might be ignored. Default empty
           hints (`dict`): Extra information the server might be able to make use of
           expiration (`int`): The time until the notification automatically closes. -1 to make the
              server decide and 0 for never. Defaults to 5000.
           icon (`str`): The string to icon it displays in the notification. Defaults to headbuds.

        Returns:
           Nothing.
        """
        if self.notifications is None:
            return

        try:
            self._last_id = self.notifications.Notify(
                meta.APP_NAME, self._last_id if replace else 0, icon, summary,
                body, actions if actions is not None else list(),
                hints if hints is not None else dict(), expiration)
        except GLib.Error as exception:
            logger.error('Failed to post notification %s', exception)
Exemple #9
0
def report_error(exc):
    "Print an error message to the debug screen"
    logger.error("{0}: {1}".format(exc.__class__.__name__, exc))
Exemple #10
0
    def Explicit(self):
        track = player.get_current_track()
        if track is None:
            return False
        else:
            return track.explicit_rating != 0


def load_xml(name):
    return pkg_resources.resource_string(__name__, "mpris/org.mpris.MediaPlayer2" + name + ".xml")\
        .decode("utf-8")


bus = SessionBus()
MPRIS2.dbus = [
    load_xml(file_) for file_ in ["", ".Player", ".TrackList", ".Playlists"]
]
mpris2_manager = MPRIS2()

try:
    bus.publish("org.mpris.MediaPlayer2.clay", mpris2_manager,
                ('/org/mpris/MediaPlayer2', mpris2_manager),
                ('/org/mpris/MediaPlayer2/Player', mpris2_manager),
                ('/org/mpris/MediaPlayer2/TrackList', mpris2_manager))

except RuntimeError as e:
    logger.error(str(e))
    logger.warn(
        "An another instance of Clay is already running so we can't start MPRIS2"
    )