Ravas coding goodies

For discussions about programming and projects not necessarily associated with Porteus.
User avatar
ncmprhnsbl
DEV Team
DEV Team
Posts: 3213
Joined: 20 Mar 2012, 03:42
Distribution: 5.0-current-64bit
Location: australia
Contact:

Ravas coding goodies

Post#46 by ncmprhnsbl » 03 Oct 2021, 13:28

Rava wrote:
03 Oct 2021, 11:15
Is it really part of any flavour of Port 5.0rc3?
not really, it was offered as bundle for openbox for RC1 (now archived) eg. http://mirrors.dotsrc.org/porteus/x86_6 ... 1/bundles/
it would seem it still works for RC3
Forum Rules : https://forum.porteus.org/viewtopic.php?f=35&t=44

User avatar
Rava
Contributor
Contributor
Posts: 3076
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.0rc3 x86_64 + 4.0 i586
Location: Forests of Germany
Contact:

Ravas coding goodies

Post#47 by Rava » 03 Oct 2021, 20:31

ncmprhnsbl wrote:
03 Oct 2021, 13:28
it would seem it still works for RC3
Just shows how good Porteus really is. :celebrate3:
Cheers!
Yours Rava

User avatar
Rava
Contributor
Contributor
Posts: 3076
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.0rc3 x86_64 + 4.0 i586
Location: Forests of Germany
Contact:

Ravas coding goodies

Post#48 by Rava » 04 Oct 2021, 20:31

The discussion about what we talked about started a few posts above, but the main issue of using file type vs file extension in determining syntax highlighting was ncmprhnsbl post here: btop (Post by ncmprhnsbl #84588)
ncmprhnsbl wrote:
04 Oct 2021, 01:45
text editors should (auto)set syntax highlighting based on content, not file extension..
I presumed geany would not go down the dark and dirty path Mousepad uses. testing it it seems my presumption was correct.

I copied a script to /tmp, changed it from ownership root.root to guest.users:

Code: Select all

root@porteus:/tmp# stat /usr/local/bin/ffplay-hide_banner-drawtext /tmp/ffplay-hide_banner-drawtext*|grep -E "File:|Access: \("
  File: /usr/local/bin/ffplay-hide_banner-drawtext
Access: (0755/-rwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
  File: /tmp/ffplay-hide_banner-drawtext
Access: (0755/-rwxr-xr-x)  Uid: ( 1000/   guest)   Gid: (  100/   users)
  File: /tmp/ffplay-hide_banner-drawtext.sh
Access: (0755/-rwxr-xr-x)  Uid: ( 1000/   guest)   Gid: (  100/   users)
Then I opened both /tmp/ffplay-hide_banner-drawtext* in geany and checked the syntax highlighting of /tmp/ffplay-hide_banner-drawtext :
Image

and then did the same with

Code: Select all

guest@porteus:/tmp$ mousepad ffplay-hide_banner-drawtext*
again only checking the script without .sh extension:
Image

As you can see, geany wins this race with flying colours, while Mousepad fails.
I not updated geany in ages, since it still runs flawlessly in even the newest of Porteus 5.0rc version, so the only program that got updated by default is Mousepad. :)
Cheers!
Yours Rava

User avatar
Rava
Contributor
Contributor
Posts: 3076
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.0rc3 x86_64 + 4.0 i586
Location: Forests of Germany
Contact:

Ravas coding goodies

Post#49 by Rava » 04 Oct 2021, 20:39

I expanded the capabilities of my previous mentioned make-ffplay-script script.

It now determines between media files containing video and ones that only have sound.
I have not tested that with very available media file. Please report any errors so I can hopefully find a workaround.

The idea is: when a media file is sound only, I want the default visualisation be "waves" instead of the default "RDFT ((Inverse) Real Discrete Fourier Transform)" and adjust the resulting window in having reduced height, or more precise: use -x 500 -y 150 .

To not clutter the resulting play-mediafile.sh with code, I use a script named

Code: Select all

ffplay-hide_banner
instead. That script needs to be executable and in the user's $PATH.

Here it is:

Code: Select all

#!/bin/sh
VERSION="0.2"
MYNAME="ffplay-hide_banner"

echo -e "$MYNAME V$VERSION"

ffprobe -hide_banner 2>&1 "$*" |grep Stream|grep "Video:" >/dev/null
if [ $? -eq 0 ]; then
	# return-value zero -> video: default
	ffplay -autoexit -hide_banner -i "$*"
else
	# return-value non-zero -> audio only - adjusting…
	ffplay -autoexit -hide_banner -showmode waves -x 500 -y 150 -i "$*"
fi
And this is the new make-ffplay-script

Code: Select all

#!/bin/sh
MYVERSION=V3.45# please add V at the beginning!
# V3.4 - $1 is the relative folder with the files, will be stripped of any "/" - e.g. Filme or Filme/ works but not /mnt/sda1/video/Filme nor /mnt/sda1/video/Filme/
# for now supported file endings are
# avi 	flv	mp3	mp4	mpg	mkv	ogv	TS	ts	webm	divx 	VOB	vob
# V3.4: now added "chmod -v a+x "$PARAMETER".sh - will create error message on NTFS or VFAT fs, necessary for Linux fs like ext2,ext3 etcetera.
# V3.5: now uses ffplay-hide_banner script instead of calling ffplay itself. ffplay-hide_banner distinguishes between video and media-file that is sound only. In the latter case the following is added: -showmode waves -x 500 -y 150 
echo make-ffplay-script $MYVERSION
PARAMETER=$(echo "$1"|sed 's|/||g')
if [ -d "$PARAMETER" ]; then
	echo working on "$PARAMETER"… writing into "$PARAMETER".sh
	echo '#!/bin/sh
echo "$0"' >"$PARAMETER".sh
	find "$PARAMETER" |grep -E "\.avi$|\.flv$|\.mp[34g]$|\.mkv$|\.ogv$|\.[tT][sS]$|\.webm$|\.divx$|\.[vV][oO][bB]$" |sort | while read line ; do
{
 echo ffplay-hide_banner \"${line}\" >>"$PARAMETER".sh
} ; done
	chmod -v a+x "$PARAMETER".sh
else
	echo Given parameter "$PARAMETER" is not a directory. Abort.
	exit 1
fi
Be aware if the resulting script is on a VFAT or NTFS filesystem you get an error similar to this one while executing make-ffplay-script:

Code: Select all

chmod: changing permissions of 'Scissor Seven.sh': Operation not permitted
failed to change mode of 'Scissor Seven.sh' from 0777 (rwxrwxrwx) to 0777 (rwxrwxrwx)
Oh boo hoo, not able to change mode from 0777 to 0777. What a disaster. </irony>
____________________________________________

When you use your DE-filebrowser (e.g. DE:XFCE; filebrowser:Thunar) to use ffplay-hide_banner to open media files, it then also enables your DE to alter the resulting audio-only window.

And just in case you also need a ffplay-version that loops the file and also distinguishes between video and audio-only like ffplay-hide_banner above: here it is. I call it ffplay-hide_banner-loop

Code: Select all

#!/bin/sh
VERSION="0.2"
MYNAME="ffplay-hide_banner-loop"

echo -e "$MYNAME V$VERSION"

ffprobe -hide_banner 2>&1 "$*" |grep Stream|grep "Video:" >/dev/null
if [ $? -eq 0 ]; then
	# return value zero -> video : default
	ffplay -autoexit -hide_banner -loop 0 -i "$*"
else
	# return value non-zero -> audio only - adjusting…
	ffplay -autoexit -hide_banner -loop 0 -showmode waves -x 500 -y 150 -i "$*"
fi
# V0.2	using ffprobe to determining if file is sound only, then alter the window appearance and visualisation
Cheers!
Yours Rava

User avatar
Ed_P
Contributor
Contributor
Posts: 6409
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 4.0 & 5.0rc3 ISOs
Location: Western NY, USA

Ravas coding goodies

Post#50 by Ed_P » 05 Oct 2021, 04:56

You're very skilled with scripting Rava. It could be helpful if you could look at USM and tweak it's code to update without errors and to run on 5.0rc3. :)
Ed

User avatar
Rava
Contributor
Contributor
Posts: 3076
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.0rc3 x86_64 + 4.0 i586
Location: Forests of Germany
Contact:

Ravas coding goodies

Post#51 by Rava » 05 Oct 2021, 05:22

Ed_P wrote:
05 Oct 2021, 04:56
You're very skilled with scripting Rava.
Thanks, you are welcome, but others on here are at least as talented as I am.
Ed_P wrote:
05 Oct 2021, 04:56
It could be helpful if you could look at USM and tweak it's code to update without errors and to run on 5.0rc3. :)
RL does not give me the time. USM is a huge project that does a lot. When there are other volunteers (at least 2 more besides me) to share the workload, I could help. But by myself? Nope.

Just look into USM yourself and you see what I mean.
Cheers!
Yours Rava

User avatar
Ed_P
Contributor
Contributor
Posts: 6409
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 4.0 & 5.0rc3 ISOs
Location: Western NY, USA

Ravas coding goodies

Post#52 by Ed_P » 05 Oct 2021, 05:29

Rava wrote:
05 Oct 2021, 05:22
Just look into USM yourself and you see what I mean.
Oh I have and it is WAY over my head. :(
Ed

User avatar
Rava
Contributor
Contributor
Posts: 3076
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.0rc3 x86_64 + 4.0 i586
Location: Forests of Germany
Contact:

Ravas coding goodies

Post#53 by Rava » 05 Oct 2021, 18:20

Since an image shows more than a thousand words, or so they say, I made two screenshots.
The first shows my original ffplay-hide_banner version, actually just doing what it names says: executing ffplay and -hide_banner:
All files are opened via

Code: Select all

ffplay -autoexit -hide_banner -i "$*"
I cropped both 1920x1080 screenshots to 632,295 : 658 x 513 (original X,Y : new_width x new_height)

Image

And here is what ffplay-hide_banner version 0.2 makes out of it, determining via ffprobe that the multi-media-file is sound only, and therefore opening it via :

Code: Select all

ffplay -autoexit -hide_banner -showmode waves -x 500 -y 150 -i "$*"
Image

Added in 1 day 3 hours 26 minutes 45 seconds:
By using ffplay-hide_banner v0.2 you can even determine via a ps|grep which running ffplay is sound only and which has video:

Code: Select all

root@porteus:~# type psg
psg is a function
psg () 
{ 
    /bin/ps ax | /bin/grep $* | /bin/grep -v grep
}

root@porteus:~# psg ffplay-hide_banner
 1526 tty2     S      0:00 /bin/sh /usr/local/bin/ffplay-hide_banner /sound/Clannad Original Soundtrack (Full Album)-J-0twocIam4.webm
 9275 tty2     S      0:00 /bin/sh /usr/local/bin/ffplay-hide_banner /video/Filme/Love, Chunibyo & Other Delusions the Movie - Rikka Takanashi Revision.mp4
 9330 tty2     S      0:00 /bin/sh /usr/local/bin/ffplay-hide_banner-loop /sound/WhiteNoise - 10 Hours.aac
31158 tty2     S      0:00 /bin/sh /usr/local/bin/ffplay-hide_banner /sound/VIOLET EVERGARDEN: Echo Through Eternity non singing+2.webm

psg ffplay-hide_banner itself hides the details, but psg ffplay|grep -v ffplay-hide_banner shows them:

Code: Select all

root@porteus:~# psg ffplay|grep -v ffplay-hide_banner
 1532 tty2     SLl   17:09 ffplay -autoexit -hide_banner -showmode waves -x 500 -y 150 -i /sound/Clannad Original Soundtrack (Full Album)
 9288 tty2     SLl    0:05 ffplay -autoexit -hide_banner -i /video/Filme/Love, Chunibyo & Other Delusions the Movie - Rikka Takanashi Rev
 9336 tty2     SLl    0:05 ffplay -autoexit -hide_banner -loop 0 -showmode waves -x 500 -y 150 -i /sound/WhiteNoise/Hairdryer White Noise
31164 tty2     SLl   29:21 ffplay -autoexit -hide_banner -showmode waves -x 500 -y 150 -i /sound/VIOLET EVERGARDEN: Echo Through Eternity non sing
Nice to see which are sound-only: PID 1532+9336+31164
Sound and video in this example is PID 9288

You can even determine if ffplay-hide_banner was executed via file browser or from a terminal, or via script as created by make-ffplay-script V3.45 or higher: because then it uses relative paths like here:

Code: Select all

root@porteus:~# psg ffplay|grep -v ffplay-hide_banner|grep Narayan,Ram
 9507 pts/7    SLl+   0:05 ffplay -autoexit -hide_banner -showmode waves -x 500 -y 150 -i Narayan,Ram/Masters of Raga/01 Rag Marwa- Alap.mp3
Cheers!
Yours Rava

User avatar
Rava
Contributor
Contributor
Posts: 3076
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.0rc3 x86_64 + 4.0 i586
Location: Forests of Germany
Contact:

Ravas coding goodies

Post#54 by Rava » 10 Oct 2021, 20:30

You can set up a custom action in your file browser that lets you create the make-ffplay-script without the need of a terminal:

This is how it works in XFCE/Thunar:
Main menu ▷ Edit ▷ Configure custom action

▷ Create a new custom action.

If your make-ffplay-script sits in /usr/local/bin the main tab looks like this:
Image

and the 2nd tab like this:
Image

Cave! The script only accepts exactly one folder as parameter. If you give it more than one it would print an error message (which you not see, since no terminal got opened) and nothing would be created.
So, select only one folder.

This is how it looks like in the context menu (aka right-mouse-click menu) when you select a folder and open the context menu:
Image
Cheers!
Yours Rava

User avatar
Rava
Contributor
Contributor
Posts: 3076
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.0rc3 x86_64 + 4.0 i586
Location: Forests of Germany
Contact:

Ravas coding goodies

Post#55 by Rava » 18 Oct 2021, 02:05

Code: Select all

<!doctype html public "-//w3c//dtd html 4.1 strict//en">
	<!-- V 0.47 2021-09-25 mailto: linux at ***CENSORED*** -->
	<html lang="de"><head>
	<link rel="icon" type="image/png" href="data:image/png;base64,/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE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iEhwP/2Q=="/>
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
	<link rel="stylesheet" type="text/css" href="file:///E:/mb.css">
<title>Dr. Copy & Mr. Paste - Textfeld V0.47 2021-09-25 - f&uuml;r FullHD</title>
</head><body>
<form action="dummy.html">
<p>
<textarea name="dummy" cols="91" rows="20" style="border : dotted 2px black;"></textarea>
</p>
</form>
</body>
</html>
Why do I code myself an empty edit area that obviously has no function? ( form action= is an invalid target)

To be able to pre-write text using the installed dictionaries (EN-UK and DE-Alte-Rechtschreibung 1903) without the need to install similar dictionaries in Libre Office… or even the need to activate and run any huge office program when the browser is already running and all I want is a plain .txt (for a later-to-be posted forum article, or a later-to-be-sent email)

Yes, me is weird as that. :P Also, at times I am on a machine without permanent Internet access. :D
Cheers!
Yours Rava

User avatar
Rava
Contributor
Contributor
Posts: 3076
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.0rc3 x86_64 + 4.0 i586
Location: Forests of Germany
Contact:

Ravas coding goodies

Post#56 by Rava » 19 Oct 2021, 17:58

You are in a softlinked directory and want to go to the real one?

Last time that happened to me I was using my 4th defined "Places" in Thunar, aka what's in ~/.config/gtk-3.0/bookmarks.
Since I do think creating a long list of "Places" would make it unübersichtlich, I decided to just keep my main 3 "Places" - ebook - sound - video - and create a new Folder named LINKS that holds all other folders that I need frequently.
Like my main Porteus_modules/5.0/ folder, or my debug/5.0_/ one…

I changed into the symlink of my /what/ever/debug/5.0_/ folder to compare file sizes of a screenshot I just made - png, webp & jpeg - to only keep the one with the smallest file size… realizing only two were in there when I expected three…

Opening mtpaint and looking into its recently opened or saved files listing in the File menu… I realized I saved the 3rd file in ".." by mistake, aka in /what/ever/debug/ instead of /what/ever/debug/5.0_/

But you can not simply change into ".." when you are in a symlinked folder, that would bring me only back to where the symlink itself sits: the LINKS folder in my case.

Opening a console and typing

Code: Select all

cd $(realpath .)
does the trick. I ponder if I should create a custom action for thunar "open recent folder's realpath in a new tab" or such.
But I think that most probably the occurrence of needing exactly that is so rare that I can again just "open terminal here" and then "cd $(realpath .)" and do what I want to do via console.

In the above example, "mv whatever.jpg 5.0_"

First I listed the most recent 26 files via lcrt since after typing this post I forgot the exact file name in the meantime.

Code: Select all

$ type lcrt
lcrt is a function
lcrt () 
{ 
    /bin/ls -oatr --time-style=long-iso "$@" | tail -n 26 | cut -c 14-93
}
Cave! The function is stupid like many of my similar aliases or functions are: they just presume $COLUMNS being 80 and calculate based on that. On my system that is usually the case so they all work okay as intended for me.
But when you have a different $COLUMNS "cut -c 14-93" might be a wrong preset for you.
Cheers!
Yours Rava

Post Reply