GithubHelp home page GithubHelp logo

webvtt fragments about pysubs2 HOT 9 CLOSED

tkarabela avatar tkarabela commented on June 7, 2024
webvtt fragments

from pysubs2.

Comments (9)

tkarabela avatar tkarabela commented on June 7, 2024 1

While pysubs2 has no particular support for WebVTT format at this time, the format is sufficiently similar to SRT that in simple cases, pysubs2 will read it just fine. If you just want to collect subtitles from multiple files without any retiming, that would be:

import pysubs2


input_files = [
    "subtitle_V1-0.webvtt",
    "subtitle_V1-1.webvtt",
    "subtitle_V1-2.webvtt",
    "subtitle_V1-3.webvtt",
]

output_subs = pysubs2.SSAFile()

for file in input_files:
    subs = pysubs2.load(file)
    output_subs.events.extend(subs.events)

output_subs.save("subtitle.srt")

from pysubs2.

X-C0DE avatar X-C0DE commented on June 7, 2024 1

While pysubs2 has no particular support for WebVTT format at this time, the format is sufficiently similar to SRT that in simple cases, pysubs2 will read it just fine. If you just want to collect subtitles from multiple files without any retiming, that would be:

import pysubs2


input_files = [
    "subtitle_V1-0.webvtt",
    "subtitle_V1-1.webvtt",
    "subtitle_V1-2.webvtt",
    "subtitle_V1-3.webvtt",
]

output_subs = pysubs2.SSAFile()

for file in input_files:
    subs = pysubs2.load(file)
    output_subs.events.extend(subs.events)

output_subs.save("subtitle.srt")

Thanks a lote
This way works for me

from pysubs2.

X-C0DE avatar X-C0DE commented on June 7, 2024

Hey
I tryied the same code for vtt subtitles and it not works. How can I do this to works with vtt files?

Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "/usr/local/lib/python3.6/site-packages/pysubs2/ssafile.py", line 92, in load
    return cls.from_file(fp, format_, fps=fps, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/pysubs2/ssafile.py", line 145, in from_file
    format_ = autodetect_format(fragment)
  File "/usr/local/lib/python3.6/site-packages/pysubs2/formats.py", line 62, in autodetect_format
    raise FormatAutodetectionError("No suitable formats")
pysubs2.exceptions.FormatAutodetectionError: No suitable formats

from pysubs2.

tkarabela avatar tkarabela commented on June 7, 2024

You can try to force the input format to get around autodetection:

subs = pysubs2.load("test.vtt", format_="srt")
subs.save("test.srt")

However, WebVTT is fundamentally a different format than SRT, so re-using SRT parser to load such files is a "hack". It may be necessary to implement proper WebVTT parser to read more complex files.

from pysubs2.

X-C0DE avatar X-C0DE commented on June 7, 2024

hmm
it not worked correctly. sad life

from pysubs2.

X-C0DE avatar X-C0DE commented on June 7, 2024

is it possible for me to use pysubs2 to concatenate subtitles in srt?
['sub_1.srt', 'sub_2.srt', 'sub_3.srt'] >>> subtitle.srt

from pysubs2.

tkarabela avatar tkarabela commented on June 7, 2024

Can you share the .vtt file which could not be loaded by pysubs2? I can have a look at it.

As for merging SRT files, yes you can do that:

import pysubs2

input_files = [
    "sub_1.srt",
    "sub_2.srt",
    "sub_3.srt",
]

output_subs = pysubs2.SSAFile()

for file in input_files:
    subs = pysubs2.load(file)
    output_subs.events.extend(subs.events)

output_subs.save("subtitle.srt")

from pysubs2.

X-C0DE avatar X-C0DE commented on June 7, 2024

Can you share the .vtt file which could not be loaded by pysubs2? I can have a look at it.

As for merging SRT files, yes you can do that:

import pysubs2

input_files = [
    "sub_1.srt",
    "sub_2.srt",
    "sub_3.srt",
]

output_subs = pysubs2.SSAFile()

for file in input_files:
    subs = pysubs2.load(file)
    output_subs.events.extend(subs.events)

output_subs.save("subtitle.srt")

VTT files:
vtt_files.zip
For concatenate srt files i already tryied to use this, but it not works.

from pysubs2.

tkarabela avatar tkarabela commented on June 7, 2024

I have added explicit support for VTT files into the library and successfully merged your testing files with this script:

import pysubs2
import glob

input_files = glob.glob("SUB_*.vtt")

output_subs = pysubs2.SSAFile()

for file in input_files:
    subs = pysubs2.load(file)
    output_subs.events.extend(subs.events)

output_subs.save("subtitle.srt")

I will be releasing a new version of pysubs2 shortly. Relevant changes are in commit 29629fd.

from pysubs2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.