From 3af3b34a1dab8f9f6357c5b094b7552489abe754 Mon Sep 17 00:00:00 2001 From: Ole Tange Date: Sat, 12 Oct 2019 22:20:20 +0200 Subject: [PATCH 1/2] ytv: Re-play is now default action. --- Makefile | 15 +++++----- fxkill/fxkill | 5 ++++ tracefile/tracefile | 12 ++++---- whitehash/whitehash | 16 +++++----- wifi-reload/wifi-reload | 14 ++++----- ytv/ytv | 65 +++++++++++++++++++++++++++-------------- 6 files changed, 78 insertions(+), 49 deletions(-) create mode 100755 fxkill/fxkill diff --git a/Makefile b/Makefile index c030bfa..e6e5eca 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,9 @@ CMD = blink bsearch burncpu duplicate-packets em encdir field forever \ - G gitnext gitundo goodpasswd histogram mtrr mirrorpdf neno \ - off pdfman plotpipe puniq ramusage rand rclean rina rn rrm \ - shython sound-reload stdout swapout T timestamp tracefile \ - transpose upsidedown vid w4it-for-port-open wifi-reload wssh \ - ytv yyyymmdd + fxkill G gitnext gitundo goodpasswd histogram mtrr mirrorpdf \ + neno off pdfman plotpipe puniq ramusage rand rclean rina rn \ + rrm shython splitvideo sound-reload stdout swapout T \ + timestamp tracefile transpose upsidedown vid \ + w4it-for-port-open wifi-reload wssh ytv yyyymmdd all: blink/blink.1 bsearch/bsearch.1 burncpu/burncpu.1 \ encdir/encdir.1 G/G.1 gitnext/gitnext.1 gitundo/gitundo.1 \ @@ -11,8 +11,8 @@ all: blink/blink.1 bsearch/bsearch.1 burncpu/burncpu.1 \ mirrorpdf/mirrorpdf.1 neno/neno.1 off/off.1 pdfman/pdfman.1 \ plotpipe/plotpipe.1 puniq/puniq.1 rand/rand.1 rina/rina.1 \ rn/rn.1 rrm/rrm.1 shython/shython.1 \ - sound-reload/sound-reload.1 stdout/stdout.1 \ - timestamp/timestamp.1 tracefile/tracefile.1 \ + sound-reload/sound-reload.1 splitvideo/splitvideo.1 \ + stdout/stdout.1 timestamp/timestamp.1 tracefile/tracefile.1 \ transpose/transpose.1 T/T.1 upsidedown/upsidedown.1 vid/vid.1 \ wifi-reload/wifi-reload.1 wssh/wssh.1 ytv/ytv.1 \ yyyymmdd/yyyymmdd.1 @@ -25,3 +25,4 @@ install: parallel eval ln -sf `pwd`/*/{} /usr/local/bin/{} ::: $(CMD) mkdir -p /usr/local/share/man/man1 parallel ln -sf `pwd`/{} /usr/local/share/man/man1/{/} ::: */*.1 + ln -s `pwd`/splitvideo/dotlocal/share/vlc/lua/extensions/splitvideo.lua $(HOME)/.local/share/vlc/lua/extensions/splitvideo.lua diff --git a/fxkill/fxkill b/fxkill/fxkill new file mode 100755 index 0000000..13d7b21 --- /dev/null +++ b/fxkill/fxkill @@ -0,0 +1,5 @@ +#!/bin/bash + +# Kill firefox content processes + +ps aux |G firefox contentproc childID -v grep |field 2 | xargs -r kill diff --git a/tracefile/tracefile b/tracefile/tracefile index 293f0e0..cd9325b 100755 --- a/tracefile/tracefile +++ b/tracefile/tracefile @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/perl -w =head1 NAME @@ -55,8 +55,8 @@ List only normal files. =item B<--local> -List only files in current directory. Useful to avoid matching at -system files. +List only files in current directory. Useful to avoid matching system +files. =item B<-n> @@ -84,14 +84,14 @@ List only files once. =item B<--read> -List only files being access for reading. +List only files being accessed for reading. =item B<-w> =item B<--write> -List only files being access for writing. +List only files being accessed for writing. =back @@ -255,6 +255,7 @@ init_functions(); my @cmd = shell_quote(@ARGV); my $dir = "."; my $pid = $opt::pid ? "-p $opt::pid" : ""; +my %seen; # BUG: If command gives output on stderr that can confuse the strace output open(IN, "-|", "strace -ff $pid -e trace=file @cmd 2>&1 >/dev/null") || die; @@ -493,3 +494,4 @@ sub my_dump(@) { } } +$opt::debug = $opt::all; diff --git a/whitehash/whitehash b/whitehash/whitehash index 4f168f8..a55911b 100755 --- a/whitehash/whitehash +++ b/whitehash/whitehash @@ -43,18 +43,20 @@ def mergeparts(tabs,part): p2 = [] for i in range(len(x)-1): - p2.append("".join(part[x[i]:x[i+1]])) + p2.append(("".join(part[x[i]:x[i+1]])).encode("utf-8")) return(p2) +spc = [ i.encode("utf-8") + for i in ("", " ", " ", " ", " ", " ", " ", " ") ] def recur(pre,n): if n == len(part)-1: - for i in ("", " ", " ", " ", " ", " ", " ", " "): - sha1 = (hashlib.sha1((pre+i+part[n]).encode("utf-8")).hexdigest())[0:searchlen]; + for i in spc: + sha1 = (hashlib.sha1(pre+i+part[n]).hexdigest())[0:searchlen]; if sha1 in searchstrings: - print(hashlib.sha1((pre+i+part[n]).encode("utf-8")).hexdigest()) - print(pre+i+part[n]) + print(hashlib.sha1(pre+i+part[n]).hexdigest()) + print((pre+i+part[n]).decode()) else: - for i in ("", " ", " ", " ", " ", " ", " ", " "): + for i in spc: recur(pre+i+part[n],n+1) bits = searchlen*4 @@ -65,7 +67,7 @@ if tabs > len(part)-1: exit(1); part = mergeparts(tabs,part) -s="0123456789abcdef" +s = "0123456789abcdef" # Chop at searchlen searchstrings = [ i[0:searchlen] for i in # Generate 111..1 222..2 .. fff..f diff --git a/wifi-reload/wifi-reload b/wifi-reload/wifi-reload index 48f202d..44dd5d4 100755 --- a/wifi-reload/wifi-reload +++ b/wifi-reload/wifi-reload @@ -79,10 +79,8 @@ startnm() { config() { IF=$1 sudo bash -c 'cat >> /etc/resolv.conf' < /etc/resolvconf/resolv.conf.d/head - sudo iwconfig $IF essid Turris - #sudo iwconfig $IF essid olet - #sudo iwconfig $IF essid elverhoej - #sudo iwconfig $IF essid Leif + #sudo iwconfig wls1 essid Turris + #sudo iwconfig wls1 essid Leif #sudo iwconfig wls1 essid SKYbroadbandCC95 sudo wpa_supplicant -c/etc/wpa_supplicant.conf -i$IF -d & sudo dhclient $IF & @@ -90,11 +88,11 @@ config() { stop starthw -config wlp3s0 -#startnm +IF=$(stdout iwconfig |perl -ane '/^\s|no wireless extension/ and next; print $F[0],"\n"') +iwconfig +config $IF +startnm if tty -s ; then # STDIN is terminal true timeout 12 dmesg -Tw & fi -#config wlp3s0 -#config wlx0016e63a51cb diff --git a/ytv/ytv b/ytv/ytv index 49afa7e..c04dfaf 100755 --- a/ytv/ytv +++ b/ytv/ytv @@ -86,10 +86,52 @@ if(not @ARGV) { } } +sub playfiles { + my @files = @_; + + if($opt::kodi) { + my @existing = + uniq( + grep { -f $_ } + map { $a=$b=$_; $b=~s/.part//; s/.temp//; $a,$b,$_ } @files + ); + for (my $i = 0; $i <= $#existing; $i++) { + my $answer; + $_ = $existing[$i]; + do { + print "KODI playing $_\n"; + if(not fork()) { + exec("idok", $_); + } + print "Press (r)etry, (d)elete, (p)revious, (n)ext\n"; + $answer = undef; + while(not defined $answer) { + open(my $tty_fh, "<", "/dev/tty") || + ::die_bug("interactive-tty"); + $answer = <$tty_fh>; + close $tty_fh; + if($answer =~ /d/i) { + unlink $_; + } + if($answer =~ /p/i) { + $i -= 2; + } + } + } while($answer =~ /^$|r/i); + } + } else { + system("vlc", map { $a=$b=$_; $b=~s/.part//; s/.temp//; $a,$b,$_ } @files); + } +} + sub play { my $url = shift; print "Playing $url\n"; + if(-e $url) { + playfiles($url); + return; + } if(not fork()) { # Download in the background system(qw(youtube-dl --all-subs --skip-download), @tor,$url); @@ -119,28 +161,7 @@ sub play { # Mark as seen map { $before{$_} = -M $_ } @new; # Run VLC on the matching files - if($opt::kodi) { - for(uniq(map { $a=$b=$_; $b=~s/.part//; s/.temp//; $a,$b,$_ } @new)) { - my $answer; - do { - print "KODI playing $_\n"; - if(not fork()) { - exec("idok", $_); - } - print "Press (r)etry, (d)elete, (n)ext\n"; - while(not $answer) { - open(my $tty_fh, "<", "/dev/tty") || ::die_bug("interactive-tty"); - $answer = <$tty_fh>; - close $tty_fh; - if($answer =~ /d/i) { - unlink $_; - } - } - } while($answer =~ /r/i); - } - } else { - system("vlc", map { $a=$b=$_; $b=~s/.part//; s/.temp//; $a,$b,$_ } @new); - } + playfiles(@new); @new = grep { not $before{$_} or $before{$_} > -M $_ } <*>; } } From 614d1e34bc583e888d040f4a2ff36374db941693 Mon Sep 17 00:00:00 2001 From: Ole Tange Date: Sat, 12 Oct 2019 22:25:01 +0200 Subject: [PATCH 2/2] splitvideo: Split video a timestamp (cmdline + VLC-plugin). --- .../share/vlc/lua/extensions/splitvideo.lua | 84 +++++++ splitvideo/splitvideo | 233 ++++++++++++++++++ 2 files changed, 317 insertions(+) create mode 100644 splitvideo/dotlocal/share/vlc/lua/extensions/splitvideo.lua create mode 100755 splitvideo/splitvideo diff --git a/splitvideo/dotlocal/share/vlc/lua/extensions/splitvideo.lua b/splitvideo/dotlocal/share/vlc/lua/extensions/splitvideo.lua new file mode 100644 index 0000000..3833a52 --- /dev/null +++ b/splitvideo/dotlocal/share/vlc/lua/extensions/splitvideo.lua @@ -0,0 +1,84 @@ +--[[ +INSTALLATION (create directories if they donot exist): +- put the file in the VLC subdir /lua/extensions, by default: +* Windows (all users): %ProgramFiles%\VideoLAN\VLC\lua\extensions\ +* Windows (current user): %APPDATA%\VLC\lua\extensions\ +* Linux (all users): /usr/share/vlc/lua/extensions/ +* Linux (current user): ~/.local/share/vlc/lua/extensions/ +* Mac OS X (all users): /Applications/VLC.app/Contents/MacOS/share/lua/extensions/ +- Restart VLC. +- The extension can then be found in the menu: + View > Split video in two +- It requires 'splitvideo' from + https://gitlab.com/ole.tange/tangetools/tree/master/splitvideo + to be in $PATH +]]-- + +--[[ Extension description ]] + +function descriptor() + return { title = "SplitVideo" ; + version = "1.0" ; + author = "Ole Tange" ; + shortdesc = "Split video at the current time"; + description = "

Split Video

" + .. "When you're playing a file, use Split Video to " + .. "split the file into two files at the current time stamp. " ; + url = "https://gitlab.com/ole.tange/tangetools/tree/master/splitvideo" + } +end + +--[[ Hooks ]] + +-- Activation hook +function activate() + local filename,secs = filename_secs() ; + d = vlc.dialog("Split Video") ; + d:add_label("Split ".. filename .. " at " .. secs .. "?") ; + d:add_button("Split", splitvideo) ; + d:add_button("Cancel", close) ; + d:show() ; + vlc.msg.dbg("[Split Video] Activated") ; +end + +function filename_secs() + -- absolute filename and current play time in seconds + -- get the current playing file + local item = vlc.input.item() + -- extract its URI + local uri = item:uri() + -- decode %foo stuff from the URI + local filename = vlc.strings.decode_uri(uri) + -- remove 'file://' prefix which is 7 chars long + filename = string.sub(filename,8) + -- maybe: + vlc.msg.dbg("[SplitVideo/filename_secs] Filename " .. filename) + input = vlc.object.input() + local elapsed_secs = vlc.var.get(input, "time")/1000000 + + return filename,elapsed_secs +end + +function splitvideo() + local filename,secs = filename_secs() + -- shell quote the filename + file, _ = filename:gsub("([\002-\009\011-\026\\#?`(){}%[%]^*<>=~|; \"!$&'\130-\255])", "\\%1") + file, _ = file:gsub("\n", "'\n'") + os.execute("splitvideo " .. secs .. " " .. file) + close() +end + + +function deactivate() + -- Deactivation hook + vlc.msg.dbg("[SplitVideo] Deactivated") + vlc.deactivate() +end + +function close() + deactivate() +end + +-- This empty function is there, because vlc pested me otherwise +function meta_changed() +end diff --git a/splitvideo/splitvideo b/splitvideo/splitvideo new file mode 100755 index 0000000..d9d5233 --- /dev/null +++ b/splitvideo/splitvideo @@ -0,0 +1,233 @@ +#!/usr/bin/perl -w + +=pod + +=head1 NAME + +splitvideo - Split video at time stamp + + +=head1 SYNOPSIS + +B time videofile + + +=head1 DESCRIPTION + +B splits I at I