Giter VIP home page Giter VIP logo

subby's Introduction

Subby

Advanced subtitle converter and processor.

Supported formats

WebVTT, DFXP/TTML/TTML2/SMPTE, SAMI, WVTT (WebVTT in MP4), STPP/ISMT (DFXP in MP4)

Functionality

  • converts supported input format to SRT
  • retains select formatting tags (italics, basic \an8 positioning)
  • corrects often found flaws in subtitles
  • opinionated timing and formatting improvements

Installation

git clone https://github.com/vevv/subby
cd subby
pip install .

Usage notes

CommonIssuesFixer should be ran after conversion and SDH stripping as it's designed to fix source issues, including ones which can cause playback problems.

Command line usage

Usage: subby [OPTIONS] COMMAND [ARGS]...

  Subby—Advanced Subtitle Converter and Processor.

Options:
  -d, --debug  Enable DEBUG level logs.
  --help       Show this message and exit.

Commands:
  convert  Convert a Subtitle to SubRip (SRT).
  process  SubRip (SRT) post-processing.
  version  Print version information.

Library usage

Converter

from subby import WebVTTConverter
from pathlib import Path

converter = WebVTTConverter()
file = Path('test.vtt')

# All statements below are equivalent
srt = converter.from_file(file)
srt = converter.from_string(file.read_text())
srt = converter.from_bytes(file.read_bytes())

# srt is pysrt.SubRipFile

output = Path('file.srt')
srt.save(output)
# saved to file.srt

Processor

Processor returns a bool indicating success - whether any changes were made, useful for determining if SDH subtitles should be saved.

from subby import CommonIssuesFixer
from pathlib import Path

processor = CommonIssuesFixer()
file = Path('test.vtt')

# All statements below are equivalent
srt, status = processor.from_file(file)
srt, status = processor.from_string(file.read_text())
srt, status = processor.from_bytes(file.read_bytes())

# srt is pysrt.SubRipFile, status is bool

output = Path('test_fixed.srt')
srt.save(output)
# saved to test_fixed.srt

Chaining

The following example will convert a VTT file, attempt to strip SDH, and then save the result.

from subby import WebVTTConverter, CommonIssuesFixer, SDHStripper
from pathlib import Path

converter = WebVTTConverter()
fixer = CommonIssuesFixer()
stripper = SDHStripper()

file = Path('file.vtt')
file_sdh = Path('file_sdh.srt')
file_stripped = Path('file_stripped.srt')
srt, _ = fixer.from_srt(converter.from_file(file))

srt.save(file_sdh)
# saved to file_sdh.srt

stripped, status = stripper.from_srt(srt)
if status is True:
    print('stripping successful')
    stripped.save(file_stripped)
    # saved to file_stripped.srt

Contributors

subby's People

Contributors

vevv avatar rlaphoenix avatar varyg1001 avatar

Stargazers

 avatar

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.