How to use the pycaption.WebVTTWriter function in pycaption

To help you get started, we’ve selected a few pycaption examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pbs / pycaption / tests / test_sami_conversion.py View on Github external
def test_sami_with_style_tags_to_webvtt_conversion(self):
        caption_set = SAMIReader().read(SAMPLE_SAMI_WITH_STYLE_TAGS)
        results = WebVTTWriter(
            video_width=640, video_height=360).write(caption_set)
        self.assertTrue(isinstance(results, six.text_type))
        self.assertWebVTTEquals(SAMPLE_WEBVTT_FROM_SAMI_WITH_STYLE, results)
github pbs / pycaption / tests / test_dfxp_conversion.py View on Github external
def test_dfxp_to_webvtt_preserves_proper_alignment(self):
        # This failed at one point when the CaptionSet had node breaks with
        # different positioning. It was fixed both at the DFXPReader AND the
        # WebVTTWriter.
        caption_set = DFXPReader().read(DFXP_STYLE_REGION_ALIGN_CONFLICT)
        results = WebVTTWriter().write(caption_set)
        self.assertEqual(
            WEBVTT_FROM_DFXP_WITH_CONFLICTING_ALIGN, results)
github pbs / pycaption / tests / test_webvtt_conversion.py View on Github external
def test_webvtt_to_webvtt_conversion(self):
        caption_set = WebVTTReader().read(SAMPLE_WEBVTT)
        results = WebVTTWriter().write(caption_set)
        self.assertTrue(isinstance(results, unicode))
        self.assertWebVTTEquals(SAMPLE_WEBVTT_FROM_WEBVTT, results)
github pbs / pycaption / tests / test_webvtt_conversion.py View on Github external
def test_positioning_is_kept(self):
        caption_set = WebVTTReader().read(
            SAMPLE_WEBVTT_FROM_DFXP_WITH_POSITIONING)
        results = WebVTTWriter().write(caption_set)
        self.assertEquals(
            SAMPLE_WEBVTT_FROM_DFXP_WITH_POSITIONING, results)
github pbs / pycaption / tests / test_srt_conversion.py View on Github external
def test_srt_to_webvtt_conversion(self):
        caption_set = SRTReader().read(SAMPLE_SRT)
        results = WebVTTWriter().write(caption_set)
        self.assertTrue(isinstance(results, six.text_type))
        self.assertWebVTTEquals(SAMPLE_WEBVTT_FROM_SRT, results)
github keredson / gnomecast / gnomecast.py View on Github external
fn = os.path.abspath(fn)
    ext = fn.split('.')[-1]
    display_name = os.path.basename(fn)
    if ext=='vtt':
      with open(fn) as f:
        self.subtitles = f.read()
    else:
      with open(fn,'rb') as f:
        caps = f.read()
        try: caps = caps.decode()
        except UnicodeDecodeError: caps = caps.decode('latin-1')
      if caps.startswith('\ufeff'): # BOM
        caps = caps[1:]
      converter = pycaption.CaptionConverter()
      converter.read(caps, pycaption.detect_format(caps)())
      self.subtitles = converter.write(pycaption.WebVTTWriter())
    pos = len(self.subtitle_store)
    stream = StreamMetadata(None, None, title=display_name)
    stream._subtitles = self.subtitles
    self.subtitle_store.append([display_name, stream, None])
    self.subtitle_combo.set_active(pos)
github keredson / gnomecast / gnomecast.py View on Github external
Python package "gi" (for building the GU not found.\n
If on Debian or Ubuntu, please run:
$ sudo apt-get install python3-gi\n
For other distributions please look up the equivalent package.\n
If this doesn't work, please report the error here:
https://github.com/keredson/gnomecast\n
Thanks! - Gnomecast
{}
"""
  print(ERROR_MESSAGE.format(line,line))
  sys.exit(1)

__version__ = '1.9.5'

if DEPS_MET:
  pycaption.WebVTTWriter._encode = lambda self, s: s


class Device:
  def __init__(self, h265=None, ac3=None):
    self.h265 = h265
    self.ac3 = ac3
    
HARDWARE = {
  ('Unknown manufacturer','Chromecast'): Device(h265=False, ac3=False),
  ('Unknown manufacturer','Chromecast Ultra'): Device(h265=True, ac3=True),
  ('Unknown manufacturer','Google Home Mini'): Device(h265=False, ac3=False),
  ('Unknown manufacturer','Google Home'): Device(h265=False, ac3=False),
  ('VIZIO','P75-F1'): Device(h265=True, ac3=True),
}
github keredson / gnomecast / gnomecast.py View on Github external
files = []
    for stream in self.subtitles:
      srt_fn = tempfile.mkstemp(suffix='.srt', prefix='gnomecast_subtitles_')[1]
      files.append(srt_fn)
      cmd += ['-map', stream.index, '-codec', 'srt', srt_fn]
      
    print(cmd)
    try:
      output = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
      for stream, srt_fn in zip(self.subtitles, files):
        with open(srt_fn) as f:
          caps = f.read()
        #print('caps', caps)
        converter = pycaption.CaptionConverter()
        converter.read(caps, pycaption.detect_format(caps)())
        stream._subtitles = converter.write(pycaption.WebVTTWriter())
        os.remove(srt_fn)
    except subprocess.CalledProcessError as e:
      print('ERROR processing subtitles:', e)
      self.subtitles = []