Internet DJ Console Homepage IDJC

website logo

With a little work this could be made to interface with your station's web page or with cloud services.

#! /usr/bin/env python3

"""idjcmon.py demo code

This could be extended to add features to IDJC without modifying the
main source code.

Takes the profile you wish to monitor as the command line parameter.
"""

import sys

import gi
gi.require_version("GLib", "2.0")
from gi.repository import GLib
import idjcmonitor


def launch_handler(monitor, profile, pid):
    print(f"Hello to IDJC {profile} with process ID {pid}.")

def quit_handler(monitor, profile, pid):
    print(f"Goodbye to IDJC {profile} with process ID {pid}.")

def streamstate_handler(monitor, which, state, where):
    print(f"Stream {which} is {('down', 'up')[state]} "
          f"on connection {where}.")

def metadata_handler(monitor, artist, title, album, songname, filename):
    print(f"Metadata is: {artist=}, {title=}, {album=}, {filename=}")

def frozen_handler(monitor, profile, pid, frozen):
    print(f"IDJC {profile} with process ID {pid} is "
          f"{('running', 'stopped or frozen ')[frozen]}")

def effect_started_handler(monitor, title, pathname, player):
    print(f"Effect player {player} is playing {title}")

def effect_stopped_handler(monitor, player):
    print(f"Effect player {player} has stopped")

def focus_changed_handler(monitor, window_name, has_focus):
    print(f"Window '{window_name}' {('lost', 'gained')[has_focus]} keyboard focus")
    entry_mode_handler(monitor, monitor.get_property("entry-mode"))

def entry_mode_handler(monitor, entry_mode):
    hotkey_window = monitor.get_property("focus-window") is not None
    hotkeys_available = hotkey_window and not entry_mode
    print(f"{entry_mode=}")
    print(f"{hotkeys_available=}")

def stream_silence_handler(monitor, stream_silence):
    print(f"{stream_silence=}")

try:
    profile = sys.argv[1]
except IndexError:
    profile = "default"

monitor = idjcmonitor.IDJCMonitor(profile)
monitor.connect("launch", launch_handler)
monitor.connect("quit", quit_handler)
monitor.connect("streamstate-changed", streamstate_handler)
monitor.connect("metadata-changed", metadata_handler)
monitor.connect("frozen", frozen_handler)
monitor.connect("effect-started", effect_started_handler)
monitor.connect("effect-stopped", effect_stopped_handler)
monitor.connect("focus-changed", focus_changed_handler)
monitor.connect("entry-mode-changed", entry_mode_handler)
monitor.connect("stream-silence-changed", stream_silence_handler)

try:
    GLib.MainLoop().run()
except KeyboardInterrupt:
    print("Goodbye from idjcmon")