Giter Club home page Giter Club logo

pwsh-srt's Introduction

Powershell tools for manipulating subtitle files (.srt)

This module contains a few methods for easy manipulation of subtitle text files.

Manual installation

Clone this repository and import the module.

PS> git clone 'https://git.beverli.net/bvli/pwsh-srt'
PS> Import-Module './pwsh-srt'

Examples of usage

Add an offset to all entries in file

This is probaly the most needed capability of the toolset. We all know the situation where we're going to watch a movie, and then the subtitles appears 10 seconds before the dialog. This is exactly why this toolset was created. So find the offset by timing the difference between when the dialog appear and the subtitle appear by watching the movie and let's fix it. If you want the titles to appear ealier use a negative number, if you want them to appear later, use a positive number.

PS> Get-Content -Path 'Pretty Woman (1990).en.srt' | 
    ConvertFrom-Srt | 
    Add-SrtTimeDifference -MilliSeconds -500 | 
    ConvertTo-Srt | 
    Out-File '.\Pretty Woman (1990).en.fixed.srt'

Remove first subtitle entry

Sometimes the first few entries in a subtitle file contains ads or other information, you don't want to have in the file. It's quite easy to delete these, while still keeping the sequence in sync.

PS> Get-Content -Path 'Pretty Woman (1990).en.srt' | 
    ConvertFrom-Srt | 
    Select-Object -Skip 1 | 
    ConvertTo-Srt |
    Out-File -Path 'Pretty Woman (1990).en.no-ads.srt'

Insert a subtitle entry

If you want to be one of the annoying persons, adding entries to a subtitle file (you don't!) then it's quite easy as well:

PS> @('0', '00:00:00,000 --> 00:00:02,000', 'Manipulated by pwsh-srt', '© bvli, 2021', '') + (cat '.\Pretty Woman (1990).en.srt') | 
    ConvertFrom-Srt | 
    ConvertTo-Srt | 
    Out-File -Path '.\Pretty Woman (1990).en.ads.srt'

The sequence number of the inserted entry is not important here, as the ConvertTo-Srt cmdlet will handle the sequencing when converting back to the srt file format.

Automate it

Of course you can mix and match as you'd like - and probably do it all in a one-liner of you prefer. Just remember to take file encodings into consideration when working with subtitles with special characters. (So please backup your original file before trying to manipulate it in a single go)

    $FileName = 'Pretty Woman (1990).en.srt'
    (Get-Content -Path $FileName | 
        ConvertFrom-Srt | 
        Select-Object -Skip 1 |
        Add-SrtTimeDifference -Seconds 15
        ConvertTo-Srt) | 
    Out-File -Path $FileName

pwsh-srt's People

Contributors

bvli avatar

Stargazers

 avatar  avatar  avatar

Watchers

 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.