Merge branch 'master' of gitlab.com:ole.tange/tangetools

encdir uses --public if root.
This commit is contained in:
Ole Tange 2019-12-27 08:36:11 +01:00
commit 4389fb20e5
9 changed files with 401 additions and 52 deletions

View file

@ -1,9 +1,9 @@
CMD = blink bsearch burncpu duplicate-packets em encdir field forever \ CMD = blink bsearch burncpu duplicate-packets em encdir field forever \
G gitnext gitundo goodpasswd histogram mtrr mirrorpdf neno \ fxkill G gitnext gitundo goodpasswd histogram mtrr mirrorpdf \
off pdfman pidcmd plotpipe puniq ramusage rand rclean rina rn \ neno off pdfman pidcmd plotpipe puniq ramusage rand rclean \
rrm shython sound-reload stdout swapout T timestamp tracefile \ rina rn rrm shython sound-reload splitvideo stdout swapout T \
transpose upsidedown vid w4it-for-port-open whitehash \ timestamp tracefile transpose upsidedown vid \
wifi-reload wssh ytv yyyymmdd w4it-for-port-open whitehash wifi-reload wssh ytv yyyymmdd
all: blink/blink.1 bsearch/bsearch.1 burncpu/burncpu.1 \ all: blink/blink.1 bsearch/bsearch.1 burncpu/burncpu.1 \
encdir/encdir.1 G/G.1 gitnext/gitnext.1 gitundo/gitundo.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 \ mirrorpdf/mirrorpdf.1 neno/neno.1 off/off.1 pdfman/pdfman.1 \
pidcmd/pidcmd.1 plotpipe/plotpipe.1 puniq/puniq.1 rand/rand.1 \ pidcmd/pidcmd.1 plotpipe/plotpipe.1 puniq/puniq.1 rand/rand.1 \
rina/rina.1 rn/rn.1 rrm/rrm.1 shython/shython.1 \ rina/rina.1 rn/rn.1 rrm/rrm.1 shython/shython.1 \
sound-reload/sound-reload.1 stdout/stdout.1 \ sound-reload/sound-reload.1 splitvideo/splitvideo.1 \
timestamp/timestamp.1 tracefile/tracefile.1 \ stdout/stdout.1 timestamp/timestamp.1 tracefile/tracefile.1 \
transpose/transpose.1 T/T.1 upsidedown/upsidedown.1 vid/vid.1 \ transpose/transpose.1 T/T.1 upsidedown/upsidedown.1 vid/vid.1 \
wifi-reload/wifi-reload.1 wssh/wssh.1 ytv/ytv.1 \ wifi-reload/wifi-reload.1 wssh/wssh.1 ytv/ytv.1 \
yyyymmdd/yyyymmdd.1 yyyymmdd/yyyymmdd.1
@ -25,3 +25,5 @@ install:
parallel eval ln -sf `pwd`/*/{} /usr/local/bin/{} ::: $(CMD) parallel eval ln -sf `pwd`/*/{} /usr/local/bin/{} ::: $(CMD)
mkdir -p /usr/local/share/man/man1 mkdir -p /usr/local/share/man/man1
parallel ln -sf `pwd`/{} /usr/local/share/man/man1/{/} ::: */*.1 parallel ln -sf `pwd`/{} /usr/local/share/man/man1/{/} ::: */*.1
mkdir -p $(HOME)/.local/share/vlc/lua/extensions
ln -s `pwd`/splitvideo/dotlocal/share/vlc/lua/extensions/splitvideo.lua $(HOME)/.local/share/vlc/lua/extensions/splitvideo.lua

View file

@ -27,7 +27,7 @@ Mount mydir.enc on mydir:
=head1 AUTHOR =head1 AUTHOR
Copyright (C) 2017 Ole Tange, Copyright (C) 2017-2020 Ole Tange,
http://ole.tange.dk and Free Software Foundation, Inc. http://ole.tange.dk and Free Software Foundation, Inc.
@ -64,10 +64,12 @@ B<encfs>
if [ -z "$2" ] ; then if [ -z "$2" ] ; then
fusermount -u $1 2>/dev/null fusermount -u $1 2>/dev/null
encfs `readlink -f $1.enc` `readlink -f $1` # --public only works if root. Ignored otherwise.
encfs --public `readlink -f "$1".enc` `readlink -f "$1"`
else else
fusermount -u `readlink -f $2` 2>/dev/null fusermount -u `readlink -f $2` 2>/dev/null
encfs `readlink -f $1` `readlink -f $2` # --public only works if root. Ignored otherwise.
encfs --public `readlink -f "$1"` `readlink -f "$2"`
fi fi

5
fxkill/fxkill Executable file
View file

@ -0,0 +1,5 @@
#!/bin/bash
# Kill firefox content processes
ps aux |G firefox contentproc childID -v grep |field 2 | xargs -r kill

View file

@ -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 = "<h1>Split Video</h1>"
.. "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 <b>".. filename .. "</b> at <b> " .. secs .. "</b>?") ;
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

233
splitvideo/splitvideo Executable file
View file

@ -0,0 +1,233 @@
#!/usr/bin/perl -w
=pod
=head1 NAME
splitvideo - Split video at time stamp
=head1 SYNOPSIS
B<splitvideo> time videofile
=head1 DESCRIPTION
B<splitvideo> splits I<videofile> at I<time>.
I<time> is given in seconds or as HH:MM:SS.s.
I<videofile> will be split into: I<videofile>-00:00:00.0-ZZ:ZZ:ZZ.Z
and I<videofile>-ZZ:ZZ:ZZ.Z-YY:YY:YY.Y where Z is the split time and Y
is the length of the video.
If I<videofile> contains XX:XX:XX.X-YY:YY:YY.Y I<videofile> will be
split into: I<videofile>-XX:XX:XX.X-ZZ:ZZ:ZZ.Z and
I<videofile>-ZZ:ZZ:ZZ.Z-YY:YY:YY.Y.
After splitting is done I<videofile> is moved to ~/.rm/splitvideo.
=head1 USES
B<splitvideo> can be used on the commandline:
splitvideo 3600 myvideo.mp4
It can also be called from VLC by installing B<splitvideo.lua> from
https://gitlab.com/ole.tange/tangetools/tree/master/splitvideo in
B<~/.local/share/vlc/lua/extensions/>
=head1 AUTHOR
Copyright (C) 2019 Ole Tange,
http://ole.tange.dk and Free Software Foundation, Inc.
=head1 LICENSE
Copyright (C) 2012 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
at your option any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
=head1 DEPENDENCIES
B<splitvideo> uses B<perl> and B<ffmpeg>.
=head1 SEE ALSO
B<ffmpeg>
=cut
use strict;
my $time = shift;
my $infile = shift;
my $rmdir = find_rm_dir(".") || ".rm";
-d $rmdir or mkdir $rmdir;
$rmdir .= "/splitvideo";
-d $rmdir or mkdir $rmdir;
$time = format_time($time);
if(not -e $infile or $time !~ /\d\d:\d\d:\d\d.\d/) {
print "$time";
print "$0 HH:MM:SS.t video.file\n",
"To split video.file at HH:MM:SS.t\n",
"The original file will be moved to .../.rm\n\n";
} else {
my ($start_file,$end_file) = destinationfilenames($infile,$time);
# fmpeg -t 00:25:29 -i in.mp4 -c copy out-start.mp4
my @start = ("ffmpeg","-t",$time,"-i","file:$infile","-c","copy","file:$start_file");
system(@start) == 0 or die(join" ",@start);
# fmpeg -ss 00:25:29 -i in.mp4 -c copy out-end.mp4
my @end = ("ffmpeg","-ss",$time,"-i","file:$infile","-c","copy","file:$end_file");
system(@end) == 0 or die(join" ",@end);
system("mv",$infile,$rmdir) == 0 or die;
}
sub destinationfilenames {
# Inputs:
# $file = video file name
# $time = time to split at
# Return name with:
# basename-(starttime)-(starttime+time).ext
# basename-(starttime+time)-(videolength).ext
my $file = shift;
my $time = shift;
my ($startfile,$endfile);
my $basename = $file;
$basename =~ s/(\.[^.]+)$//;
my $extension = $1;
if($basename =~ s/-(\d\d:\d\d:\d\d.\d)-(\d\d:\d\d:\d\d.\d)//) {
my $add = format_time(to_secs($1)+to_secs($time));
$startfile = "$basename-$1-$add$extension";
$endfile = "$basename-$add-$2$extension";
} else {
my $length = videolength($file);
$startfile = "$basename-00:00:00.0-$time$extension";
$endfile = "$basename-$time-$length$extension";
}
return($startfile,$endfile);
}
sub videolength {
# Inputs:
# $file = video filename
# Return:
# length of $file in 00:00:00.0 format
my $file = shell_quote_scalar_default(shift);
# mp4info 'The future of London'"'"'s airports-KXmpdJO9UOc.mp4'
# The future of London's airports-KXmpdJO9UOc.mp4:
# Track Type Info
# 1 video H264 Main@3.1, 561.560 secs, 932 kbps, 1280x720 @ 25.000000 fps
# 2 audio MPEG-4 AAC LC, 561.574 secs, 0 kbps, 44100 Hz
open(my $fh, "-|", "mp4info $file") || die;
my $length = 0;
for(<$fh>) {
/(\d+.\d+) secs/ and $length = max($1,$length);
warn $_;
}
$length ||= "99:99:99.9";
$length = format_time($length);
return $length;
}
sub max(@) {
# Returns:
# Maximum value of array
my $max;
for (@_) {
# Skip undefs
defined $_ or next;
defined $max or do { $max = $_; next; }; # Set $_ to the first non-undef
$max = ($max > $_) ? $max : $_;
}
return $max;
}
sub shell_quote_scalar_default($) {
# Quote for other shells (Bourne compatibles)
# Inputs:
# $string = string to be quoted
# Returns:
# $shell_quoted = string quoted as needed by the shell
my $s = $_[0];
if($s =~ /[^-_.+a-z0-9\/]/i) {
$s =~ s/'/'"'"'/g; # "-quote single quotes
$s = "'$s'"; # '-quote entire string
$s =~ s/^''//; # Remove unneeded '' at ends
$s =~ s/''$//; # (faster than s/^''|''$//g)
return $s;
} elsif ($s eq "") {
return "''";
} else {
# No quoting needed
return $s;
}
}
sub to_secs {
# Inputs:
# $time = time in seconds or 00:00:00.0
# Returns:
# time in seconds
my $time = shift;
$time =~ /(((\d\d):)?((\d\d):))?(\d\d+)\.(\d+)/;
my $secs = $3 * 3600 + $5 * 60 + $6 + eval "0.$7";
return $secs;
}
sub format_time {
# Inputs:
# $time = time in seconds or 00:00:00.0
# Returns:
# time in 00:00:00.0
my $time = shift;
if($time =~ /^\d+(\.\d+)?$/) {
# Time in seconds
my $h = int($time/3600);
my $m = int($time/60) - 60*$h;
my $s = int($time) - 60*$m - 3600*$h;
my $ys = $time - int($time);
$time = sprintf("%02d:%02d:%02d.%d",$h,$m,$s,$ys);
}
$time =~ s/^(\d):?(\d\d)$/00:0$1:$2/;
$time =~ s/^(\d\d):?(\d\d)$/00:$1:$2/;
$time =~ s/^(\d\d:\d\d)$/00:$1/;
$time =~ s/^(\d\d:\d\d:\d\d)$/$1.0/;
return $time;
}
sub find_rm_dir {
my $dir = shift;
if(-d "$dir/.rm") {
return "$dir/.rm";
}
if(join(" ",stat $dir) eq join(" ",stat "../$dir")) {
# We have reached root dir (.. = .)
return undef;
} else {
return find_rm_dir("../$dir");
}
}

View file

@ -1,4 +1,4 @@
#!/usr/bin/perl #!/usr/bin/perl -w
=head1 NAME =head1 NAME
@ -55,8 +55,8 @@ List only normal files.
=item B<--local> =item B<--local>
List only files in current directory. Useful to avoid matching at List only files in current directory. Useful to avoid matching system
system files. files.
=item B<-n> =item B<-n>
@ -84,14 +84,14 @@ List only files once.
=item B<--read> =item B<--read>
List only files being access for reading. List only files being accessed for reading.
=item B<-w> =item B<-w>
=item B<--write> =item B<--write>
List only files being access for writing. List only files being accessed for writing.
=back =back
@ -255,6 +255,7 @@ init_functions();
my @cmd = shell_quote(@ARGV); my @cmd = shell_quote(@ARGV);
my $dir = "."; my $dir = ".";
my $pid = $opt::pid ? "-p $opt::pid" : ""; my $pid = $opt::pid ? "-p $opt::pid" : "";
my %seen;
# BUG: If command gives output on stderr that can confuse the strace output # 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; 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;

View file

@ -43,18 +43,20 @@ def mergeparts(tabs,part):
p2 = [] p2 = []
for i in range(len(x)-1): 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) return(p2)
spc = [ i.encode("utf-8")
for i in ("", " ", " ", " ", " ", " ", " ", " ") ]
def recur(pre,n): def recur(pre,n):
if n == len(part)-1: if n == len(part)-1:
for i in ("", " ", " ", " ", " ", " ", " ", " "): for i in spc:
sha1 = (hashlib.sha1((pre+i+part[n]).encode("utf-8")).hexdigest())[0:searchlen]; sha1 = (hashlib.sha1(pre+i+part[n]).hexdigest())[0:searchlen];
if sha1 in searchstrings: if sha1 in searchstrings:
print(hashlib.sha1((pre+i+part[n]).encode("utf-8")).hexdigest()) print(hashlib.sha1(pre+i+part[n]).hexdigest())
print(pre+i+part[n]) print((pre+i+part[n]).decode())
else: else:
for i in ("", " ", " ", " ", " ", " ", " ", " "): for i in spc:
recur(pre+i+part[n],n+1) recur(pre+i+part[n],n+1)
bits = searchlen*4 bits = searchlen*4

View file

@ -79,10 +79,8 @@ startnm() {
config() { config() {
IF=$1 IF=$1
sudo bash -c 'cat >> /etc/resolv.conf' < /etc/resolvconf/resolv.conf.d/head sudo bash -c 'cat >> /etc/resolv.conf' < /etc/resolvconf/resolv.conf.d/head
sudo iwconfig $IF essid Turris #sudo iwconfig wls1 essid Turris
#sudo iwconfig $IF essid olet #sudo iwconfig wls1 essid Leif
#sudo iwconfig $IF essid elverhoej
#sudo iwconfig $IF essid Leif
#sudo iwconfig wls1 essid SKYbroadbandCC95 #sudo iwconfig wls1 essid SKYbroadbandCC95
sudo wpa_supplicant -c/etc/wpa_supplicant.conf -i$IF -d & sudo wpa_supplicant -c/etc/wpa_supplicant.conf -i$IF -d &
sudo dhclient $IF & sudo dhclient $IF &
@ -90,11 +88,11 @@ config() {
stop stop
starthw starthw
config wlp3s0 IF=$(stdout iwconfig |perl -ane '/^\s|no wireless extension/ and next; print $F[0],"\n"')
#startnm iwconfig
config $IF
startnm
if tty -s ; then if tty -s ; then
# STDIN is terminal # STDIN is terminal
true timeout 12 dmesg -Tw & true timeout 12 dmesg -Tw &
fi fi
#config wlp3s0
#config wlx0016e63a51cb

65
ytv/ytv
View file

@ -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 { sub play {
my $url = shift; my $url = shift;
print "Playing $url\n"; print "Playing $url\n";
if(-e $url) {
playfiles($url);
return;
}
if(not fork()) { if(not fork()) {
# Download in the background # Download in the background
system(qw(youtube-dl --all-subs --skip-download), @tor,$url); system(qw(youtube-dl --all-subs --skip-download), @tor,$url);
@ -119,28 +161,7 @@ sub play {
# Mark as seen # Mark as seen
map { $before{$_} = -M $_ } @new; map { $before{$_} = -M $_ } @new;
# Run VLC on the matching files # Run VLC on the matching files
if($opt::kodi) { playfiles(@new);
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);
}
@new = grep { not $before{$_} or $before{$_} > -M $_ } <*>; @new = grep { not $before{$_} or $before{$_} > -M $_ } <*>;
} }
} }