diff --git a/cli/ranger/commands.py b/cli/ranger/commands.py index 19277a3..b5bc56b 100644 --- a/cli/ranger/commands.py +++ b/cli/ranger/commands.py @@ -172,7 +172,7 @@ class fzf_edit(Command): self.fm.edit_file(fzf_file) -class fc(Command): +class mediacut_join(Command): def execute(self): """ Concatenate selected video """ cwd = self.fm.thisdir @@ -200,3 +200,26 @@ class fc(Command): obj.signal_bind('after', refresh) self.fm.loader.add(obj) + + +class mediacut_open(Command): + def execute(self): + """ play all files in current dir """ + thisfile = self.fm.thisfile + if thisfile.filetype.startswith('inode/directory'): + files = [file.path for file in thisfile.files if file.filetype.startswith('video')] + else: + files = [thisfile.path] + descr = "mediacut open" + obj = CommandLoader( + args=[ + 'mpv', + '--no-resume-playback', + '--start=0', + '--osd-fractions', + '--osd-level=3' + ] + files, + descr=descr, + read=False, + ) + self.fm.loader.add(obj) diff --git a/cli/ranger/rc.conf b/cli/ranger/rc.conf index 5e63213..c43876d 100644 --- a/cli/ranger/rc.conf +++ b/cli/ranger/rc.conf @@ -8,3 +8,4 @@ set vcs_aware true map \cg eval import subprocess;fm.cd(subprocess.getoutput('git rev-parse --show-toplevel')) map fzf_select map fzf_edit +map oo mediacut_open diff --git a/gui/mpv/input.conf b/gui/mpv/input.conf new file mode 100644 index 0000000..917b40a --- /dev/null +++ b/gui/mpv/input.conf @@ -0,0 +1 @@ +CTRL+p script-message osc-playlist \ No newline at end of file diff --git a/gui/mpv/scripts/cut.lua b/gui/mpv/scripts/cut.lua new file mode 100644 index 0000000..e6ec77c --- /dev/null +++ b/gui/mpv/scripts/cut.lua @@ -0,0 +1,38 @@ +local utils = require "mp.utils" + +function mark_begin() + begin_pos = mp.get_property('time-pos') + mp.osd_message('Begin Position Marked at ' .. begin_pos) +end + +function mark_end() + end_pos = mp.get_property('time-pos') + mp.osd_message('End Position Marked at ' .. end_pos) +end + +function output_marked() + --if not begin_pos and not end_pos then + --mp.osd_message('Please set Begin Position with Ctrl-b, End Position with Ctrl-e') + --return + --end + ss = begin_pos or 0 + t = end_pos or mp.get_property('duration') + path = mp.get_property('path') + dir, file = utils.split_path(path) + output_dir = utils.join_path(dir, 'clips') + utils.subprocess({ + args={'mkdir', '-p', output_dir}, + cancellable=false + }) + output_file = utils.join_path(output_dir, file) + utils.subprocess({ + args={'ffmpeg', '-ss', tostring(ss), '-i', path, '-t', tostring(t), '-c', 'copy', output_file}, + cancellable=false + }) + mp.osd_message('Clip save to ' .. output_file) +end + + +mp.add_key_binding("ctrl+b", "mark_begin", mark_begin); +mp.add_key_binding("ctrl+e", "mark_end", mark_end); +mp.add_key_binding("ctrl+o", "output_marked", output_marked); diff --git a/gui/player.sh b/gui/player.sh index 87b5131..d57b087 100755 --- a/gui/player.sh +++ b/gui/player.sh @@ -19,7 +19,9 @@ esac # symlink configuration lnsf "$DIR/mpd/mpd.conf" "$XDG_CONFIG_HOME/mpd/mpd.conf" lnsf "$DIR/mpv/mpv.conf" "$XDG_CONFIG_HOME/mpv/mpv.conf" +lnsf "$DIR/mpv/input.conf" "$XDG_CONFIG_HOME/mpv/input.conf" lnsf "$DIR/mpv/scripts/organize.lua" "$XDG_CONFIG_HOME/mpv/scripts/organize.lua" +lnsf "$DIR/mpv/scripts/cut.lua" "$XDG_CONFIG_HOME/mpv/scripts/cut.lua" lnsf "$DIR/ncmpcpp/bindings" "$XDG_CONFIG_HOME/ncmpcpp/bindings" lnsf "$DIR/ncmpcpp/config" "$XDG_CONFIG_HOME/ncmpcpp/config"