Giter VIP home page Giter VIP logo

Comments (7)

byroot avatar byroot commented on September 23, 2024

Hi,

Pysrt is not supposed to raise a ValueError like that. On that kind of parsing error it should raise a pysrt.InvalidItem.
It's a bug so I will fix it ASAP.

About the is_valid method: the only way to now if a SubRip file is properly formated is to parse it, so it will be just an alias of open that catch the exception and return Trueor False. I don't think that it's really useful. And it could be misleading because you can fail to parse a properly formatted file for an encoding reason.

from pysrt.

Diaoul avatar Diaoul commented on September 23, 2024

Anyway, if that raises a InvalidItemError that's ok for me :)

from pysrt.

byroot avatar byroot commented on September 23, 2024

It will in a few minutes.

from pysrt.

byroot avatar byroot commented on September 23, 2024

Both pysrt 0.4.2 and pysrt3 0.4.2have been released with the fix.

Note that in your case you should catch the base exception pysrt.Error https://github.com/byroot/pysrt/blob/master/pysrt/srtexc.py

from pysrt.

Diaoul avatar Diaoul commented on September 23, 2024

This is a partial solution because I still can't validate the structure of the file only and have to validate both the structure of the file and encoding.
I don't care about encoding so I'd like to be able to use this https://github.com/byroot/pysrt/blob/master/pysrt/srtfile.py#L267 :

source_file = codecs.open(path, 'rU', encoding=encoding, errors='replace')

For now, pysrt doesn't allow that.

from pysrt.

byroot avatar byroot commented on September 23, 2024

You can give any file like object to pysrt:

source_file = codecs.open(path, 'rU', encoding=encoding, errors='replace')
try:
  for item in pysrt.SubRipFile.stream(source_file, error_handling=SubRipFile.ERROR_RAISE):
    pass
except pysrt.Error:
  valid = False
else:
  valid = True

But allowing to specify errors='replace' is a good idea. I will surely add it to pysrt soon.

from pysrt.

Diaoul avatar Diaoul commented on September 23, 2024

Right, didn't thought of this option. Thanks

from pysrt.

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.