예제 #1
0
def write_snarks(dest_file, snarks, show_time, options={}, keep_alive_func=None, sleep_func=None):
  """Writes snarks as tab-separated text.

  Columns: In-Movie Time, Original Date, Color, User, Msg.

  Newlines in "msg" are represented with \n.

  :param dest_file: A binary-mode file-like object to write into.
  :param snarks: A list of processed snark dicts.
  :param show_time: Timedelta duration each msg appears on-screen.
  :param options: A dict of extra options specific to this exporter.
                  Not used.
  :param keep_alive_func: Optional replacement to get an abort boolean.
  :param sleep_func: Optional replacement to sleep N seconds.
  """
  if (keep_alive_func is None): keep_alive_func = global_config.keeping_alive
  if (sleep_func is None): sleep_func = global_config.nap

  dest_file.write("\t".join(["In-Movie Time", "Original Date", "Color", "User", "Msg"]))
  dest_file.write("\r\n")

  for snark in snarks:
    snark_start = common.delta_str(snark["time"])
    snark_date = snark["date"].strftime("%Y-%m-%d %H:%M:%S")

    snark_color = ""
    if ("color" in snark and snark["color"] is not None):
      snark_color = common.rgb_to_hex(snark["color"])

    # Represent newlines with \n.
    snark_msg = snark["msg"].replace("\n", "\\n")

    dest_file.write("\t".join([snark_start, snark_date, snark_color, snark["user"], snark_msg]))
    dest_file.write("\r\n")
예제 #2
0
파일: subrip.py 프로젝트: Vhati/CompileSubs
def color_message(text, color):
  """Wraps a string with an html/srt FONT tag of the given color.

  :param text: A snark message.
  :param color: An RGB float tuple (value range: 0.0-1.0).
  :return: The wrapped string.
  """
  text = "<font color=\"#%s\">%s</font>" % (common.rgb_to_hex(color), text)
  return text
예제 #3
0
def write_palette_preview(path, unique_colors):
  """Dumps colors to a sanity-preserving html file for eyeballing.
  A relic from debugging random palettes.

  :param path: A file path to write to.
  :param unique_colors: A list of RGB float tuples.
  """
  out_file = open(path, 'w')
  out_file.write("<html><body>\n");
  for color in unique_colors:
    out_file.write("<font color=\"#%s\"><b>#########</b></font><br />\n" % (common.rgb_to_hex(color)));
  out_file.write("</body></html>");
  out_file.close()