summaryrefslogtreecommitdiffstats
path: root/lass/2configs
diff options
context:
space:
mode:
authormakefu <github@syntax-fehler.de>2020-03-19 13:16:27 +0100
committermakefu <github@syntax-fehler.de>2020-03-19 13:16:27 +0100
commit2761a90fbb4747a473c792060e258088a1749263 (patch)
tree457af539332b3ab299b55f52fe1fbf5195044178 /lass/2configs
parentcbd9b1923236566893f12a9ce96bec7c9f59fcda (diff)
parent2ec1535de5c3e751d2c98952d0f2eeb80d1d2e1e (diff)
Merge remote-tracking branch 'lass/master'
Diffstat (limited to 'lass/2configs')
-rw-r--r--lass/2configs/games.nix2
-rw-r--r--lass/2configs/mpv.nix75
2 files changed, 75 insertions, 2 deletions
diff --git a/lass/2configs/games.nix b/lass/2configs/games.nix
index c0e6beba4..63bfa53e0 100644
--- a/lass/2configs/games.nix
+++ b/lass/2configs/games.nix
@@ -65,7 +65,7 @@ in {
createHome = true;
useDefaultShell = true;
packages = with pkgs; [
- minecraft
+ # minecraft
steam-run
scummvm
dolphinEmu
diff --git a/lass/2configs/mpv.nix b/lass/2configs/mpv.nix
index b3de42c7b..7dc43a9ee 100644
--- a/lass/2configs/mpv.nix
+++ b/lass/2configs/mpv.nix
@@ -2,11 +2,84 @@
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)
+ 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)
+ '';
+
+ autosub = pkgs.writeText "autosub.lua" ''
+ -- Requires Subliminal version 1.0 or newer
+ -- Make sure to specify your system's Subliminal location below:
+ local utils = require 'mp.utils'
+
+ -- Log function: log to both terminal and mpv OSD (On-Screen Display)
+ function log(string, secs)
+ secs = secs or 2 -- secs defaults to 2 when the secs parameter is absent
+ mp.msg.warn(string) -- This logs to the terminal
+ mp.osd_message(string, secs) -- This logs to mpv screen
+ end
+
+ function download()
+ log('Searching subtitles ...', 10)
+ table = { args = {"${download_subs}", mp.get_property('path')} }
+ result = utils.subprocess(table)
+ if result.error == nil then
+ -- remove trailing newline from subtitle filename
+ filename = string.gsub(result.stdout, "\n", "")
+ log(filename)
+ mp.commandv('sub_add', filename)
+ log('Subtitles ready!')
+ else
+ log('Subtitles failed downloading')
+ end
+ end
+
+ -- Control function: only download if necessary
+ function control_download()
+ duration = tonumber(mp.get_property('duration'))
+ if duration < 900 then
+ mp.msg.warn('Video is less than 15 minutes\n', '=> NOT downloading any subtitles')
+ return
+ end
+ -- There does not seem to be any documentation for the 'sub' property,
+ -- but it works on both internally encoded as well as external subtitle files!
+ -- -> sub = '1' when subtitles are present
+ -- -> sub = 'no' when subtitles are not present
+ -- -> sub = 'auto' when called before the 'file-loaded' event is triggered
+ sub = mp.get_property('sub')
+ if sub == '1' then
+ mp.msg.warn('Sub track is already present\n', '=> NOT downloading other subtitles')
+ return
+ end
+ mp.msg.warn('No sub track was detected\n', '=> Proceeding to download subtitles:')
+ download()
+ end
+
+ mp.register_event('file-loaded', control_download)
+ mp.add_key_binding('S', "download_subs", download)
+ '';
+
mpv = pkgs.symlinkJoin {
name = "mpv";
paths = [
(pkgs.writeDashBin "mpv" ''
- exec ${pkgs.mpv}/bin/mpv --no-config "$@"
+ exec ${pkgs.mpv}/bin/mpv --no-config --script=${autosub} "$@"
+ # exec ${pkgs.mpv}/bin/mpv --no-config "$@"
'')
pkgs.mpv
];