GeekTips
109 subscribers
586 photos
3 videos
77 files
231 links
Linux Mint, video encoding, ffmpeg, geek tips, regex, pdf manipulation, substitcher, mpv config
Download Telegram
You can try to align chapter numbers by adding blank pages or deleting some unwanted pages so the table of content numbers match the actual PDF page number.

Or you can use vim and a plugin called vim-NumUtils.
sudo apt install vim
download vim-NumUtils and after unzipping put the doc/ and plugin/ into the ~/.vim directory. It can do NumUtilsAdd, NumUtilsSub, NumUtilsMul, NumUtilsDiv

Here all the actual PDF page numbers are 3 pages behind the listed page numbers.

:% NumUtilsSub 3, '\,'
sometimes I type a space after the , so to get those too do
:% NumUtilsSub 3, '\, '

Quick vim commands
:wq - write/save file and quit
:q - quit
u - undo
Ctrl-R - redo
i - insert mode ESC to quit insert mode
a - append text
% is a range for entire document
Great vim guide
{
foreword by the author,6
{
poem:,
first, my country, 15
this is my own, my dear, and native land,16
god made me free, 21
to the stars and stripes,33

Renumber chapter page numbers in text file with math operations. How to do it with sed and awk
sometimes I'll type a space after the , so let's substitute space after a comma followed by a number then the 2nd substitution separated with a ; does same but has no space
sed -i -r 's/(, )([0-9])/,\2/; s/,([0-9])/%\1/' toc.txt

-i insert in place the /s (substitutions) looking for , followed by any number of digits. Some chapter titles have , in them and it'll ignore them
-r extended regex so don't need to escape capturing groups
\2 2nd capture group put a , then single digit to remove space
\1 is the first capture group ([0-9]) which is just a single digit and re-inserting it after the %
without touching other commas in chapter names
{
foreword by the author%6
{
poem:,
first, my country%15
this is my own, my dear, and native land%16
god made me free%21
to the stars and stripes%33

Now subtract 3 from the chapter page numbers
awk -F% '{if (/%/) {print $1 "," $2-3} else {print $0}}' > renumbered.txt

-F% field separator , would work but if the chapters contain , which they do sometimes it screws up fields so needs to be something else like %
if (/%/)
there's a match for % on the line then
print $1 print field 1 which is the text string up till the %
","
will print a comma between $1 and $2 so it's ready for titlecase
print $2-3
print the number after the % and subtract 3 can do + addition * multiplication / division also
else print $0 prints entire line if no match

changes to:
{
foreword by the author,3
{
poem:,
first, my country,12
this is my own, my dear, and native land,13
god made me free,18
to the stars and stripes,30

now it's ready for title case
titlecase -f renumbered.txt -o chapters.txt
changes to:
{
Foreword by the Author,3
{
Poem:,
First, My Country,12
This Is My Own, My Dear, and Native Land,13
God Made Me Free,18
To the Stars and Stripes,30

combine all three commands on one line
sed -i -r 's/(, )([0-9])/,\2/; s/,([0-9])/%\1/' toc.txt && awk -F% '{if (/%/) {print $1 "," $2-3} else {print $0}}' toc.txt > renumbered.txt &&  titlecase -f renumbered.txt -o chapters.txt

then booky to add chapters to pdf
booky.sh SomeBook.pdf chapters.txt

If you want to offset the pages numbers by +5 just change $2-3 to $2+5
sed -i -r 's/(, )([0-9])/,\2/; s/,([0-9])/%\1/' toc.txt && awk -F% '{if (/%/) {print $1 "," $2+5} else {print $0}}' toc.txt > renumbered.txt &&  titlecase -f renumbered.txt -o chapters.txt

changes to:
{
Foreword by the Author,11
{
Poem:,
First, My Country,20
This Is My Own, My Dear, and Native Land,21
God Made Me Free,26
To the Stars and Stripes,38
Tree Style Tab firefox /librewolf extension. I never have that many tabs open but today I did as internet was slow and didn't wanna bookmark them which I ended up having to do anyway. Tried various color tabs and ended only liking this one which is for Tree Style Tabs.
Color Tabs settings anything that started with a, b or c would be green and d, e or f blue, etc.
https?:\/\/(www\.)?[-a-c]
https?:\/\/(www\.)?[-d-f]
Stumbled upon Sidebery and I prefer this one over Tree Style Tab. Sidebery has a bookmark side panel too. I'm aware Tree Style Tab has a bookmark extension.

Can create more panels for your tabs. Has a modern interface / feeling to it. One of those extensions I can live without but will try it out. One huge thing for me is when hovering over sideberry bookmarks it'll also display full URL unlike with regular tabs.
Sidebery — the only settings I changed to get it to my liking was Settings | Appearance | Color Scheme dark

Settings | Styles editor |Tabs
Background color on hover (brown) #63452cff
Active tab background color (purple) #613583ff

Settings | Styles editor |Bookmarks
Bookmark background color on hover (brown) #63452cff
Bookmark background color on click (purple) #613583ff
Closed folder color (blue) #62a0eaff
Expanded folder color (orange) #ff7800ff (not working now..bug)
Modifying opus chaptered audiobooks

linux (some are multiplatform) apps that can

add or remove cover image
tageditor
puddletag
kid3

Modify existing opus chapter names from opus audiobook
MusicBrainz Picard
Ex Falso
puddletag (Edit | Extended tags)
kid3

add metadata tag from filename (so one can name chapter names from filenames before adding to freac)
puddletag
functions choose Filename to Tag
Patter: %title%

kid3
Format: (up arrow) %f
Format: (down arrow) %{title} press Tag 2

Ex Falso
Tags from Path put <title> also can save it as a pattern named whatever

MusicBrainz Picard
Options | Options | User Interface
add Parse File Names
then just select all Ctrl-A and click Parse File Names


Since puddletag and kid3 can do all three I'll quickly show them
puddle tag right click and choose Extended Tags or Ctrl-E. Each chapter name you edit will create a popup dialog. Deleting or removing a cover image is quite easy.
puddletag naming chapters based on filename. Click function choose Filename to Tag and Pattern: %title% ..files can be batch renamed like this.
kid3 edit opus chapter names
kid3 add or delete a cover image
Smart Title Case Converter. This one is the best online one and does it great. Doesn't matter all that much if you use AP, Bluebook, Chicago...just avoid NYTimes as that had weird exceptions.

For an explanation of which words NOT to capitalize see https://titlecaseconverter.com/words-to-capitalize/

So if I want to rename mp3 files with Smart Title case before adding to freac to make an opus chaptered audiobook it's not so easy. Sure any filemanager can Title Case them but not Smart Title case them. Ex Falso has a plugin for Human Title Case but it only works on one file at a time. So here's the bash script I wrote to do that. The end part of renaming old files to new I found online.
#/bin/bash
ls *.mp3 | sort -n > filenames
sed -i -r 's/(^[0-9]{1,3})/\1:/; s/.mp3//' filenames
titlecase -f filenames -o new
sed -i -r 's/(.$)/\1.mp3/' new
ls *.mp3 | sort -n > old
while IFS= read -r old <&3 && IFS= read -r new <&4; do
mv -i -- "$old" "$new"
done 3< old 4< new
rm filenames new old
try this in a test directory
touch '1 this is to test out chapters.mp3' '2 lord of the rings.mp3' '3 the sun rises in the west.mp3' '44 of all the various species.mp3' '45 never again but tomorrow.mp3' '101 should work till 999 king louis xiv here.mp3' '241 but will not work with period between numbers.mp3'

have these mp3 files that look like so:
1 this is to test out chapters.mp3
2 lord of the rings.mp3
3 the sun rises in the west.mp3
44 of all the various species.mp3
45 never again but tomorrow.mp3
101 should work till 999 king louis xiv here.mp3
241 but will not work with period between numbers.mp3

And the goal is to get them to be like so:
1: This Is to Test Out Chapters.mp3
2: Lord of the Rings.mp3
3: The Sun Rises in the West.mp3
44: Of All the Various Species.mp3
45: Never Again but Tomorrow.mp3
101: Should Work Till 999 King Louis XIV Here.mp3
241: But Will Not Work With Period Between Numbers.mp3

1.2 some chapter
1.3 some chapter
these won't work as it'll put 1:.2 and 1:.3

You must add : or a - after a number otherwise titlecase won't capitalize the word after the number.
45 the flowers
45 the Flowers
instead of
45: the flowers
45: The Flowers

it will make xiv capital but not if it's at the end though. I'll share my titlecase.txt file I have in ~/. directory for the titlecase script.

Just name this script chaptersrename.sh
chmod a+x chaptersrename.sh
sudo chaptersrename.sh /usr/bin

also put echo before mv like echo mv if just wish to preview the changes. You do need to replace mp3 three places are better just rename your file extensions from say m4a to mp3 temporarily
titlecase.txt
1.8 KB
This is the ~/.titlecaste.txt file I use for exceptions for titlecase script. A huge list of roman numerals I II I. II. I, II,
remember though if at end of chapter it won't convert it
1: the life of louis xiv
1: The Life of Louis Xiv

5: the life of Louis xiv and other stuff
5: The Life of Louis XIV and Other Stuff

a small preview of text

i.e.
e.g.
etc.
#Roman Numerals 1-99 and . + , after
I
II
III
IV
V
VI
VII
VIII
IX
X
XI
XII
XIII
XIV
XV
Normal Title Case is so simple yet is to is Is To (not Is to) of the is Of The and but is But and in the is In The

Hopefully file managers will add this Human / Smart Title Case in the future
Decided to learn python and should've learned programming many years ago but never did. So here are my links. No idea how long it's gonna take.
{{{Tutorials)}}}

https://learnxinyminutes.com/docs/python/
https://www.w3schools.com/python/
https://www.pythontutorial.net/getting-started/what-is-python/
https://python-course.eu/python-tutorial/
https://www.programiz.com/python-programming
https://www.tutorialspoint.com/python/
https://thepythonguru.com/getting-started-with-python/
https://www.tutorialsteacher.com/python
https://python.land/python-tutorial
https://www.stavros.io/tutorials/python/
https://docs.python.org/3/tutorial
https://www.codecademy.com/learn/dscp-python-fundamentals/modules/dscp-python-syntax/cheatsheet
https://note.nkmk.me/en/python-post-summary/

{{{Quizzes, Challenges, Exercises}}}

https://www.tutorialsteacher.com/online-test/python-test
https://www.learnpython.org/
https://www.practicepython.org/
https://www.pythonchallenge.com/
https://pythontutor.com/ (click examples for step by step)
https://pynative.com/python/
https://www.w3resource.com/python-exercises/
https://www.codechef.com/practice (advanced)

{{{Exercises but must login}}}

https://www.hackerrank.com
https://exercism.org

{{{Books Online (HTML)}}}

https://python.swaroopch.com/ (A Byte of Python)
https://diveintopython3.net/
https://inventwithpython.com/
https://anandology.com/python-practice-book/
https://openbookproject.net/thinkcs/python/english3e/
https://www.py4e.com/book.php (Python for Everybody) many languages

{{{Code Examples}}}

https://www.learnbyexample.org/python-dictionary/
https://www.30secondsofcode.org/python/
Best of Python ~400 open source projects
https://github.com/ml-tooling/best-of-python
Python Recipes
https://code.activestate.com/recipes/langs/python/

{{{Advanced}}}

The Elements of Python Style PEP8
https://github.com/amontalenti/elements-of-python-style

short how to articles
https://fluentprogramming.com/

Python Algorithms
https://github.com/TheAlgorithms/Python/blob/master/DIRECTORY.md

Python Patterns and Idioms
https://github.com/faif/python-patterns

Python Examples for Education
https://github.com/geekcomputers/Python

Programming Projects to Solve with Solutions
https://github.com/karan/Projects

Beginner Friendly Projects
https://github.com/MunGell/awesome-for-beginners#python

Awesome Python frameworks, libraries, software and resources.
https://github.com/vinta/awesome-python

Awesome machine learning frameworks, libraries and software
https://github.com/josephmisiti/awesome-machine-learning#python

Math problems
https://projecteuler.net/
Python IDEs

tried out a few on linux
Thonny, Pyzo 
Atom ...installed packages linter-python-pep8 and python-indent (pep8 auto-indentation) and it's quite good. I've used Atom in the past. Edit | Select Grammar | Python
PyCharm
Community Edition - yes it's impressive but java app and 4x as much memory hogger as other IDEs
Geany - just a text editor but can hit execute (F5) and terminal popups up with python shell then hit enter to close it each time. Auto complete worked well

eric7 don't install flatpak as it won't work and same goes for spyder. eric7 just didn't like it.

spyder version 5 I installed with pip
python3 -m venv spyder-env
source spyder-env/bin/activate
&& spyder

This is my 2nd favorite with iPython console, variable explorer, great documentation, help system, Ctrl-I on any object

To run it make a bash script to
source ~/spyder-env/bin/activate && spyder

Favorite one is Wing 8 Personal edition which is free. Just installed deb file and changed to dark theme ...yes they want you to eventually buy their $180/yr Pro version eventually but I'm just learning python and personal edition is always free. Great documentation, tips, source browser, source assistant.
Wing 8 Personal Edition Python IDE — my favorite
Spyder 5.3.3 — a very close 2nd favorite