glut23 / webvtt-py

Read, write, convert and segment WebVTT caption files in Python.
MIT License
192 stars 56 forks source link

let the parser read content either from a file or from a file-like object #23

Closed omerholz closed 5 years ago

omerholz commented 5 years ago

reading and loading the WebVTT content are coupled. As a result, if the webvtt content to parse is not on the file system, we need to put it to the file system for the parser to be able to load it. This PR decouples these 2 functions. It keeps full backward compatibility, including for "internal" methods prefixed with _. With the addition of read_buffer method to the WebVTT class, this PR adds support for parsing any kind of file-like object:

import webvtt
import requests
from io import StringIO

payload = requests.get('http://subtitles.com/1234.vtt').text()
buffer = StringIO(payload)
for caption in webvtt.read_buffer(buffer):
    print(caption.start)
    print(caption.end)
    print(caption.text)
glut23 commented 5 years ago

Thanks for that @omerholz !

sdavids13 commented 4 years ago

Any plans on publishing a new version of this library to pypi? Having this particular PR integrated would be extremely helpful for me... Thanks!

glut23 commented 4 years ago

Hi @sdavids13 I was planning to do that. I will publish it soon. Thanks!

glut23 commented 4 years ago

Hi @sdavids13 I just released 0.4.3.