Skip to content

Commit

Permalink
moved to the cabal build system
Browse files Browse the repository at this point in the history
  • Loading branch information
redfish64 committed May 3, 2017
1 parent 04efa55 commit b712829
Show file tree
Hide file tree
Showing 7 changed files with 255 additions and 41 deletions.
4 changes: 3 additions & 1 deletion Gui/GuiCore.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Control.Monad.Trans.Either (EitherT,left,right,runEitherT)
import System.Directory (doesFileExist)
import Control.Monad.Trans.Class(lift)
import Data.List.Split(splitOn)
import Paths_MpvLangLearn(getDataFileName)
-- import Graphics.UI.WXCore.WxcDefs
-- import Graphics.UI.WXCore.Frame
-- import Graphics.UI.WXCore.WxcClassesAL
Expand Down Expand Up @@ -82,7 +83,8 @@ simple f w =


logop <- panel p []
bm <- bitmapCreateFromFile "logo.png"
logoFile <- getDataFileName "logo.png"
bm <- bitmapCreateFromFile $ logoFile
bmsize <- get bm size
logo <- panel logop [ on paint := onPaint bm]
-- f <- fakeout p
Expand Down
29 changes: 0 additions & 29 deletions Makefile

This file was deleted.

File renamed without changes.
File renamed without changes.
60 changes: 55 additions & 5 deletions MpvLangLearn.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ name: MpvLangLearn
-- PVP summary: +-+------- breaking API changes
-- | | +----- non-breaking API additions
-- | | | +--- code changes with no API change
version: 0.1.0.0
version: 1.0.0.1

-- A short (one-line) description of the package.
synopsis: Learn a foreign language using mpv and srt files

-- A longer description of the package.
-- description:
description: Uses subtitles to loop dialog of a video with and without displaying subtitles, to help learn a foreign language. The idea is to loop the video without subtitles, so the user can try and guess what the dialog means, and then repeat with subtitles to verify his/her answer.

-- URL for the project homepage or repository.
homepage: http://rareventure.com/MpvLangLearn
Expand Down Expand Up @@ -48,10 +48,11 @@ extra-source-files: Changes
-- Constraint on the version of Cabal needed to build this package.
cabal-version: >=1.10

data-files: logo.png

executable MpvLangLearn
executable MpvLL
-- .hs or .lhs file containing the Main module.
main-is: Main.hs
main-is: MpvLL.hs

-- Modules included in this executable, other than Main.
-- other-modules:
Expand All @@ -60,7 +61,16 @@ executable MpvLangLearn
other-extensions: ForeignFunctionInterface

-- Other library packages from which modules are imported.
build-depends: base >=4.9 && <4.10, mtl >=2.2 && <2.3, deepseq >=1.4 && <1.5, split >=0.2 && <0.3, text >=1.2 && <1.3, strict, either
build-depends:
base >=4.9 && <4.10,
mtl >=2.2 && <2.3,
deepseq >=1.4 && <1.5,
split >=0.2 && <0.3,
text >=1.2 && <1.3,
either >= 4.4.1 && < 4.5,
transformers >= 0.5.2 && < 0.6,
strict >= 0.3.2 && < 0.4,
directory >= 1.3.0 && < 1.4

-- Directories containing source files.
-- hs-source-dirs:
Expand All @@ -70,4 +80,44 @@ executable MpvLangLearn

-- Base language which the package is written in.
default-language: Haskell2010

extra-libraries: mpv
c-sources: foo.c

executable MpvLLGui
-- .hs or .lhs file containing the Main module.
main-is: MpvLLGui.hs

-- Modules included in this executable, other than Main.
-- other-modules:

-- LANGUAGE extensions used by modules in this package.
other-extensions: ForeignFunctionInterface

-- Other library packages from which modules are imported.
build-depends:
base >=4.9 && <4.10,
mtl >=2.2 && <2.3,
deepseq >=1.4 && <1.5,
split >=0.2 && <0.3,
text >=1.2 && <1.3,
either >= 4.4.1 && < 4.5,
transformers >= 0.5.2 && < 0.6,
strict >= 0.3.2 && < 0.4,
directory >= 1.3.0 && < 1.4,
wx >= 0.92.2 && < 0.93,
wxcore >= 0.92.2 && < 0.93


-- Directories containing source files.
-- hs-source-dirs:

-- Extra tools (e.g. alex, hsc2hs, ...) needed to build the source.
build-tools: hsc2hs

-- Base language which the package is written in.
default-language: Haskell2010

extra-libraries: mpv
c-sources: foo.c

14 changes: 8 additions & 6 deletions doc/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ <h2>Overview</h2>
<p>Below is an example of this for a user who knows English and is trying to learn Chinese.
<img src="videoloop.svg" width="90%">
<h2>Building/Installing</h2>
<p>Mpv Lang Learn is available for Linux and Windows. Executables are available here: <a href="foo.html">foo.html</a>
<p>Source is here: <a href="http://github.com/redfish64/MpvLangLearn/">http://github.com/redfish64/MpvLangLearn/</a>
<p>In Linux, Compile with: "make" to build command line tool, and "make gui" to build gui
<p>Mpv Lang Learn is available for Linux and Windows. Windows Executables are available here: <a href="https://github.com/redfish64/MpvLangLearn/releases/latest">https://github.com/redfish64/MpvLangLearn/releases/latest</a>
<p>Source is here: <a href="http://github.com/redfish64/MpvLangLearn/">https://github.com/redfish64/MpvLangLearn/</a>
<p>In Linux, you need <a href="https://www.haskell.org/ghc/">ghc</a>, and the development library files for <a href="https://mpv.io/">mpv</a>.
See <a href="https://wiki.haskell.org/Cabal/How_to_install_a_Cabal_package">https://wiki.haskell.org/Cabal/How_to_install_a_Cabal_package</a> for how to install.
<h2>Running</h2>
<p>Command line can be invoked as follows:
<pre>MpvLL &lt;srt tracks...&gt; -- &lt;track number or none&gt;[:&lt;speed&gt;[:&lt;lead padding&gt;:&lt;trailing padding&gt;]]] -- [mpv options] &lt;video file&gt;</pre>
Expand All @@ -22,8 +23,9 @@ <h2>Running</h2>
<p>This would show the video "rtrl.avi" using subtitle tracks, "rtrl-ZN.srt" and "rtrl-EN.srt". First no subtitles would be shown (because "none" was specified), then a loop with subtitles from track 1, "rtrl-ZN.srt",
and finally with subtitles from track 2, "rtrl-EN.srt"
<h2>Other notes</h2>
It's very important that subtitle files loaded line up with each other and the dialog of the movie. If not, the loops will not occur at the right times.
<There are various programs on the web to do this. Just search the web for "subtitle editor".
<p>Alternatively, you can use the 'x' and the 'z' keys within mpv to adjust the subtitle delay on the fly. Note that this will not align two different subtitle files,
<p>It's very important that subtitle files loaded line up with each other and the dialog of the movie. If not, the loops will not occur at the right times.
<There are various programs on the web to do this. Just search the web for "subtitle editor".</p>
<p>You can use the 'x' and the 'z' keys within mpv to adjust the subtitle delay on the fly. Note that this will not align two different subtitle files,
so if you are trying to use a native and a foreign language subtitle file together, and they are not aligned, you will have to edit one or the other.
There are several subtitle editor programs available on the web to do this. You can also use the included, srt_fixer.pl program to do this. However, the interface is rather cryptic. </p>
</body>
189 changes: 189 additions & 0 deletions srt_fixer.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
#!/usr/bin/perl

while(@ARGV)
{
$a = $ARGV[0];

if($a eq "-srt1")
{
shift @ARGV;
$srt1 = shift @ARGV;;
}

elsif($a eq "-fs")
{
shift @ARGV;
$fs = shift @ARGV;;
}

elsif($a eq "-srt2")
{
shift @ARGV;
$srt2 = shift @ARGV;;
}

elsif($a eq "-video_delay1")
{
shift @ARGV;
$vd1 = shift @ARGV;;
}

elsif($a eq "-video_delay2")
{
shift @ARGV;
$vd2 = shift @ARGV;;
}
elsif($a eq "-vt1")
{
shift @ARGV;
$vt1 = shift @ARGV;;
}

elsif($a eq "-vt2")
{
shift @ARGV;
$vt2 = shift @ARGV;;
}
elsif($a eq "-m")
{
shift @ARGV;
$m = shift @ARGV;;
}
elsif($a eq "-k")
{
shift @ARGV;
$k = shift @ARGV;;
}
elsif($a eq "-pin")
{
shift @ARGV;
$pin = shift @ARGV;;
}
else {
last; }
}

if((!defined $srt1 || !defined $srt2 ||
(!defined $vd1 || !defined $vd2) &&
(!defined $vt1 || !defined $vt2))
&& (!defined $m || (!defined $k && !defined $pin)))
{
print "Usage: $0 -fs <framespeed (only needed for MicroDvd subs) -srt1 <srt first time hh:mm:ss.sub, mm:ss.sub, ss.sub, etc.> \n";
print " -srt2 <srt second time mm:ss or ss>\n";
print " -video_delay1 <video delay 1 mm:ss or ss>\n";
print " -video_delay2 <video delay 2 mm:ss or ss>\n";
print " -vt1 <video time 1 mm:ss or ss>\n";
print " -vt2 <video time 2 mm:ss or ss>\n";
print "or -m <multiplier> -k <addition>\n";
exit 1;
}

foreach $v (\$srt1, \$srt2, \$vd1, \$vd2, \$vt1, \$vt2, \$pin, \$fs)
{
if($$v =~ /(-?)([0-9]{1,3}):([0-9]{1,3}):([0-9]{2})([.,]([0-9]*))?/)
{
$$v = $2 * 3600 + $3 * 60 + $4 + (".".$6);
if($1 eq "-")
{
$$v = - $$v;
}
}
if($$v =~ /(-?)([0-9]{1,3}):([0-9]{2})([.,]([0-9]*))?/)
{
$$v = $2 * 60 + $3 + (".".$5);
if($1 eq "-")
{
$$v = - $$v;
}
}
}

if(!defined $vt1)
{
$vt1 = $srt1 + $vd1;
$vt2 = $srt2 + $vd2;
}

if(!defined $m)
{
$m = -(-$vt1 + $vt2)/($srt1 - $srt2);
$k = -($srt2 * $vt1 - $srt1 * $vt2)/($srt1 - $srt2);
}

if(!defined $k)
{
print STDERR "Adjusting: m = $m, pin = $pin secs\n";
}
else
{
print STDERR "Adjusting: m = $m, k = $k secs\n";
}

if($m < 0)
{
die "m is less than zero?";
}

my $mode;
while(<>)
{
$t1 = $t2 = undef;

if($_ =~ /([0-9]{2}):([0-9]{2}):([0-9]{2}),([0-9]{3}) --> ([0-9]{2}):([0-9]{2}):([0-9]{2}),([0-9]{3})/)
{
$t1 = $1 * 60 * 60 + $2 * 60 + $3 + $4 / 1000.;
$t2 = $5 * 60 * 60 + $6 * 60 + $7 + $8 / 1000.;
$mode = 0;
}
#{3569}{3654}Command station, this is ST-321.|Code clearance blue.
elsif($_ =~ /^\{([0-9]+)\}\{([0-9]+)\}(.*)/)
{
die "Must specify framespeed!" if !defined $fs;
$t1 = $1 / $fs;
$t2 = $2 / $fs;
$mode = 1;
$msg = $3;
}

# print "$t1, $t2\n";
if(defined $t1)
{
if(!defined $k)
{
$k = ($pin / $m - $t1) * $m;
print STDERR "Adjusting: k = $k secs\n";
}

$t1 = $t1 * $m + $k;
$t2 = $t2 * $m + $k;

use POSIX;
# print "$t1, $t2\n";

if($mode == 0)
{
printf("%02d:%02d:%02d,%03d --> %02d:%02d:%02d,%03d\r\n",
POSIX::floor($t1 / 3600),
POSIX::floor($t1 % 3600 / 60),
POSIX::floor($t1 % 60),
POSIX::floor($t1 * 1000 % 1000),
POSIX::floor($t2 / 3600),
POSIX::floor($t2 % 3600 / 60),
POSIX::floor($t2 % 60),
POSIX::floor($t2 * 1000 % 1000));
}
else
{
printf("{%d}{%d}%s\n",$t1*$fs,$t2*$fs,$msg);
}
}
elsif($_ =~ /^[0-9]+$/)
{
print ++$i."\r\n";
}
else
{
print $_;
}
}

0 comments on commit b712829

Please sign in to comment.