martastain

Nebula playout plugin examle (content alert)

Dec 25th, 2023
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.37 KB | None | 0 0
  1. import time
  2. from nebula.plugins.playout import PlayoutPlugin, PlayoutPluginSlot
  3.  
  4.  
  5. class Plugin(PlayoutPlugin):
  6.  
  7.     # Plugin info. Plugin name needs to be appended to the channels plugin list
  8.     name = "content_alert"
  9.  
  10.     # Default CasparCG layer. Used by self.layer() method
  11.     id_layer = 98
  12.  
  13.     # Slots are inuputs for the plugin. they will be displayed as widgets in
  14.     # the Firefly plugin control UI. In this case, we want to be able to
  15.     # manually hide the alert if something goes wrong. "action" type Slots
  16.     # will be displayed as buttons.
  17.     slots = [
  18.         PlayoutPluginSlot(type="action", name="Hide")
  19.     ]
  20.  
  21.     # Custom attribute holding the current parental guidance level
  22.     current_level: int | None = None
  23.  
  24.  
  25.     def on_change(self):
  26.         # This method is called every time a new item starts playing
  27.         # we wait a bit to make sure the item is actually playing
  28.         time.sleep(0.2)
  29.  
  30.         # Then we check if the item has a parental guidance level
  31.         if alert := self.current_item["content_alert/scheme"]:
  32.             self.current_level = {
  33.                 "53.1.2": 12,
  34.                 "53.1.3": 15,
  35.                 "53.1.4": 18,
  36.             }.get(alert)
  37.  
  38.             # If it does, we add two tasks to the plugin task list
  39.             # The tasks will be executed in order, and will be repeated
  40.             # until they return True. This allows us to wait for the
  41.             # right moment to show or hide the alert.
  42.             if self.current_level:
  43.                 self.tasks = [self.show, self.hide]
  44.                 return
  45.  
  46.         # If the item does not have a parental guidance level, we clear
  47.         # the tasks list and hide the layer
  48.         self.current_level = None
  49.         self.tasks = []
  50.         self.query(f"CLEAR {self.layer()}")
  51.  
  52.     def show(self):
  53.         # This method is called by the first task in the task list
  54.         # It will be called repeatedly until it returns True
  55.         # Our goal is to show the alert after the item has been playing
  56.         # for 5 seconds. We check the item position and return False
  57.         # if it's too early.
  58.         if self.position < 5:
  59.             return False
  60.  
  61.         # If it's not too early, we show the alert and return True
  62.         # to tell the task list that we're done, and that it can be
  63.         # removed from the task list.
  64.         self.query(f"PLAY {self.layer()} alert-{self.current_level} MIX 25")
  65.         return True
  66.  
  67.     def hide(self):
  68.         # This method is called by the second task in the task list
  69.         # It will be called repeatedly until it returns True
  70.         # Our goal is to hide the alert after the item has been playing
  71.         # for 10 seconds. We check the item position and return False
  72.         # if it's too early.
  73.         if self.position < 10:
  74.             return False
  75.  
  76.         # If it's not too early, we hide the alert and return True
  77.         # to tell the task list that we're done, and that it can be
  78.         # removed from the task list.
  79.         self.query(f"PLAY {self.layer()} EMPTY MIX 25")
  80.         return True
  81.  
  82.     def on_command(self, action, data):
  83.         # This method is called when a Slot is triggered
  84.         # We check if the Slot is the "Hide" Slot, and if it is,
  85.         # we hide the alert.
  86.         if action == "hide":
  87.             self.query(f"PLAY {self.layer()} EMPTY")
  88.         return True
  89.  
  90.  
  91.  
Add Comment
Please, Sign In to add comment