|
|
|
|
@ -6,6 +6,9 @@
|
|
|
|
|
- [Text Processing](#text-processing) |
|
|
|
|
- [Torrents](#torrents) |
|
|
|
|
- [PDF Tools](#pdf-tools) |
|
|
|
|
- [PDF Sheet Music](#pdf-sheet-music) |
|
|
|
|
- [Audiobooks](#audiobooks) |
|
|
|
|
- [Large File Transfer (rclone)](#large-file-transfer-rclone) |
|
|
|
|
|
|
|
|
|
--- |
|
|
|
|
|
|
|
|
|
@ -15,17 +18,21 @@
|
|
|
|
|
|
|
|
|
|
### List content types with node counts |
|
|
|
|
|
|
|
|
|
drush sqlq 'select count(node.nid) as node_count, node_type.type |
|
|
|
|
```bash |
|
|
|
|
drush sqlq 'select count(node.nid) as node_count, node_type.type |
|
|
|
|
from node |
|
|
|
|
inner join node_type on node.type = node_type.type |
|
|
|
|
group by node_type.type' |
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
### Filter results by keyword (e.g. "2014") |
|
|
|
|
|
|
|
|
|
drush sqlq 'select count(node.nid) as node_count, node_type.type |
|
|
|
|
```bash |
|
|
|
|
drush sqlq 'select count(node.nid) as node_count, node_type.type |
|
|
|
|
from node |
|
|
|
|
inner join node_type on node.type = node_type.type |
|
|
|
|
group by node_type.type' | grep 2014 |
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
--- |
|
|
|
|
|
|
|
|
|
@ -33,25 +40,31 @@
|
|
|
|
|
|
|
|
|
|
### Find and replace inside files (perl) |
|
|
|
|
|
|
|
|
|
# Single file type in current directory |
|
|
|
|
perl -pi -w -e 's/SEARCH_FOR/REPLACE_WITH/g;' *.txt |
|
|
|
|
```bash |
|
|
|
|
# Single file type in current directory |
|
|
|
|
perl -pi -w -e 's/SEARCH_FOR/REPLACE_WITH/g;' *.txt |
|
|
|
|
|
|
|
|
|
# Recursively across all file types |
|
|
|
|
perl -pi -w -e 's/thex/robertsonlibrary/g;' **/*.* |
|
|
|
|
# Recursively across all file types |
|
|
|
|
perl -pi -w -e 's/thex/robertsonlibrary/g;' **/*.* |
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
### Find and replace in file names |
|
|
|
|
|
|
|
|
|
# Rename files matching a pattern, verbose output shows what changed |
|
|
|
|
rename 's/livero/lives/g' **/*.* -v |
|
|
|
|
```bash |
|
|
|
|
# Rename files matching a pattern, verbose output shows what changed |
|
|
|
|
rename 's/livero/lives/g' **/*.* -v |
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
## <<<<<<< HEAD |
|
|
|
|
--- |
|
|
|
|
|
|
|
|
|
## Torrents |
|
|
|
|
|
|
|
|
|
### Download via magnet link (aria2c) |
|
|
|
|
|
|
|
|
|
# aria2c is a lightweight multi-protocol download utility |
|
|
|
|
aria2c -d ~/Downloads "magnetlink" |
|
|
|
|
```bash |
|
|
|
|
# aria2c is a lightweight multi-protocol download utility |
|
|
|
|
aria2c -d ~/Downloads "magnetlink" |
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
--- |
|
|
|
|
|
|
|
|
|
@ -59,105 +72,137 @@
|
|
|
|
|
|
|
|
|
|
### OCR a PDF (ocrmypdf) |
|
|
|
|
|
|
|
|
|
# Standard: optimize output, skip pages that already have a text layer |
|
|
|
|
ocrmypdf --optimize 3 --skip-text input.pdf output.pdf |
|
|
|
|
```bash |
|
|
|
|
# Standard: optimize output, skip pages that already have a text layer |
|
|
|
|
ocrmypdf --optimize 3 --skip-text input.pdf output.pdf |
|
|
|
|
|
|
|
|
|
# Aggressive: force re-OCR even if a text layer exists (useful for corrupt/bad layers), |
|
|
|
|
# set DPI manually, use page segmentation mode 1 (automatic with OSD) |
|
|
|
|
ocrmypdf --optimize 3 --image-dpi 300 --output-type pdf \ |
|
|
|
|
# Aggressive: force re-OCR even if a text layer exists (useful for corrupt/bad layers), |
|
|
|
|
# set DPI manually, use page segmentation mode 1 (automatic with OSD) |
|
|
|
|
ocrmypdf --optimize 3 --image-dpi 300 --output-type pdf \ |
|
|
|
|
--force-ocr --tesseract-pagesegmode 1 input.pdf output.pdf |
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
### Downsample a PDF to 72dpi (Ghostscript) |
|
|
|
|
|
|
|
|
|
# Single file |
|
|
|
|
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 \ |
|
|
|
|
```bash |
|
|
|
|
# Single file |
|
|
|
|
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 \ |
|
|
|
|
-dPDFSETTINGS=/screen \ |
|
|
|
|
-dNOPAUSE -dQUIET -dBATCH \ |
|
|
|
|
-sOutputFile=output.pdf input.pdf |
|
|
|
|
|
|
|
|
|
# Batch - processes all PDFs in current folder, preserves original filenames |
|
|
|
|
mkdir -p downsampled |
|
|
|
|
for f in *.pdf *.PDF; do |
|
|
|
|
# Batch - processes all PDFs in current folder, preserves original filenames |
|
|
|
|
mkdir -p downsampled |
|
|
|
|
for f in *.pdf *.PDF; do |
|
|
|
|
[ -f "$f" ] || continue |
|
|
|
|
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen \ |
|
|
|
|
-dNOPAUSE -dBATCH -dQUIET \ |
|
|
|
|
-sOutputFile="downsampled/$f" \ |
|
|
|
|
"$f" |
|
|
|
|
done |
|
|
|
|
done |
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
### Check image DPI in PDFs (pdfimages) |
|
|
|
|
|
|
|
|
|
# Print image info to terminal |
|
|
|
|
for f in *.pdf *.PDF; do |
|
|
|
|
```bash |
|
|
|
|
# Print image info to terminal |
|
|
|
|
for f in *.pdf *.PDF; do |
|
|
|
|
echo "=== $f ===" |
|
|
|
|
pdfimages -list "$f" |
|
|
|
|
echo "" |
|
|
|
|
done |
|
|
|
|
done |
|
|
|
|
|
|
|
|
|
# Save output to images_list.txt instead |
|
|
|
|
for f in *.pdf *.PDF; do |
|
|
|
|
# Save output to images_list.txt instead (appends; delete the file first to start fresh) |
|
|
|
|
for f in *.pdf *.PDF; do |
|
|
|
|
[ -f "$f" ] || continue |
|
|
|
|
echo "=== $f ===" >> images_list.txt |
|
|
|
|
pdfimages -list "$f" >> images_list.txt |
|
|
|
|
echo "" >> images_list.txt |
|
|
|
|
done |
|
|
|
|
done |
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
### Scan for CCITT encoding |
|
|
|
|
|
|
|
|
|
# CCITT is a fax-era compression format - flags PDFs that may cause compatibility issues |
|
|
|
|
for f in *.pdf *.PDF; do |
|
|
|
|
CCITT is a fax-era compression format - this flags PDFs that may cause compatibility issues. |
|
|
|
|
|
|
|
|
|
```bash |
|
|
|
|
for f in *.pdf *.PDF; do |
|
|
|
|
[ -f "$f" ] || continue |
|
|
|
|
if pdfimages -list "$f" 2>/dev/null | grep -q " ccitt "; then |
|
|
|
|
echo "$f uses CCITT" |
|
|
|
|
fi |
|
|
|
|
done |
|
|
|
|
done |
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
--- |
|
|
|
|
|
|
|
|
|
## PDF Sheet Music |
|
|
|
|
|
|
|
|
|
### Check page size |
|
|
|
|
|
|
|
|
|
```bash |
|
|
|
|
pdfinfo filename.pdf |
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
### Resize to letter |
|
|
|
|
|
|
|
|
|
```bash |
|
|
|
|
gs -sDEVICE=pdfwrite \ |
|
|
|
|
-sPAPERSIZE=letter \ |
|
|
|
|
-dFIXEDMEDIA \ |
|
|
|
|
-dPDFFitPage \ |
|
|
|
|
-dNOPAUSE -dBATCH \ |
|
|
|
|
-sOutputFile=output.pdf input.pdf |
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
### Audiobook commands |
|
|
|
|
### Batch resize to letter |
|
|
|
|
|
|
|
|
|
# cd to desired dir, create 'input' dir and put m4b file in it and run command |
|
|
|
|
docker run --rm -it \ |
|
|
|
|
```bash |
|
|
|
|
mkdir -p resized_music |
|
|
|
|
for f in *.pdf; do |
|
|
|
|
gs -sDEVICE=pdfwrite -sPAPERSIZE=letter -dFIXEDMEDIA -dPDFFitPage \ |
|
|
|
|
-dNOPAUSE -dBATCH -sOutputFile="resized_music/$f" "$f" |
|
|
|
|
done |
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
--- |
|
|
|
|
|
|
|
|
|
## Audiobooks |
|
|
|
|
|
|
|
|
|
### Split an m4b into MP3 chapters (m4b-tool via Docker) |
|
|
|
|
|
|
|
|
|
`cd` to the desired directory, create an `input` dir, put the m4b file in it, then run: |
|
|
|
|
|
|
|
|
|
```bash |
|
|
|
|
docker run --rm -it \ |
|
|
|
|
-v "$(pwd)":/data \ |
|
|
|
|
sandreas/m4b-tool \ |
|
|
|
|
split "/data/input/The Haunting of Hill House.m4b" \ |
|
|
|
|
--audio-format mp3 \ |
|
|
|
|
--audio-bitrate 128k \ |
|
|
|
|
--audio-channels 1 \ |
|
|
|
|
--output-dir "/data/split" |
|
|
|
|
--output-dir "/data/split" \ |
|
|
|
|
-vv |
|
|
|
|
|
|
|
|
|
``` |
|
|
|
|
ffmpeg -i Chaos.m4b -map 0:a -f segment -segment_times $(ffprobe -i Chaos.m4b -show_chapters -loglevel error | grep end_time | cut -d= -f2 | tr '\n' ',' | sed 's/,$//') -c:a libmp3lame -q:a 2 chapter_%03d.mp3 |
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
# check current dpi |
|
|
|
|
### Split an m4b by chapter (ffmpeg) |
|
|
|
|
|
|
|
|
|
for f in _.pdf_.PDF; do |
|
|
|
|
echo "=== Images in: $f ===" |
|
|
|
|
pdfimages -list "$f" |
|
|
|
|
echo "" |
|
|
|
|
done |
|
|
|
|
Reads chapter end times with ffprobe and writes `chapter_000.mp3`, `chapter_001.mp3`, etc. |
|
|
|
|
|
|
|
|
|
# Creates (or overwrites) images_list.txt in the current directory |
|
|
|
|
```bash |
|
|
|
|
ffmpeg -i Chaos.m4b -map 0:a -f segment \ |
|
|
|
|
-segment_times $(ffprobe -i Chaos.m4b -show_chapters -loglevel error \ |
|
|
|
|
| grep end_time | cut -d= -f2 | tr '\n' ',' | sed 's/,$//') \ |
|
|
|
|
-c:a libmp3lame -q:a 2 chapter_%03d.mp3 |
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
for f in _.pdf_.PDF; do |
|
|
|
|
if [ -f "$f" ]; then |
|
|
|
|
echo "=== Images in: $f ===" >> images_list.txt |
|
|
|
|
pdfimages -list "$f" >> images_list.txt |
|
|
|
|
echo "" >> images_list.txt |
|
|
|
|
fi |
|
|
|
|
done |
|
|
|
|
--- |
|
|
|
|
|
|
|
|
|
# scan for ccitt encoding |
|
|
|
|
## Large File Transfer (rclone) |
|
|
|
|
|
|
|
|
|
for f in _.pdf_.PDF; do |
|
|
|
|
[ -f "$f" ] || continue |
|
|
|
|
if pdfimages -list "$f" 2>/dev/null | grep -q " ccitt "; then |
|
|
|
|
echo "$f uses CCITT" |
|
|
|
|
fi |
|
|
|
|
done |
|
|
|
|
|
|
|
|
|
# Large file transfer to gdrive |
|
|
|
|
### Copy to Google Drive |
|
|
|
|
|
|
|
|
|
```bash |
|
|
|
|
rclone copy file_location file_destination \ |
|
|
|
|
--progress \ |
|
|
|
|
--transfers 4 \ |
|
|
|
|
@ -167,27 +212,4 @@ rclone copy file_location file_destination \
|
|
|
|
|
--drive-chunk-size 64M \ |
|
|
|
|
--log-file rclone.log \ |
|
|
|
|
--log-level INFO |
|
|
|
|
|
|
|
|
|
# PDF sheetmusic commands |
|
|
|
|
|
|
|
|
|
## check size |
|
|
|
|
|
|
|
|
|
`pdfinfo filename.pdf` |
|
|
|
|
|
|
|
|
|
## resize to letter |
|
|
|
|
|
|
|
|
|
`gs -sDEVICE=pdfwrite \ |
|
|
|
|
-sPAPERSIZE=letter \ |
|
|
|
|
-dFIXEDMEDIA \ |
|
|
|
|
-dPDFFitPage \ |
|
|
|
|
-dNOPAUSE -dBATCH \ |
|
|
|
|
-sOutputFile=output.pdf input.pdf` |
|
|
|
|
|
|
|
|
|
## batch resize to letter |
|
|
|
|
|
|
|
|
|
`mkdir -p resized_music |
|
|
|
|
for f in *.pdf; do |
|
|
|
|
gs -sDEVICE=pdfwrite -sPAPERSIZE=letter -dFIXEDMEDIA -dPDFFitPage -dNOPAUSE -dBATCH -sOutputFile="resized_music/$f" "$f" |
|
|
|
|
done` |
|
|
|
|
|
|
|
|
|
> > > > > > > f99d1ed ([nb] Edit: cli_commands.md) |
|
|
|
|
``` |
|
|
|
|
|