summaryrefslogtreecommitdiffstats
path: root/lass/2configs
diff options
context:
space:
mode:
authorlassulus <git@lassul.us>2023-07-02 19:43:23 +0200
committerlassulus <git@lassul.us>2023-07-02 19:50:23 +0200
commit0660f1de491c1da0c5fb35052c1af6d71ce3acf7 (patch)
tree9ad213e4f311a4d6937c8b6e880f454b52dc083a /lass/2configs
parente9ed4ea7ed2a35599e9b83f87b0e543cab782907 (diff)
l mpv autosub: switch to subdl
Diffstat (limited to 'lass/2configs')
-rw-r--r--lass/2configs/mpv.nix32
1 files changed, 7 insertions, 25 deletions
diff --git a/lass/2configs/mpv.nix b/lass/2configs/mpv.nix
index f88d0d91d..558070940 100644
--- a/lass/2configs/mpv.nix
+++ b/lass/2configs/mpv.nix
@@ -1,28 +1,10 @@
{ pkgs, lib, ... }:
let
-
- download_subs = pkgs.writers.writePython3 "download_sub" {
- libraries = [ pkgs.python3Packages.subliminal ];
- } ''
- from subliminal import download_best_subtitles, scan_video
- from babelfish import Language
- import sys
-
- video_filename = sys.argv[1]
-
- vid = scan_video(video_filename)
- try:
- sub = download_best_subtitles([vid], {Language('eng')})[vid][0]
-
- filename = '/tmp/' + vid.title + '.srt'
-
- with open(filename, 'wb+') as file:
- file.write(sub.content)
-
- print(filename)
- except: # noqa
- print("/dev/null")
+ dl_subs = pkgs.writers.writeDashBin "dl_subs" ''
+ filename=$1
+ ${pkgs.subdl}/bin/subdl --output='/tmp/{m}.{M}.sub' "$filename" 1>&2
+ echo "/tmp/$(basename "$filename").sub"
'';
autosub = pkgs.writeText "autosub.lua" ''
@@ -39,10 +21,9 @@ let
function download()
log('Searching subtitles ...', 10)
- table = { args = {"${download_subs}", mp.get_property('path')} }
- result = utils.subprocess(table)
+ path = mp.get_property('path')
+ result = utils.subprocess({ args = {"${dl_subs}/bin/dl_subs", path} })
if result.error == nil then
- -- remove trailing newline from subtitle filename
filename = string.gsub(result.stdout, "\n", "")
log(filename)
mp.commandv('sub_add', filename)
@@ -122,5 +103,6 @@ let
in {
environment.systemPackages = [
mpv
+ dl_subs
];
}