Skip to content

Commit 75e6bdf

Browse files
committed
add vttclean overlay
1 parent 47dee11 commit 75e6bdf

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

flake.nix

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
seder = callPackage ./packages/seder.nix { };
4343
srtcpy = callPackage ./packages/srtcpy.nix { };
4444
transcribe = callPackage ./packages/transcribe.nix { };
45+
vttclean = haskell.packages.ghc965.callCabal2nix "" ./vttclean { };
4546
};
4647

4748
in {

vttclean/Main.hs

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{-# OPTIONS_GHC -Wno-name-shadowing #-}
2+
3+
module Main where
4+
5+
import qualified Control.Foldl as Fold
6+
import Data.Char
7+
import Data.Text.IO
8+
import Options.Applicative
9+
import Turtle hiding (header)
10+
import Prelude hiding (putStrLn)
11+
12+
main :: IO ()
13+
main = do
14+
file <- execParser parserInfo
15+
sh $ do
16+
t <- shellThing . runFile $ file
17+
liftIO . putStrLn $ t
18+
19+
shellThing :: FilePath -> Shell Text
20+
shellThing f = do
21+
lines <- fold (cleanFile f) Fold.list
22+
pure . linesToText $ lines
23+
24+
cleanFile :: FilePath -> Shell Line
25+
cleanFile f = uniq . grep keepLines $ input f
26+
27+
keepLines :: Pattern String
28+
keepLines = satisfy isLetter >> some keepChars
29+
30+
keepChars :: Pattern Char
31+
keepChars = satisfy f
32+
where
33+
f c = isLetter c || isSpace c || c == '\''
34+
35+
-------------------------------------------------------------
36+
-- CLI Parser
37+
newtype FileInput = File {runFile :: FilePath}
38+
39+
parserInfo :: ParserInfo FileInput
40+
parserInfo =
41+
info
42+
(cliParser <**> helper)
43+
( fullDesc
44+
<> progDesc "print parsed vtt output"
45+
<> header "basic parser for youtube vtt files"
46+
)
47+
48+
cliParser :: Parser FileInput
49+
cliParser =
50+
File
51+
<$> strOption
52+
( long "file"
53+
<> metavar "file"
54+
<> help "vtt input file"
55+
<> short 'f'
56+
)

vttclean/vttclean.cabal

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
cabal-version: 3.0
2+
name: vttclean
3+
version: 0.1.0.0
4+
license: MIT
5+
build-type: Simple
6+
7+
common warnings
8+
ghc-options: -Wall
9+
default-language: Haskell2010
10+
default-extensions: NoStarIsType
11+
12+
executable vttclean
13+
import: warnings
14+
main-is: Main.hs
15+
build-depends:
16+
, base ^>=4.18.2.1
17+
, foldl
18+
, optparse-applicative
19+
, text
20+
, turtle

0 commit comments

Comments
 (0)