feat(subtitles): package sc0ty/subsync
All checks were successful
Discord / discord commits (push) Has been skipped
All checks were successful
Discord / discord commits (push) Has been skipped
This commit is contained in:
parent
f47047a58e
commit
7c9af8ebdd
7 changed files with 256 additions and 0 deletions
|
@ -14,6 +14,7 @@ in {
|
|||
./modules/qbittorrent
|
||||
./modules/snapraid.nix
|
||||
./modules/subtitles/sub-clean.nix
|
||||
./modules/subtitles/subsync
|
||||
];
|
||||
|
||||
vars = {
|
||||
|
|
45
devices/nos/modules/subtitles/subsync/default.nix
Normal file
45
devices/nos/modules/subtitles/subsync/default.nix
Normal file
|
@ -0,0 +1,45 @@
|
|||
{
|
||||
config,
|
||||
pkgs,
|
||||
...
|
||||
}: let
|
||||
inherit (config.vars) mainUser;
|
||||
|
||||
sphinxbase = pkgs.callPackage ./sphinxbase.nix {};
|
||||
pocketsphinx = pkgs.callPackage ./pocketsphinx.nix {inherit sphinxbase;};
|
||||
subsync = pkgs.callPackage ./subsync.nix {inherit sphinxbase pocketsphinx;};
|
||||
in {
|
||||
systemd = {
|
||||
services.subsync-job = {
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
User = mainUser;
|
||||
Group = config.users.users.${mainUser}.group;
|
||||
};
|
||||
|
||||
path = with pkgs; [
|
||||
findutils
|
||||
subsync
|
||||
(writeShellApplication {
|
||||
name = "sync-sub";
|
||||
runtimeInputs = [subsync];
|
||||
text = ''
|
||||
# TODO: sync on a specific file
|
||||
# $1 = file path
|
||||
'';
|
||||
})
|
||||
];
|
||||
|
||||
script = ''
|
||||
find /data/anime -name '*.srt' -exec sync-sub "{}" \;
|
||||
find /data/movies -name '*.srt' -exec sync-sub "{}" \;
|
||||
find /data/tv -name '*.srt' -exec sync-sub "{}" \;
|
||||
'';
|
||||
};
|
||||
timers.subsync-job = {
|
||||
wantedBy = ["timers.target"];
|
||||
partOf = ["subsync-job.service"];
|
||||
timerConfig.OnCalendar = ["0:00:00"];
|
||||
};
|
||||
};
|
||||
}
|
65
devices/nos/modules/subtitles/subsync/patches/cmd_ln.patch
Normal file
65
devices/nos/modules/subtitles/subsync/patches/cmd_ln.patch
Normal file
|
@ -0,0 +1,65 @@
|
|||
diff --git a/gizmo/media/speechrec.h b/gizmo/media/speechrec.h
|
||||
index de7a932..076c8fe 100644
|
||||
--- a/gizmo/media/speechrec.h
|
||||
+++ b/gizmo/media/speechrec.h
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "text/words.h"
|
||||
#include <pocketsphinx.h>
|
||||
#include <string>
|
||||
+#include <util/cmd_ln.h>
|
||||
|
||||
|
||||
class SpeechRecognition : public AVOutput
|
||||
|
||||
diff --git a/gizmo/media/speechrec.cpp b/gizmo/media/speechrec.cpp
|
||||
index 4fe0bf7..fd041b9 100644
|
||||
--- a/gizmo/media/speechrec.cpp
|
||||
+++ b/gizmo/media/speechrec.cpp
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "general/exception.h"
|
||||
#include <cstring>
|
||||
#include <cstdint>
|
||||
+#include <util/cmd_ln.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -30,28 +31,13 @@ SpeechRecognition::~SpeechRecognition()
|
||||
|
||||
void SpeechRecognition::setParam(const string &key, const string &val)
|
||||
{
|
||||
- arg_t const *args = ps_args();
|
||||
+ ps_arg_t const *args = ps_args();
|
||||
|
||||
for (size_t i = 0; args[i].name != NULL; i++)
|
||||
{
|
||||
if (key == args[i].name)
|
||||
{
|
||||
- int type = args[i].type;
|
||||
- if (type & ARG_INTEGER)
|
||||
- cmd_ln_set_int_r(m_config, key.c_str(), atol(val.c_str()));
|
||||
- else if (type & ARG_FLOATING)
|
||||
- cmd_ln_set_float_r(m_config, key.c_str(), atof(val.c_str()));
|
||||
- else if (type & ARG_STRING)
|
||||
- cmd_ln_set_str_r(m_config, key.c_str(), val.c_str());
|
||||
- else if (type & ARG_BOOLEAN)
|
||||
- cmd_ln_set_boolean_r(m_config, key.c_str(),
|
||||
- !(val.empty() || val == "0"));
|
||||
- else
|
||||
- throw EXCEPTION("invalid parameter type")
|
||||
- .module("SpeechRecognition", "setParameter")
|
||||
- .add("parameter", key)
|
||||
- .add("value", val)
|
||||
- .add("type", type);
|
||||
+ cmd_ln_set_str_extra_r(m_config, key.c_str(), val.c_str());
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -89,7 +75,7 @@ void SpeechRecognition::start(const AVStream *stream)
|
||||
throw EXCEPTION("can't init Sphinx engine")
|
||||
.module("SpeechRecognition", "ps_init");
|
||||
|
||||
- int32_t frate = cmd_ln_int32_r(m_config, "-frate");
|
||||
+ int32_t frate = ((cmd_ln_access_r(m_config, "-frate"))->val).fl;
|
||||
m_framePeriod = 1.0 / (double)frate;
|
||||
|
||||
if (frate == 0)
|
25
devices/nos/modules/subtitles/subsync/patches/cstdint.patch
Normal file
25
devices/nos/modules/subtitles/subsync/patches/cstdint.patch
Normal file
|
@ -0,0 +1,25 @@
|
|||
diff --git a/gizmo/text/utf8.h b/gizmo/text/utf8.h
|
||||
index 7c3bcdb..99f1a92 100644
|
||||
--- a/gizmo/text/utf8.h
|
||||
+++ b/gizmo/text/utf8.h
|
||||
@@ -2,6 +2,7 @@
|
||||
#define __UTF8_H__
|
||||
|
||||
#include <string>
|
||||
+#include <cstdint>
|
||||
|
||||
|
||||
class Utf8
|
||||
|
||||
diff --git a/gizmo/text/ssa.h b/gizmo/text/ssa.h
|
||||
index 66d9918..170e265 100644
|
||||
--- a/gizmo/text/ssa.h
|
||||
+++ b/gizmo/text/ssa.h
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <string>
|
||||
+#include <cstdint>
|
||||
|
||||
|
||||
class SSAParser
|
26
devices/nos/modules/subtitles/subsync/pocketsphinx.nix
Normal file
26
devices/nos/modules/subtitles/subsync/pocketsphinx.nix
Normal file
|
@ -0,0 +1,26 @@
|
|||
{
|
||||
cmake,
|
||||
fetchFromGitHub,
|
||||
pkg-config,
|
||||
sphinxbase,
|
||||
stdenv,
|
||||
...
|
||||
}:
|
||||
stdenv.mkDerivation rec {
|
||||
name = "pocketsphinx";
|
||||
version = "unstable";
|
||||
|
||||
src = fetchFromGitHub {
|
||||
owner = "cmusphinx";
|
||||
repo = "pocketsphinx";
|
||||
rev = "7be89aae3e76568e02e4f3d41cf1adcb7654430c";
|
||||
hash = "sha256-imrwUIpORpfInitVjU11SKPPpjvObKyfI8IB4f41hfY=";
|
||||
};
|
||||
|
||||
buildInputs = [pkg-config];
|
||||
nativeBuildInputs = [cmake sphinxbase];
|
||||
|
||||
postFixup = ''
|
||||
cp -ar ${src}/src/util $out/include
|
||||
'';
|
||||
}
|
28
devices/nos/modules/subtitles/subsync/sphinxbase.nix
Normal file
28
devices/nos/modules/subtitles/subsync/sphinxbase.nix
Normal file
|
@ -0,0 +1,28 @@
|
|||
{
|
||||
autoreconfHook,
|
||||
bison,
|
||||
fetchFromGitHub,
|
||||
pkg-config,
|
||||
python3,
|
||||
stdenv,
|
||||
swig2,
|
||||
...
|
||||
}:
|
||||
stdenv.mkDerivation {
|
||||
name = "sphinxbase";
|
||||
version = "unstable";
|
||||
|
||||
buildInputs = [bison pkg-config python3 swig2];
|
||||
nativeBuildInputs = [autoreconfHook];
|
||||
|
||||
autoreconfPhase = ''
|
||||
./autogen.sh
|
||||
'';
|
||||
|
||||
src = fetchFromGitHub {
|
||||
owner = "cmusphinx";
|
||||
repo = "sphinxbase";
|
||||
rev = "617e53691889336a482631380f75b453445d0dae";
|
||||
hash = "sha256-w/Huz4+crTzdiSyQVAx0h3lhtTTrtPyKp3xpQD5EG9g=";
|
||||
};
|
||||
}
|
66
devices/nos/modules/subtitles/subsync/subsync.nix
Normal file
66
devices/nos/modules/subtitles/subsync/subsync.nix
Normal file
|
@ -0,0 +1,66 @@
|
|||
{
|
||||
fetchFromGitHub,
|
||||
ffmpeg,
|
||||
pkg-config,
|
||||
pocketsphinx,
|
||||
python3Packages,
|
||||
sphinxbase,
|
||||
...
|
||||
}: let
|
||||
inherit (builtins) concatStringsSep;
|
||||
in
|
||||
python3Packages.buildPythonPackage {
|
||||
pname = "subsync";
|
||||
version = "unstable";
|
||||
|
||||
src = fetchFromGitHub {
|
||||
owner = "sc0ty";
|
||||
repo = "subsync";
|
||||
rev = "8e0cf71960b9a5418acb60a1910cf3295d67e6bf";
|
||||
hash = "sha256-jUur1U1yNShQx70/mj36+sGoVk8+E5hQUV/G79q2A2k=";
|
||||
};
|
||||
|
||||
buildInputs = [
|
||||
ffmpeg
|
||||
pkg-config
|
||||
pocketsphinx
|
||||
sphinxbase
|
||||
];
|
||||
|
||||
nativeBuildInputs = with python3Packages; [
|
||||
pip
|
||||
setuptools
|
||||
wheel
|
||||
];
|
||||
|
||||
propagatedBuildInputs = with python3Packages; [
|
||||
certifi
|
||||
cryptography
|
||||
pybind11
|
||||
pycryptodome
|
||||
pysubs2
|
||||
pyyaml
|
||||
requests
|
||||
utils
|
||||
];
|
||||
|
||||
patches = [
|
||||
./patches/cmd_ln.patch
|
||||
./patches/cstdint.patch
|
||||
];
|
||||
|
||||
# The tests are for the GUI
|
||||
doCheck = false;
|
||||
|
||||
# 'pip install .' takes care of building the package
|
||||
buildPhase = "";
|
||||
|
||||
installPhase = ''
|
||||
python -m pip install . ${concatStringsSep " " [
|
||||
"--no-index"
|
||||
"--no-warn-script-location"
|
||||
"--prefix=\"$out\""
|
||||
"--no-cache"
|
||||
]}
|
||||
'';
|
||||
}
|
Loading…
Reference in a new issue