<commit_before># pylint: disable=C0111,R0903

"""Displays information about the current song in Google Play music player.

Requires the following executable:
    * gpmdp-remote
"""

import bumblebee.util
import bumblebee.input
import bumblebee.output
import bumblebee.engine

class Module(bumblebee.engine.Module):
    def __init__(self, engine, config):
        widgets = [
            bumblebee.output.Widget(name='gpmdp.prev'),
            bumblebee.output.Widget(name='gpmdp.main', full_text=self.description),
            bumblebee.output.Widget(name='gpmdp.next'),
        ]
        super(Module, self).__init__(engine, config, widgets)

        engine.input.register_callback(widgets[0], button=bumblebee.input.LEFT_MOUSE,
            cmd='playerctl previous')
        engine.input.register_callback(widgets[1], button=bumblebee.input.LEFT_MOUSE,
             cmd='playerctl play-pause')
        engine.input.register_callback(widgets[2], button=bumblebee.input.LEFT_MOUSE,
             cmd='playerctl next')

        self._status = None
        self._tags = None

    def description(self, widget):
        return self._tags if self._tags else 'n/a'

    def update(self, widgets):
        self._load_song()

    def state(self, widget):
        if widget.name == 'gpmdp.prev':
            return 'prev'
        if widget.name == 'gpmdp.next':
            return 'next'
        return self._status

    def _load_song(self):
        info = ''
        try:
            info = bumblebee.util.execute('gpmdp-remote current')
            status = bumblebee.util.execute('gpmdp-remote status')
        except RuntimeError:
            pass
        self._status = status.split('\n')[0].lower()
        self._tags = info.split('\n')[0]

# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4<commit_msg>[modules/gpmdp] Update to latest API<commit_after># pylint: disable=C0111,R0903

"""Displays information about the current song in Google Play music player.

Requires the following executable:
    * gpmdp-remote
"""

import core.module
import core.widget
import core.input

import util.cli

class Module(core.module.Module):
    def __init__(self, config):
        widgets = [
            core.widget.Widget(name='gpmdp.prev'),
            core.widget.Widget(name='gpmdp.main', full_text=self.description),
            core.widget.Widget(name='gpmdp.next'),
        ]
        super().__init__(config, widgets)

        core.input.register(widgets[0], button=core.input.LEFT_MOUSE,
            cmd='playerctl previous')
        core.input.register(widgets[1], button=core.input.LEFT_MOUSE,
             cmd='playerctl play-pause')
        core.input.register(widgets[2], button=core.input.LEFT_MOUSE,
             cmd='playerctl next')

        self.__status = None
        self.__tags = None

    def description(self, widget):
        return self.__tags if self.__tags else 'n/a'

    def update(self):
        self.__load_song()

    def state(self, widget):
        if widget.name() == 'gpmdp.prev':
            return 'prev'
        if widget.name() == 'gpmdp.next':
            return 'next'
        return self.__status

    def __load_song(self):
        info = util.cli.execute('gpmdp-remote current', ignore_errors=True)
        status = util.cli.execute('gpmdp-remote status', ignore_errors=True)
        self.__status = status.split('\n')[0].lower()
        self.__tags = info.split('\n')[0]

# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
{'fraction_non_alphanumeric': 0.12196531791907514, 'fraction_numerical': 0.009248554913294798, 'mean_word_length': 2.689765458422175, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3066975', 'n_tokens_mistral': 1075, 'n_tokens_neox': 1043, 'n_words': 212}