Skip to content

Instantly share code, notes, and snippets.

@Mozk0
Created January 23, 2012 07:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Mozk0/1661402 to your computer and use it in GitHub Desktop.
Save Mozk0/1661402 to your computer and use it in GitHub Desktop.
統合TVのネタバレスーパーを生成する。
import System.Environment (getArgs)
import Control.Monad (mapM_)
import Data.Functor ((<$>))
import Data.String.Utils (replace) -- missingH
import System.IO.UTF8 (putStrLn, readFile) -- utf8-string
import Prelude hiding (putStrLn, readFile)
main :: IO ()
main = main' =<< getArgs
main' :: [String] -> IO ()
main' (hukidashiFile : timeFile : date : []) = do
hukidashi <- lines <$> readFile hukidashiFile :: IO [String]
exactTime <- map read . lines <$> readFile timeFile :: IO [Double]
roundedTime <- return $ map round exactTime :: IO [Int]
mapM_ putStrLn $ prefix
mapM_ putStrLn $ map (format date) $ hukidashi `zip` roundedTime
mapM_ putStrLn $ postfix
main' _ = putStrLn "Usage: format hukidashiFile timeFile date"
prefix :: [String]
prefix = [" <%= netabare_start 'ここを押すと動画のスーパーが読めます。', 'button' %>", " <blockquote>"]
format :: String -> (String, Int) -> String
format date (str, t) = " <%= a \"" ++ escape str ++ " (" ++ formatTime t ++ ")|http://togotv.dbcls.jp/20" ++ date ++ ".html?" ++ jumpTime t ++ "#p01\" %>"
where
formatTime :: Int -> String
formatTime t = show (t `div` 60) ++ "分" ++ show (t `rem` 60) ++ "秒"
escape :: String -> String
escape = replace "\"" "\\\"" . replace "\\" "\\\\"
jumpTime :: Int -> String
jumpTime t = show $ (t - 2) `max` 0
postfix :: [String]
postfix = [" </blockquote>", " <%= netabare_end %>"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment