Skip to content

Commit

Permalink
Merge pull request #12 from Dash-Industry-Forum/update-sscgen
Browse files Browse the repository at this point in the history
Add generate_ccs.py to generate ccs file and update sccgen.py.
  • Loading branch information
tobbee authored Jan 12, 2023
2 parents 66be01c + 57a37a9 commit 2856174
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 8 deletions.
6 changes: 3 additions & 3 deletions python/dash_tools/cea608.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ def log(self, severity, msg):
try:
minimal_level = self.verbose_filter[severity]
except KeyError:
print "WARNING: Severity %s not defined" % severity
print("WARNING: Severity %s not defined" % severity)
else:
if self.verbose_level >= minimal_level:
print "%s [%s] %s" % (self.time, severity, msg)
print("%s [%s] %s" % (self.time, severity, msg))


# Here comes the global logger instance
Expand Down Expand Up @@ -511,7 +511,7 @@ def set_bkg_data(self, bkg_data):
def set_mode(self, new_mode):
"Set the CC mode."
if not new_mode in self.modes:
raise KeyError, "Mode %s not supported!"
raise KeyError("Mode %s not supported!" % new_mode)
logger.log("INFO", "MODE=%s" % new_mode)
if new_mode == self.mode:
return
Expand Down
15 changes: 15 additions & 0 deletions python/dash_tools/example.ccs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
00:00:00:00
# > is command
# RCL = Resume Caption Loading (selects POP-ON)
# ENM = Erase Non-Displaced Memory
# EDM = Erase Displaced Memory
# PAC = Preamble Address code
# EOC = END of Caption. Will display caption
> RCL ENM PAC_1_white
eng: 00:00:00:00
> EDM EOC
# Next second
00:00:01:00
> RCL ENM PAC_2_green
eng: 00:00:01:00
> EDM EOC
26 changes: 26 additions & 0 deletions python/dash_tools/generate_ccs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import os, sys
from optparse import OptionParser

def main():
parser = OptionParser(usage="%prog [options]", description="Create .ccs file with rolling timestamps every second")
parser.add_option('-d', '--dur', help='duration in seconds [default: %default]',
type='int', action='store', default=10, dest='duration')
parser.add_option('-l', '--language', help='language [default: %default]',
type='string', action='store', default="eng", dest='lang')
(opts, _) = parser.parse_args()
secs = 0
line_nrs = (1, 2, 3, 4, 5, 10, 11, 12, 13, 14)
colors = ("white", "green", "blue", "cyan", "red", "yellow", "magenta", "italics")
while secs < opts.duration:
line_nr = line_nrs[secs % len(line_nrs)]
color = colors[secs % len(colors)]
minutes, seconds = divmod(secs, 60)
print("00:%02d:%02d:00" % (minutes, seconds))
print("> RCL ENM PAC_%d_%s" % (line_nr, color))
print("%s: 00:%02d:%02d:00" % (opts.lang, minutes, seconds))
print("> EDM EOC")
print("")
secs += 1

if __name__ == "__main__":
main()
14 changes: 9 additions & 5 deletions python/dash_tools/sccgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def parse_line(self, line):
if line[0] == "#": # Comment
return
time_parts = line.split(":")
if len(time_parts) == 4:
if len(time_parts) == 4 and len(time_parts[0]) == 2:
self.handle_dangling_char()
self.time = line
self.ofh.write("\n\n%s" % self.time)
Expand Down Expand Up @@ -152,7 +152,8 @@ def interpret_cmd(self, part):
byte2_offset = 0x10 + indent_amount/2 + underline
code = (pac_code[0], pac_code[1] + byte2_offset)
if self.verbose_level > 0:
print "PAC_code for row=%d indent=%d underline=%d (%02x, %02x)" % (line_nr, indent_amount, underline, code[0], code[1])
print("PAC_code for row=%d indent=%d underline=%d (%02x, %02x)" %
(line_nr, indent_amount, underline, code[0], code[1]))
else:
# Pattern is PAC_color or PAC_color_u
try:
Expand All @@ -163,7 +164,8 @@ def interpret_cmd(self, part):
byte2_offset = color_code + underline
code = (pac_code[0], pac_code[1] + byte2_offset)
if self.verbose_level > 0:
print "PAC_code for row=%d color=%s underline=%d (%02x, %02x)" % (line_nr, color, underline, code[0], code[1])
print("PAC_code for row=%d color=%s underline=%d (%02x, %02x)" %
(line_nr, color, underline, code[0], code[1]))
elif part.startswith("MID"):
# Pattern is MID_color or MID_color_u
parts = part.split("_")
Expand All @@ -175,7 +177,8 @@ def interpret_cmd(self, part):
underline = len(parts) > 2 and 1 or 0
code = (0x11, color_code + underline)
if self.verbose_level > 0:
print "MIDROW color=%s underline=%d (%02x, %02x)" % (color, underline, code[0], code[1])
print("MIDROW color=%s underline=%d (%02x, %02x)" %
(color, underline, code[0], code[1]))
elif part.startswith("BKG"):
parts = part.split("_")
color = parts[1]
Expand Down Expand Up @@ -273,7 +276,8 @@ def cmd_line():
from optparse import OptionParser

parser = OptionParser(usage="%prog [options] file.ccs", description="Create .scc file from .css input file")
parser.add_option('-v', '--verbosity', help='verbosity level [default: %default]', type='int', action='store', default=0, dest='verbosity_level')
parser.add_option('-v', '--verbosity', help='verbosity level [default: %default]',
type='int', action='store', default=0, dest='verbosity_level')
(opts, args) = parser.parse_args()
if len(args) != 1:
parser.print_help()
Expand Down

0 comments on commit 2856174

Please sign in to comment.