def _connect(self): try: self.client = MopidyAPI( host=self.hostname, port=self.port, use_websocket=False, logger=logging.getLogger(__name__ + ".client"), ) self.server_version = self.client.rpc_call("core.get_version") _LOGGER.debug( "Connection to Mopidy server %s (%s:%s) established", self.device_name, self.hostname, self.port, ) except reConnectionError as error: _LOGGER.error( "Cannot connect to %s @ %s:%s", self.device_name, self.hostname, self.port, ) _LOGGER.error(error) self._available = False return self._available = True
def __init__(self, musiq): self.SEEK_DISTANCE = 10 * 1000 self.shuffle = Setting.objects.get_or_create( key='shuffle', defaults={'value': 'False'})[0].value == 'True' self.repeat = Setting.objects.get_or_create( key='repeat', defaults={'value': 'False'})[0].value == 'True' self.autoplay = Setting.objects.get_or_create( key='autoplay', defaults={'value': 'False'})[0].value == 'True' self.musiq = musiq self.queue = models.QueuedSong.objects Player.queue_semaphore = Semaphore(self.queue.count()) self.alarm_playing = Event() self.player = MopidyAPI() self.player_lock = Lock() with self.mopidy_command(important=True): self.player.playback.stop() self.player.tracklist.clear() # make songs disappear from tracklist after being played self.player.tracklist.set_consume(True) with self.mopidy_command(important=True): #currentsong = self.player.currentsong() self.volume = self.player.mixer.get_volume() / 100
def setUp(self): super().setUp() # mute player for testing self.player = MopidyAPI(host=settings.MOPIDY_HOST) self.player.mixer.set_volume(0) # reduce number of downloaded songs for the test self.client.post(reverse("set_max_playlist_items"), {"value": "5"})
def _test_connection(host, port): client = MopidyAPI( host=host, port=port, use_websocket=False, logger=logging.getLogger(__name__ + ".client"), ) client.rpc_call("core.get_version") return True
def _validate_input(host, port): """Validate the user input.""" client = MopidyAPI( host=host, port=port, use_websocket=False, logger=logging.getLogger(__name__ + ".client"), ) client.rpc_call("core.get_version") return True
''' dépot et documentation de la librairie : https://github.com/AsbjornOlling/mopidyapi pip3 install mopidyapi ''' from mopidyapi import MopidyAPI import time START_BOLD = '\033[1m' END_BOLD = '\033[0m' m = MopidyAPI() tracks = m.tracklist.get_tracks() # print(tracks[0].name) m.tracklist.clear() presets = ['spotify:track:4evj46yiEKdN8gr6K0e7PX', 'local:track:ah.mp3', 'tunein:station:s15200'] response = m.tracklist.add(uris=presets) m.playback.play() # Liste des evenements : https://docs.mopidy.com/en/latest/api/core/#core-events @m.on_event('track_playback_started') def print_newtracks(event): print(f"Started playing track: {event.tl_track.track.name}") @m.on_event('track_playback_paused') def print_paused_events(event): print(f"Paused song : {START_BOLD}{event.tl_track.track.name}{END_BOLD} at : {START_BOLD}{event.time_position}{END_BOLD} ms")
def _test_connection(host, port): client = MopidyAPI(host=host, port=port, use_websocket=False) i = client.rpc_call("core.get_version") return True
from django.conf import settings as conf from django.core.handlers.wsgi import WSGIRequest from django.db import transaction from django.db.models import F from django.http import HttpResponseForbidden from django.http.response import HttpResponse, HttpResponseBadRequest from django.utils import timezone from django.views.decorators.csrf import csrf_exempt from mopidyapi import MopidyAPI from core import models, redis, user_manager from core.musiq import musiq, playback from core.settings import storage from core.util import extract_value PLAYER = MopidyAPI(host=conf.MOPIDY_HOST, port=conf.MOPIDY_PORT) SEEK_DISTANCE = 10 def control(func: Callable) -> Callable: """A decorator for functions that control the playback. Every control changes the views state and returns an empty response. At least mod privilege is required during voting.""" def _decorator(request: WSGIRequest) -> HttpResponse: if storage.get( "interactivity" ) != storage.Interactivity.full_control and not user_manager.has_controls( request.user): return HttpResponseForbidden() response = func(request) musiq.update_state()
config.read(str(Path.home()) + '/.config/mopidy/mopidy.conf') On cible la section spotify spotify_config = config['spotify'] On passe les valeurs à spotipy client_credentials_manager = SpotifyClientCredentials(client_id=spotify_config['client_id'], client_secret=spotify_config['client_secret']) 1sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager) """ """ Pas très clean de mettre les fonction de callback aux évènements dans le main Mais on a besoin de l'instance de mopidyApi et la fonction callback à besoin de l'instance nfcHandler pour lancer les recos... Piste : Ajouter encore une classe mère pour remplacer le main? """ if __name__ == "__main__": mopidy = MopidyAPI() o2mConf = util.get_config_file("o2m.conf") # o2m mopidyConf = util.get_config_file("mopidy.conf") # mopidy #mopidyConf = util.get_config_file("snapcast.conf") # mopidy nfcHandler = NfcToMopidy(mopidy, o2mConf, mopidyConf, logging) # Fonction called when track started @mopidy.on_event("track_playback_started") def track_started_event(event): track = event.tl_track.track #Quick and dirty volume Management if "radiofrance-podcast.net" in track.uri: nfcHandler.current_volume = nfcHandler.mopidyHandler.mixer.get_volume( ) nfcHandler.mopidyHandler.mixer.set_volume(
def _validate_input(host, port): """Validate the user input.""" client = MopidyAPI( host=host, port=port, use_websocket=False ) t = client.rpc_call("core.get_version") return True
if screenConfiguration: from musicDisplay import musicDisplaySmall as musicDisplay else: from musicDisplay import musicDisplay else: from musicDisplay import musicDisplay if config.has_option("mopidy", "host"): mopidyHost = config["mopidy"]["host"] if config.has_option("mopidy", "port"): mopidyPort = int(config["mopidy"]["port"]) trackingPath = "/home/pi/workspace/data" trackingFile = trackingPath + "/" + "librespotOutput" m = MopidyAPI(host=mopidyHost, port=mopidyPort) currentTrack = Track("Uninitialized", "Uninitialized", "Uninitialized", "Uninitialized", "Uninitialized") artistMutex = Lock() displaySemaphore = Semaphore(2) displayMutex = Lock() def trackFromResult(resultTrack): localTrack = Track() localTrack.title = resultTrack.name localTrack.artist = resultTrack.artists[0].name localTrack.album = resultTrack.album.name time = resultTrack.length / 1000 localTrack.timeAudio = str(int(time / 60)) + ":" + '%02d' % int(time % 60)