occivink / mpv-image-viewer

Configuration, scripts and tips for using mpv as an image viewer
The Unlicense
284 stars 23 forks source link

Browsing the directory #5

Closed smarek closed 4 years ago

smarek commented 4 years ago

When launching mvi through xdg-open (see #4 ), and the same when launching mvi through cli, it will only play the file(s) we opened.

Usually image browsers do support switching between images (in alphabetical order) in the same directory right away.

I've very naive solution to this, which uses last file from provided arguments and adds whole directory to allow browsing (sincerely from the first file in alphabetical order away)

It would be cool, if the mvi, when launched with single file argument, added whole directory as playlist and switched to file in argument in created playlist appropriately. I think this would not work well when launched with multiple arguments (disregard if those are files or folders)

My solution:

#!/bin/bash

LASTARG="${@: -1}"
REAL=$(realpath "$LASTARG")
DIR=$(dirname "$REAL")
if [[ -f $REAL ]];
then
  ADD=$DIR
else
  ADD=""
fi

# will pass original arguments and then folder determined from last argument, if determined
mpv --config-dir=$HOME/.config/mvi/ "$@" "$ADD"
occivink commented 4 years ago

I recommend using the autoload.lua script from mpv for this. (also thanks for the .desktop file issue, I'll address it at some point)

smarek commented 4 years ago

Thank you, that seems like the best way, I've added the file in ~/.config/mvi/scripts/ directory and it autoloaded, sadly it does not work. Check on line 105 ( https://github.com/mpv-player/mpv/blob/master/TOOLS/lua/autoload.lua#L105 ) will return immediately, and will not add surrounding files to current playlist. You might know why?

(cheers, #4 was fun, it as well might not be integrated, i'm just happy it works in my case)

occivink commented 4 years ago

It looks like the script only runs when the file you're playing matches any of these extensions, try changing that? https://github.com/mpv-player/mpv/blob/master/TOOLS/lua/autoload.lua#L25-L28

smarek commented 4 years ago

Thank you, works correctly after adding appropriate extensions, could you probably include modified script in your repo?

occivink commented 4 years ago

I don't really like the idea of duplicating the script, but I think the mpv people would accept a pull request that makes these changes, if you feel like submitting one.

smarek commented 4 years ago

We could try, however since MPV is video player, i don't think they'll accept it. Maybe patch file and script would suit you better?

occivink commented 4 years ago

I'd only accept a patch if they explicitly refused to add these formats. I think it's just as in scope as audio formats.

smarek commented 4 years ago

Well https://github.com/mpv-player/mpv/pull/6990 got merged, so I guess we could provide instructions on how to use / configure that autoload now?

occivink commented 4 years ago

It's actually already mentioned in the "Others" section in the README (even though I had never tested that it works for us). Is there something you would add? The script is very much paste and forget

smarek commented 4 years ago

Well since it got accepted with default presets (images on) not much, maybe just the default script-opts disabling audio and video files for mvi purposes.

On Thu, Oct 3, 2019, 10:05 AM Olivier Perret notifications@github.com wrote:

It's actually already mentioned in the "Others" section in the README (even though I had never tested that it works for us). Is there something you would add? The script is very much paste and forget

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/occivink/mpv-image-viewer/issues/5?email_source=notifications&email_token=AAC56OCZL2IDBF7HG7I2UYLQMWRVHA5CNFSM4IXNVPN2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEAHLR5A#issuecomment-537835764, or mute the thread https://github.com/notifications/unsubscribe-auth/AAC56OAPBCIOKYPCJCGGFWTQMWRVHANCNFSM4IXNVPNQ .