2023-07-26 09:56:26 +00:00
|
|
|
# mpv docs:
|
|
|
|
# - <https://mpv.io/manual/master>
|
|
|
|
# - <https://github.com/mpv-player/mpv/wiki>
|
|
|
|
# curated mpv mods/scripts/users:
|
|
|
|
# - <https://github.com/stax76/awesome-mpv>
|
2023-10-23 08:36:28 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
2022-11-22 05:28:41 +00:00
|
|
|
|
2023-10-23 08:36:28 +00:00
|
|
|
let
|
|
|
|
cfg = config.sane.programs.mpv;
|
|
|
|
in
|
2022-10-21 15:43:57 +00:00
|
|
|
{
|
2023-04-24 07:22:33 +00:00
|
|
|
sane.programs.mpv = {
|
2023-10-23 08:36:28 +00:00
|
|
|
configOption = with lib; mkOption {
|
|
|
|
default = {};
|
|
|
|
type = types.submodule {
|
|
|
|
options.vo = mkOption {
|
2023-10-24 13:07:16 +00:00
|
|
|
type = types.nullOr types.str;
|
2023-10-23 08:36:28 +00:00
|
|
|
default = null;
|
|
|
|
description = "--vo=FOO flag to pass to mpv";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2024-01-22 03:50:28 +00:00
|
|
|
packageUnwrapped = (pkgs.wrapMpv pkgs.mpv-unwrapped {
|
2023-07-26 12:36:01 +00:00
|
|
|
scripts = with pkgs.mpvScripts; [
|
2023-07-27 05:47:21 +00:00
|
|
|
mpris
|
2023-12-10 00:27:09 +00:00
|
|
|
uosc
|
|
|
|
# pkgs.mpv-uosc-latest
|
2023-07-26 12:36:01 +00:00
|
|
|
];
|
2023-10-23 08:36:28 +00:00
|
|
|
extraMakeWrapperArgs = lib.optionals (cfg.config.vo != null) [
|
2023-08-30 10:32:31 +00:00
|
|
|
# 2023/08/29: fixes an error where mpv on moby launches with the message
|
|
|
|
# "DRM_IOCTL_MODE_CREATE_DUMB failed: Cannot allocate memory"
|
|
|
|
# audio still works, and controls, screenshotting, etc -- just not the actual rendering
|
2023-12-04 11:07:59 +00:00
|
|
|
#
|
|
|
|
# this is likely a regression for mpv 0.36.0.
|
|
|
|
# the actual error message *appears* to come from the mesa library, but it's tough to trace.
|
|
|
|
#
|
|
|
|
# TODO(2023/12/03): remove once mesa 23.3.1 lands: <https://github.com/NixOS/nixpkgs/pull/265740>
|
2023-10-23 08:36:28 +00:00
|
|
|
#
|
|
|
|
# backend compatibility (2023/10/22):
|
2023-08-30 10:32:31 +00:00
|
|
|
# run with `--vo=help` to see a list of all output options.
|
2023-10-23 08:36:28 +00:00
|
|
|
# non-exhaustive (W=works, F=fails, A=audio-only, U=audio+ui only (no video))
|
2023-08-30 10:32:31 +00:00
|
|
|
# ? null Null video output
|
2023-10-23 08:36:28 +00:00
|
|
|
# A (default)
|
|
|
|
# A dmabuf-wayland Wayland dmabuf video output
|
|
|
|
# A libmpv render API for libmpv (mpv plays the audio, but doesn't even render a window)
|
|
|
|
# A vdpau VDPAU with X11
|
2023-08-30 10:32:31 +00:00
|
|
|
# F drm Direct Rendering Manager (software scaling)
|
2023-10-23 08:36:28 +00:00
|
|
|
# F gpu-next Video output based on libplacebo
|
|
|
|
# F vaapi VA API with X11
|
|
|
|
# F x11 X11 (software scaling)
|
|
|
|
# F xv X11/Xv
|
|
|
|
# U gpu Shader-based GPU Renderer
|
|
|
|
# W caca libcaca (terminal rendering)
|
|
|
|
# W sdl SDL 2.0 Renderer
|
|
|
|
# W wlshm Wayland SHM video output (software scaling)
|
|
|
|
"--add-flags" "--vo=${cfg.config.vo}"
|
2023-08-30 10:32:31 +00:00
|
|
|
];
|
2024-01-22 03:50:28 +00:00
|
|
|
}).overrideAttrs (base: {
|
|
|
|
buildCommand = base.buildCommand + ''
|
|
|
|
# runHook postFixup to allow sandbox wrappers to wrap the binaries
|
|
|
|
runHook postFixup
|
|
|
|
'';
|
|
|
|
});
|
|
|
|
|
2024-01-23 11:37:37 +00:00
|
|
|
sandbox.method = "bwrap";
|
2024-01-27 17:19:48 +00:00
|
|
|
sandbox.autodetectCliPaths = true;
|
2024-02-08 21:51:32 +00:00
|
|
|
sandbox.net = "all";
|
2024-02-02 19:18:30 +00:00
|
|
|
sandbox.whitelistDri = true; #< mpv has excellent fallbacks to non-DRI, but DRI offers a good 30%-50% reduced CPU
|
2024-02-12 08:17:31 +00:00
|
|
|
sandbox.extraHomePaths = [
|
|
|
|
".config/mpv" #< else mpris plugin crashes on launch
|
2024-02-12 08:59:46 +00:00
|
|
|
# it's common for album (or audiobook, podcast) images/lyrics/metadata to live adjacent to the primary file.
|
|
|
|
# CLI detection is too poor to pick those up, so expose the common media dirs to the sandbox to make that *mostly* work.
|
|
|
|
"Music"
|
|
|
|
"Videos"
|
|
|
|
"Books"
|
2024-02-12 08:17:31 +00:00
|
|
|
];
|
2024-01-22 03:50:28 +00:00
|
|
|
|
2023-11-08 15:32:50 +00:00
|
|
|
persist.byStore.plaintext = [ ".local/state/mpv/watch_later" ];
|
2023-12-16 00:43:43 +00:00
|
|
|
fs.".config/mpv/input.conf".symlink.text = let
|
|
|
|
execInTerm = "${pkgs.xdg-terminal-exec}/bin/xdg-terminal-exec";
|
|
|
|
in ''
|
2023-12-16 00:39:36 +00:00
|
|
|
# docs:
|
|
|
|
# - <https://mpv.io/manual/master/#list-of-input-commands>
|
|
|
|
# - script-binding: <https://mpv.io/manual/master/#command-interface-script-binding>
|
|
|
|
# - properties: <https://mpv.io/manual/master/#property-list>
|
|
|
|
|
2023-09-06 04:17:14 +00:00
|
|
|
# let volume/power keys be interpreted by the system.
|
2023-07-26 12:36:01 +00:00
|
|
|
# this is important for sxmo.
|
2023-09-06 04:17:14 +00:00
|
|
|
# mpv defaults is POWER = close, VOLUME_{UP,DOWN} = adjust application-level volume
|
|
|
|
POWER ignore
|
2023-07-26 12:36:01 +00:00
|
|
|
VOLUME_UP ignore
|
|
|
|
VOLUME_DOWN ignore
|
2023-12-16 00:39:36 +00:00
|
|
|
|
|
|
|
# uosc menu
|
|
|
|
# text after the shebang is parsed by uosc to construct the menu and names
|
|
|
|
menu script-binding uosc/menu
|
|
|
|
s script-binding uosc/subtitles #! Subtitles
|
|
|
|
a script-binding uosc/audio #! Audio tracks
|
|
|
|
q script-binding uosc/stream-quality #! Stream quality
|
|
|
|
p script-binding uosc/items #! Playlist
|
|
|
|
c script-binding uosc/chapters #! Chapters
|
|
|
|
> script-binding uosc/next #! Navigation > Next
|
|
|
|
< script-binding uosc/prev #! Navigation > Prev
|
|
|
|
o script-binding uosc/open-file #! Navigation > Open file
|
|
|
|
# set video-aspect-override "-1" #! Utils > Aspect ratio > Default
|
|
|
|
# set video-aspect-override "16:9" #! Utils > Aspect ratio > 16:9
|
|
|
|
# set video-aspect-override "4:3" #! Utils > Aspect ratio > 4:3
|
|
|
|
# set video-aspect-override "2.35:1" #! Utils > Aspect ratio > 2.35:1
|
|
|
|
# script-binding uosc/audio-device #! Utils > Audio devices
|
|
|
|
# script-binding uosc/editions #! Utils > Editions
|
|
|
|
ctrl+s async screenshot #! Utils > Screenshot
|
|
|
|
alt+i script-binding uosc/keybinds #! Utils > Key bindings
|
|
|
|
O script-binding uosc/show-in-directory #! Utils > Show in directory
|
|
|
|
# script-binding uosc/open-config-directory #! Utils > Open config directory
|
2023-12-16 00:43:43 +00:00
|
|
|
# set pause yes; run ${execInTerm} go2tv -v "''${stream-open-filename}" #! Cast
|
|
|
|
# set pause yes; run ${execInTerm} go2tv -u "''${stream-open-filename}" #! Cast (...) > Stream
|
|
|
|
# set pause yes; run go2tv #! Cast (...) > GUI
|
2023-12-16 00:39:36 +00:00
|
|
|
# TODO: unify "Cast" and "Cast (stream)" options above.
|
2023-07-26 12:36:01 +00:00
|
|
|
'';
|
2023-05-08 21:41:02 +00:00
|
|
|
fs.".config/mpv/mpv.conf".symlink.text = ''
|
2023-07-26 12:36:01 +00:00
|
|
|
save-position-on-quit=yes
|
|
|
|
keep-open=yes
|
|
|
|
|
2023-08-14 05:52:16 +00:00
|
|
|
# force GUI, even for tracks w/o album art
|
|
|
|
# see: <https://www.reddit.com/r/mpv/comments/rvrrpt/oscosdgui_and_arch_linux/>
|
|
|
|
player-operation-mode=pseudo-gui
|
|
|
|
|
2023-07-26 12:36:01 +00:00
|
|
|
# use uosc instead (for On Screen Controls)
|
|
|
|
osc=no
|
|
|
|
# uosc provides its own seeking/volume indicators, so you also don't need this
|
|
|
|
osd-bar=no
|
|
|
|
# uosc will draw its own window controls if you disable window border
|
|
|
|
border=no
|
2023-04-24 07:22:33 +00:00
|
|
|
'';
|
2023-07-26 09:56:26 +00:00
|
|
|
fs.".config/mpv/script-opts/osc.conf".symlink.text = ''
|
|
|
|
# make the on-screen controls *always* visible
|
|
|
|
# unfortunately, this applies to full-screen as well
|
|
|
|
# - docs: <https://mpv.io/manual/master/#on-screen-controller-visibility>
|
2023-07-26 12:36:01 +00:00
|
|
|
# if uosc is installed, this file is unused
|
2023-07-26 09:56:26 +00:00
|
|
|
visibility=always
|
|
|
|
'';
|
2023-07-26 12:36:01 +00:00
|
|
|
fs.".config/mpv/script-opts/uosc.conf".symlink.text = let
|
|
|
|
play_pause_btn = "cycle:play_arrow:pause:no=pause/yes=play_arrow";
|
2023-07-28 00:34:49 +00:00
|
|
|
rev_btn = "command:replay_10:seek -10";
|
2023-07-26 12:36:01 +00:00
|
|
|
fwd_btn = "command:forward_30:seek 30";
|
|
|
|
in ''
|
|
|
|
# docs:
|
|
|
|
# - <https://github.com/tomasklaen/uosc>
|
2023-12-10 00:27:09 +00:00
|
|
|
# - <https://github.com/tomasklaen/uosc/blob/main/src/uosc.conf>
|
2023-07-26 12:36:01 +00:00
|
|
|
# - <https://superuser.com/questions/1775550/add-new-buttons-to-mpv-uosc-ui>
|
|
|
|
timeline_style=bar
|
|
|
|
timeline_persistency=paused,audio
|
|
|
|
controls_persistency=paused,audio
|
|
|
|
volume_persistency=audio
|
|
|
|
volume_opacity=0.75
|
|
|
|
|
|
|
|
# speed_persistency=paused,audio
|
|
|
|
# vvv want a close button?
|
|
|
|
top_bar=always
|
|
|
|
top_bar_persistency=paused
|
|
|
|
|
|
|
|
controls=menu,<video>subtitles,<has_many_audio>audio,<has_many_video>video,<has_many_edition>editions,<stream>stream-quality,space,${rev_btn},${play_pause_btn},${fwd_btn},space,speed:1.0,gap,<video>fullscreen
|
|
|
|
|
|
|
|
text_border=6.0
|
|
|
|
font_bold=yes
|
2023-12-10 00:27:09 +00:00
|
|
|
color=foreground=ff8080,background_text=ff8080
|
2023-07-26 12:36:01 +00:00
|
|
|
|
|
|
|
ui_scale=1.0
|
|
|
|
'';
|
2023-07-26 09:56:26 +00:00
|
|
|
|
2023-09-16 08:36:08 +00:00
|
|
|
# mime.priority = 200; # default = 100; 200 means to yield to other apps
|
|
|
|
mime.priority = 50; # default = 100; 50 in order to take precedence over vlc.
|
2023-07-26 09:56:26 +00:00
|
|
|
mime.associations."audio/flac" = "mpv.desktop";
|
|
|
|
mime.associations."audio/mpeg" = "mpv.desktop";
|
2023-11-29 01:14:15 +00:00
|
|
|
mime.associations."audio/x-opus+ogg" = "mpv.desktop";
|
2023-07-26 09:56:26 +00:00
|
|
|
mime.associations."audio/x-vorbis+ogg" = "mpv.desktop";
|
|
|
|
mime.associations."video/mp4" = "mpv.desktop";
|
|
|
|
mime.associations."video/quicktime" = "mpv.desktop";
|
|
|
|
mime.associations."video/webm" = "mpv.desktop";
|
2024-01-01 11:48:18 +00:00
|
|
|
mime.associations."video/x-flv" = "mpv.desktop";
|
2023-07-26 09:56:26 +00:00
|
|
|
mime.associations."video/x-matroska" = "mpv.desktop";
|
2023-12-11 04:49:36 +00:00
|
|
|
mime.urlAssociations."^https?://(www.)?youtube.com/watch\?.*v=" = "mpv.desktop";
|
2023-12-13 03:44:57 +00:00
|
|
|
mime.urlAssociations."^https?://(www.)?youtube.com/v/" = "mpv.desktop";
|
2023-12-11 16:19:51 +00:00
|
|
|
mime.urlAssociations."^https?://(www.)?youtu.be/.+" = "mpv.desktop";
|
2023-04-24 07:22:33 +00:00
|
|
|
};
|
2022-10-21 15:43:57 +00:00
|
|
|
}
|
|
|
|
|