This repository has no description
2.4 kB
84 lines
1{ pkgs, lib, ... }:
2
3let
4 dl_subs = pkgs.writers.writeDashBin "dl_subs" ''
5 set -efu
6 filename=$1
7 cd "$(dirname "$filename")"
8 filename=$(basename "$filename")
9 ${pkgs.subdl}/bin/subdl --download=best-rating --existing=overwrite --output='/tmp/{m}.{M}.sub' "$filename" 1>&2
10 echo "/tmp/$filename.sub"
11 '';
12
13 autosub = pkgs.writeText "autosub.lua" ''
14 utils = require 'mp.utils'
15
16 -- Log function: log to both terminal and mpv OSD (On-Screen Display)
17 function log(string, secs)
18 secs = secs or 2 -- secs defaults to 2 when the secs parameter is absent
19 mp.msg.warn(string) -- This logs to the terminal
20 mp.osd_message(string, secs) -- This logs to mpv screen
21 end
22
23 function download()
24 log('Searching subtitles ...', 10)
25 path = mp.get_property('path')
26 result = utils.subprocess({ args = {"${dl_subs}/bin/dl_subs", path} })
27 if result.error == nil then
28 filename = string.gsub(result.stdout, "\n", "")
29 log(filename)
30 mp.commandv('sub_add', filename)
31 log('Subtitles ready!')
32 else
33 log('Subtitles failed downloading')
34 end
35 end
36
37 mp.add_key_binding('S', "download_subs", download)
38 '';
39
40 mpvInput = pkgs.writeText "mpv.input" ''
41 : script-binding console/enable
42 x add audio-delay -0.050
43 X add audio-delay 0.050
44 '';
45
46 mpvConfig = pkgs.writeText "mpv.conf" ''
47 osd-font-size=20
48 '';
49
50 mpv = pkgs.symlinkJoin {
51 name = "mpv";
52 paths = [
53 (pkgs.writeDashBin "mpv" ''
54 set -efu
55 Y_RES=1081
56 # we need to disable sponsorblock local database because of
57 # https://github.com/po5/mpv_sponsorblock/issues/31
58 exec ${pkgs.mpv.override {
59 scripts = with pkgs.mpvScripts; [
60 sponsorblock
61 quality-menu
62 vr-reversal
63 ];
64 }}/bin/mpv \
65 --no-config \
66 --input-conf=${mpvInput} \
67 --include=${mpvConfig} \
68 --script=${autosub} \
69 --ytdl-format="best[height<$Y_RES]" \
70 --script-opts=ytdl_hook-ytdl_path=${pkgs.yt-dlp}/bin/yt-dlp \
71 --script-opts-append=sponsorblock-local_database=no \
72 --audio-channels=2 \
73 "$@"
74 '')
75 pkgs.mpv
76 ];
77 };
78
79in {
80 environment.systemPackages = [
81 mpv
82 dl_subs
83 ];
84}