コード例 #1
0
    def __init__(self, debug=False):
        applog.debug('Initializing MopidyClient ...')

        # Init variables
        self.state = 'stopped'
        self.uri = None
        self.save_results = False
        self.debug_flag = debug

        # Instantiate Mopidy Client
        self.mopidy = MopidyClient(
            ws_url='ws://localhost:6680/mopidy/ws',
            #event_handler=self.on_event,
            connection_handler=self.on_connection,
            autoconnect=False,
            retry_max=None,
            retry_secs=10)

        self.mopidy.debug_client(self.debug_flag)
        self.mopidy.bind_event('playback_state_changed',
                               self.playback_state_changed)
        self.mopidy.connect()

        # Instantiate Timer Objects
        self.backlight_dim_timer = None
        self.backlight_off_timer = None
コード例 #2
0
ファイル: music.py プロジェクト: Wqrld/mopidy-to-rgb-matrix
    def __init__(self, *args, **kwargs):
        super(RunText, self).__init__(*args, **kwargs)
        self.parser.add_argument("-t", "--text", help="The text to scroll on the RGB LED panel", default="Hello world!")
        super(RunText, self).__init__()

        print('Starting Mopidy to Matrix')

        # Init variables
        self.state = 'stopped'
        self.uri = None
        self.save_results = False
        self.debug_flag = False

        # Instantiate Mopidy Client
        self.mopidy = MopidyClient(
            ws_url='ws://192.168.178.220:6680/mopidy/ws',
            autoconnect=False,
            retry_max=10,
            retry_secs=10
        )
        self.mopidy.bind_event('track_playback_started', updatetrack)
        self.mopidy.bind_event('playback_state_changed', playback_state_changed)
        self.mopidy.debug_client(self.debug_flag)
        self.mopidy.connect()
        global mopid
        mopid = self.mopidy
        
        s.start()
        t.start()
コード例 #3
0
ファイル: mopidy_service.py プロジェクト: sanyasig/AlexaHome
    def test(self):

        self.mopidy = MopidyClient(
            ws_url='ws://localhost:6680/mopidy/ws',
            error_handler=None,
            connection_handler=None,
            autoconnect=False,
            retry_max=10,
            retry_secs=10
        )

        self.mopidy.connect()
        args = ""
        self.mopidy.tracklist.add(uris=self.gen_uris(args))
コード例 #4
0
ファイル: manager.py プロジェクト: ismailof/rockberry-player
    def __init__(self, **kwargs):
        super(MediaManager, self).__init__(**kwargs)

        self.app = App.get_running_app()
        MediaController.app = self.app

        self.mopidy = MopidyClient(
            ws_url='ws://' + self.app.MOPIDY_SERVER + '/mopidy/ws',
            version='2.0.1',
            error_handler=self.on_mopidy_error,
            connection_handler=self.on_connection,
        )
        #        self.mopidy.debug_client(True)

        self.controllers = (self.state, self.mixer, self.options, self.current,
                            self.next, self.prev, self.queue, self.browser,
                            self.history)

        self.bind_events()
コード例 #5
0
class VolumeGPIO(object):

    mopidy = MopidyClient()
    volume = 50
    mute = False

    def __init__(self, pinout):

        # Bind mopidy events to functions
        self.mopidy.listener.bind('volume_changed', self.update_volume)
        self.mopidy.listener.bind('mute_changed', self.update_mute)

        # Get initial values for volume and mute
        self.mopidy.mixer.get_volume(on_result=self.update_volume)
        self.mopidy.mixer.get_mute(on_result=self.update_mute)

        # Initialize GPIO controlers
        self.c_volume = RotaryEncoder(pinout=(pinout[0], pinout[1]),
                                      on_rotate=self.change_volume)

        self.c_mute = MomentarySwitch(pin=pinout[2],
                                      holdtime=2,
                                      on_press=self.toggle_mute)

    def change_volume(self, value):
        new_volume = max(min(self.volume + value * 5, 100), 0)
        self.mopidy.mixer.set_volume(new_volume)

    def toggle_mute(self):
        new_mute = not self.mute
        self.mopidy.mixer.set_mute(new_mute)

    def update_volume(self, volume):
        self.volume = volume

    def update_mute(self, mute):
        self.mute = mute

    def close(self):
        self.c_volume.close()
        self.c_mute.close()
コード例 #6
0
    def __init__(self, debug=False):
        super(MopidyWSCLI, self).__init__()

        print('Starting Mopidy Websocket Client CLI DEMO ...')

        # Init variables
        self.state = 'stopped'
        self.uri = None
        self.save_results = False
        self.debug_flag = debug

        # Instantiate Mopidy Client
        self.mopidy = MopidyClient(ws_url='ws://localhost:6680/mopidy/ws',
                                   error_handler=self.on_server_error,
                                   connection_handler=self.on_connection,
                                   autoconnect=False,
                                   retry_max=10,
                                   retry_secs=10)

        self.mopidy.debug_client(self.debug_flag)
        self.bind_events()
        self.mopidy.connect()
コード例 #7
0
        return

    trackinfo = {
        'name':
        track.get('name'),
        'artists':
        ', '.join([artist.get('name') for artist in track.get('artists')])
    }
    print('Now playing: {artists} - {name}'.format(**trackinfo))


def show_tracklist(tracklist):
    print_nice('> Current Tracklist: ', tracklist, format='tracklist')


mopidy = MopidyClient()
mopidy.bind_event('track_playback_started', print_track_info)

mopidy.tracklist.get_tl_tracks(on_result=show_tracklist)

mopidy.tracklist.add(uris=[
    'local:track:01%20Home%20Recording.m4a',
    'local:track:Zonder%20totetrekkerie.mp3'
])

mopidy.tracklist.get_tl_tracks(on_result=show_tracklist)

mopidy.playback.play()

if __name__ == '__main__':
コード例 #8
0
#!/usr/bin/env python3
"""
This is an interface for mopidy using a bluetooth remote controller
I have it running on a raspberry pi that is connected via bluetooth to a speaker with a remote control
"""

import evdev
from mopidy_json_client import MopidyClient
import time
from os import path

BLUETOOTH_FILE = '/dev/input/event1'

mp = MopidyClient()

# mp.bind_event('track_playback_started', print_track_info)
# mp.playback.play()


def handle_remote_control_key(mp, key_event):
    key_down_events = {
        "KEY_PAUSECD": mp.playback.pause,
        "KEY_PLAYCD": mp.playback.play,
        "KEY_PREVIOUSSONG": mp.playback.previous,
        "KEY_NEXTSONG": mp.playback.next
    }

    e = evdev.categorize(key_event)
    print(
        f"keys are {e.keystate}, {e.key_down}, {e.key_up}, {e.keycode}, {e.event}, {e.scancode}"
    )
コード例 #9
0
ファイル: bot.py プロジェクト: zippyy/mopidybot
from uuid import uuid4

import logging

# Enable logging
logging.basicConfig(
    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
    level=logging.INFO)

logger = logging.getLogger(__name__)

mopidy = MopidyClient(
    ws_url='ws://localhost:6680/mopidy/ws',
    # event_handler=self.on_event,
    # error_handler=self.on_server_error,
    # connection_handler=self.on_connection,
    autoconnect=False
    # retry_max=10,
    # retry_secs=10
)
mopidy.connect()


def show_search_results(search_results):
    print_nice('Search Results: ', search_results, format='search')


def start(bot, update):
    update.message.reply_text('Hello World!')

コード例 #10
0
#!/usr/bin/env python3
"""
This launches albums on mopidy

still a work in progress
"""

from mopidy_json_client import MopidyClient
import pathlib
import urllib.parse

TESTING = False

if TESTING:
    BASE_FP = "/home/bsaund/Dropbox/Music/"
    mp = MopidyClient(ws_url='ws://192.168.1.54:6680/mopidy/ws')
else:
    BASE_FP = "/home/pi/Dropbox/Music"
    mp = MopidyClient()


def add_all_songs_from_folder(folder):
    d = pathlib.Path(BASE_FP) / folder
    uris = sorted([
        'file://' + urllib.parse.quote(fp.as_posix())
        for fp in d.glob('[!._]*.mp3')
    ])
    # uris = [urllib.parse.quote(a) for a in uris]
    mp.tracklist.mopidy_request('core.tracklist.add', uris=uris)

    # pathilb.Path()