Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- from nebula.plugins.playout import PlayoutPlugin, PlayoutPluginSlot
- class Plugin(PlayoutPlugin):
- # Plugin info. Plugin name needs to be appended to the channels plugin list
- name = "content_alert"
- # Default CasparCG layer. Used by self.layer() method
- id_layer = 98
- # Slots are inuputs for the plugin. they will be displayed as widgets in
- # the Firefly plugin control UI. In this case, we want to be able to
- # manually hide the alert if something goes wrong. "action" type Slots
- # will be displayed as buttons.
- slots = [
- PlayoutPluginSlot(type="action", name="Hide")
- ]
- # Custom attribute holding the current parental guidance level
- current_level: int | None = None
- def on_change(self):
- # This method is called every time a new item starts playing
- # we wait a bit to make sure the item is actually playing
- time.sleep(0.2)
- # Then we check if the item has a parental guidance level
- if alert := self.current_item["content_alert/scheme"]:
- self.current_level = {
- "53.1.2": 12,
- "53.1.3": 15,
- "53.1.4": 18,
- }.get(alert)
- # If it does, we add two tasks to the plugin task list
- # The tasks will be executed in order, and will be repeated
- # until they return True. This allows us to wait for the
- # right moment to show or hide the alert.
- if self.current_level:
- self.tasks = [self.show, self.hide]
- return
- # If the item does not have a parental guidance level, we clear
- # the tasks list and hide the layer
- self.current_level = None
- self.tasks = []
- self.query(f"CLEAR {self.layer()}")
- def show(self):
- # This method is called by the first task in the task list
- # It will be called repeatedly until it returns True
- # Our goal is to show the alert after the item has been playing
- # for 5 seconds. We check the item position and return False
- # if it's too early.
- if self.position < 5:
- return False
- # If it's not too early, we show the alert and return True
- # to tell the task list that we're done, and that it can be
- # removed from the task list.
- self.query(f"PLAY {self.layer()} alert-{self.current_level} MIX 25")
- return True
- def hide(self):
- # This method is called by the second task in the task list
- # It will be called repeatedly until it returns True
- # Our goal is to hide the alert after the item has been playing
- # for 10 seconds. We check the item position and return False
- # if it's too early.
- if self.position < 10:
- return False
- # If it's not too early, we hide the alert and return True
- # to tell the task list that we're done, and that it can be
- # removed from the task list.
- self.query(f"PLAY {self.layer()} EMPTY MIX 25")
- return True
- def on_command(self, action, data):
- # This method is called when a Slot is triggered
- # We check if the Slot is the "Hide" Slot, and if it is,
- # we hide the alert.
- if action == "hide":
- self.query(f"PLAY {self.layer()} EMPTY")
- return True
Add Comment
Please, Sign In to add comment