Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Oct 18, 2019
Merged

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

merged 2 commits into from
Oct 18, 2019

Conversation

omerholz
Copy link
Contributor

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 glut23 merged commit 8f6a4ea into glut23:master Oct 18, 2019
@glut23
Copy link
Owner

glut23 commented Oct 18, 2019

Thanks for that @omerholz !

@sdavids13
Copy link

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
Copy link
Owner

glut23 commented Nov 14, 2019

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

@glut23
Copy link
Owner

glut23 commented Nov 22, 2019

Hi @sdavids13 I just released 0.4.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants