Skip to content

Instantly share code, notes, and snippets.

@vitouXY
Last active November 13, 2018 02:16
Show Gist options
  • Save vitouXY/4857932024253ad23d9f221e5058fde9 to your computer and use it in GitHub Desktop.
Save vitouXY/4857932024253ad23d9f221e5058fde9 to your computer and use it in GitHub Desktop.
Download Edit Translate Upload · Text
#!/usr/bin/env bash
##!/usr/bin/env zsh
##!/usr/bin/env bash
##!/bin/bash -e
# ${HOME}/.local/bin/<mm>
set -o errexit
set -o nounset
set -o pipefail
set -o xtrace
# ${UID} -ge 1000 && -d ${HOME}/.local/bin
[[ -d "${HOME}/.lbin" ]] || (mkdir -p ${HOME}/.lbin)
if [[ -d ${HOME}/.lbin && -z $(echo ${PATH} | grep -o ${HOME}/.lbin) ]]
then
export PATH="${PATH}:${HOME}/.lbin"
fi
if ! test -x "`which curl`"; then echo "wget not found!"; exit 2 ; fi
if ! test -x "`which wget`"; then echo "wget not found!"; exit 2 ; fi
if ! test -x "`which lynx`"; then echo "lynx not found!"; exit 2 ; fi
if ! test -x "`which curl`"; then echo "curl not found!"; exit 2 ; fi
if ! test -x "`which sed`"; then echo "sed not found!"; exit 2 ; fi
if ! test -x "`which transh`"; then echo "transh not found!"; exit 2 ; fi
#git clone https://github.com/soimort/translate-shell
#cd translate-shell/
#make TARGET=zsh -j$(nproc) || make -j$(nproc)
#cp build/trans ~/.local/bin/transh
#
#wget --quiet -c git.io/trans -O ${HOME}/.local/bin/transh
#chmod +x ${HOME}/.local/bin/transh
GBL_V__ERRMSG_B="."
function GBL_F__ERRMSG() {
if [[ -z "${1}" ]]; then GBL_V__ERRMSG_A="--ERR--" ; fi ; GBL_V__ERRMSG_A="${1}"
echo -e "\n[$(date +%d%m%Y-%H%M%S)] - ${GBL_V__ERRMSG_B} ${GBL_V__ERRMSG_A}"
echo "[$(date +%d%m%Y-%H%M%S)] - ${GBL_V__ERRMSG_B} ${GBL_V__ERRMSG_A}" >> 0-err.txt
echo " ... Exiting." ; exit 2
}
function GLB_F__PRESSCTRLC() { GBL_F__ERRMSG 'Ctrl+C' ; }
trap "GLB_F__PRESSCTRLC" 1 2 3 6
GBL_V__DIRPATH="$(dirname "$0")"
if [[ ! -d "${GBL_V__DIRPATH}" ]]; then GBL_V__DIRPATH="$(pwd)" ; fi
##################################################################################
# #
# BEGIN USER CONFIG #
# #
##################################################################################
# #
# EN to ES !!! #
if [[ "$#" -lt "1" ]]; then
cat <<EOF
+ Usage:
$(basename $0) <nombreNovela>
+ Example for 'nvldl_ATG.cfg':
$(basename $0) 'ATG'
(C) 2018 All Rights Not Reserved - This program comes with ABSOLUTELY NO
WARRANTY. This is free software, and you are welcome to redistribute
it under the GNU GPL Version 3 (or later) License.
EOF
GBL_F__ERRMSG 'arg!'
fi
GBL_V__ARG="${1}"
#GBL_V__ARG="XX"
GBL_V__ERRMSG_B="${GBL_V__ARG}"
if [[ ! -f "$(pwd)/nvldl_${GBL_V__ARG}.cfg" ]]; then GBL_F__ERRMSG "$(pwd)/nvldl_${GBL_V__ARG}.cfg ?" ; fi
chmod +x "$(pwd)/nvldl_${GBL_V__ARG}.cfg"
echo "Directory: $(pwd)/"
################
# NOT OPTIONAL #
################
#GBL_U__NVLNAME='<YY_NVL>'
GBL_U__NVLNAME="CN_${GBL_V__ARG}"
#GBL_U__NVLNAME="JP_${GBL_V__ARG}"
source "$(pwd)/nvldl_${GBL_V__ARG}.cfg"
#. "nvldl_${GBL_V__ARG}.cfg"
# nvldl_XX.cfg
#### <<<<
#> function GBL_U__VARS() {
#> true
#> ################
#> # NOT OPTIONAL #
#> ################
#> # ${GBL_V__BOOK_} ${GBL_V__CHAPTER_} $(printf "%03d" ${GBL_V__CHAPTER_})
#> ##GBL_U__URL="file:/home/user/nvl-XX/TMO/volume-${GBL_V__BOOK_}/eps-${GBL_V__CHAPTER_}.html"
#> GBL_U__URL="http://example.com/nvl-XX/volume-${GBL_V__BOOK_}/eps-${GBL_V__CHAPTER_}.html"
#> #GBL_U__URL="/home/user/nvl-XX/TMO/volume-${GBL_V__BOOK_}/eps-${GBL_V__CHAPTER_}.txt"
#> GBL_U__FIRSTLINETEXT='Chapter'
#> GBL_U__FIRSTLINENUMB='97'
#> GBL_U__LASTLINETEXT='Share'
#> GBL_U__LASTLINETEXT2='Comment'
#> GBL_U__FOOTER='Get from example.com -- nixMTL.ES-Translated'
#> GBL_U__UPLOAD='0'
#> }
#> function GBL_U__KEEPWORDS() {
#> true
#> ################
#> # OPTIONAL #
#> ################
#> # <English En> -> <EspañolES>
#> sed -i -e 's/[E]nglish [Ee][Nn]/[EspañolES]/g' "${GBL_V__KEEPSPECIALWORDSUSER_A}"
#> }
#> function GBL_U__WORK() {
#> true
#> ################
#> # NOT OPTIONAL #
#> ################
#> # echo 'TShL2' > ....txt
#> # F__TASK_ <Book> <fromChapter> <toChapter> <Numb/Letter> <Url|none>
#> F__TASK_ 1 1 10 a none
#>}
#### >>>>
##################################################################################
# #
# END USER CONFIG #
# #
##################################################################################
#source "${GBL_V__DIRPATH}/incl.sh"
#. "${GBL_V__DIRPATH}/incl.sh"
function GBL_F__PINGCHECK_A() { ( ping 8.8.8.8 -c 3 >/dev/null 2>&1 ) && ( GBL_V__COUNT_CC=$((${GBL_V__COUNT_C} + 1)) ; GBL_V__COUNT_C="${GBL_V__COUNT_CC}" ; GBL_F__BNNRMSG "$ Ping(TRY:${GBL_V__COUNT_C})" ) || ( GBL_V__COUNT_CC=$((${GBL_V__COUNT_C} + 1)) ; GBL_V__COUNT_C="${GBL_V__COUNT_CC}" ; GBL_F__BNNRMSG "$ Ping(TRY:${GBL_V__COUNT_C}!)" ; sleep 2s ; GBL_F__PINGCHECK_A ) ; }
#!#function GBL_F__PINGCHECK() { GBL_V__COUNT_C='0' ; GBL_F__PINGCHECK_A ; }
function GBL_F__PINGCHECK() { true ; echo 'pong' ; }
# # ! Descargar texto web para archivo de texto SRC
function GBL_F__DONWLOADTEXT() {
true
GBL_F__BNNRMSG '$ ...'
if [[ -z "${1}" ]]; then GBL_F__ERRMSG '_DONWLOADTEXT' ; fi ; GBL_V__DONWLOADTEXT_A="${1}"
if [[ -z "${3}" ]]; then GBL_V__DONWLOADTEXT_C='none' ; fi ; GBL_V__DONWLOADTEXT_C="${3}"
if [[ -z "${2}" && -z "${3}" ]]; then GBL_F__ERRMSG '_DONWLOADTEXT' ; fi ; GBL_V__DONWLOADTEXT_B="${2}"
GBL_V__COUNT_B='0'
function GBL_F__DONWLOADTEXT_A() {
if [[ -f "${GBL_V__DONWLOADTEXT_A}" ]]; then
rm -rf "${GBL_V__DONWLOADTEXT_A}" || ( GBL_F__ERRMSG '_DONWLOADTEXT' )
fi
GBL_F__PINGCHECK
#echo -n 'D'
GBL_V__COUNT_BB=$((${GBL_V__COUNT_B} + 1)) ; GBL_V__COUNT_B="${GBL_V__COUNT_BB}" ; GBL_F__BNNRMSG "$ Downloading(TRY:${GBL_V__COUNT_B}!)"
#curl -sL "${GBL_V__DONWLOADTEXT_B} | html2text > "${GBL_V__DONWLOADTEXT_A}"
if [[ "${GBL_V__DONWLOADTEXT_C}" == "none" ]]; then
( lynx --dump "${GBL_V__DONWLOADTEXT_B}" > "${GBL_V__DONWLOADTEXT_A}" ) || ( GBL_F__DONWLOADTEXT_A )
else
( lynx --dump "${GBL_V__DONWLOADTEXT_C}" > "${GBL_V__DONWLOADTEXT_A}" ) || ( GBL_F__DONWLOADTEXT_A )
fi
}
GBL_F__DONWLOADTEXT_A
if [[ ! -r "${GBL_V__DONWLOADTEXT_A}" ]]; then GBL_F__ERRMSG '_DONWLOADTEXT' ; fi
if [[ ! -w "${GBL_V__DONWLOADTEXT_A}" ]]; then GBL_F__ERRMSG '_DONWLOADTEXT' ; fi
if [[ ! -s "${GBL_V__DONWLOADTEXT_A}" ]]; then GBL_F__ERRMSG '_DONWLOADTEXT' ; fi
}
# # ! Cortar texto para archivo de texto SRC
function GBL_F__SELECTTEXT() {
true
GBL_F__BNNRMSG '$ ...'
if [[ -z "${1}" ]]; then GBL_F__ERRMSG '_SELECTTEXT' ; fi ; GBL_V__SELECTTEXT_A="${1}"
if [[ -z "${2}" ]]; then GBL_F__ERRMSG '_SELECTTEXT' ; fi ; GBL_V__SELECTTEXT_B="${2}"
if [[ -z "${3}" ]]; then GBL_F__ERRMSG '_SELECTTEXT' ; fi ; GBL_V__SELECTTEXT_C="${3}"
if [[ -z "${4}" ]]; then GBL_F__ERRMSG '_SELECTTEXT' ; fi ; GBL_V__SELECTTEXT_D="${4}"
if [[ -z "${5}" ]]; then GBL_F__ERRMSG '_SELECTTEXT' ; fi ; GBL_V__SELECTTEXT_E="${5}"
if [[ -z "${6}" ]]; then GBL_F__ERRMSG '_SELECTTEXT' ; fi ; GBL_V__SELECTTEXT_F="${6}"
if [[ ! -r "${GBL_V__SELECTTEXT_A}" ]]; then GBL_F__ERRMSG '_SELECTTEXT' ; fi
if [[ ! -w "${GBL_V__SELECTTEXT_A}" ]]; then GBL_F__ERRMSG '_SELECTTEXT' ; fi
if [[ ! -s "${GBL_V__SELECTTEXT_A}" ]]; then GBL_F__ERRMSG '_SELECTTEXT' ; fi
if [[ -f "${GBL_V__SELECTTEXT_B}" ]]; then
rm -rf "${GBL_V__SELECTTEXT_B}" || ( GBL_F__ERRMSG '_SELECTTEXT' )
fi
GBL_V__SELECTTEXT_FIRSTLINE=$(cat "${GBL_V__SELECTTEXT_A}" | grep -n "${GBL_V__SELECTTEXT_C}" | cut -d':' -f1 | grep -o '[[:digit:]]*' | head -n1)
if [[ -z "${GBL_V__SELECTTEXT_FIRSTLINE}" ]]; then
GBL_V__SELECTTEXT_FIRSTLINE="${GBL_V__SELECTTEXT_D}"
fi
GBL_V__SELECTTEXT_LASTLINE=$(cat "${GBL_V__SELECTTEXT_A}" | grep -n "${GBL_V__SELECTTEXT_E}" | cut -d':' -f1 | grep -o '[[:digit:]]*' | head -n1)
if [[ -z "${GBL_V__SELECTTEXT_LASTLINE}" ]]; then
GBL_V__SELECTTEXT_LASTLINE=$(cat "${GBL_V__SELECTTEXT_A}" | grep -n "${GBL_V__SELECTTEXT_F}" | cut -d':' -f1 | grep -o '[[:digit:]]*' | head -n1)
fi
if [[ -z "${GBL_V__SELECTTEXT_FIRSTLINE}" || -z "${GBL_V__SELECTTEXT_LASTLINE}" ]]; then GBL_F__ERRMSG '_SELECTTEXT' ; fi
sed -n ${GBL_V__SELECTTEXT_FIRSTLINE},${GBL_V__SELECTTEXT_LASTLINE}p "${GBL_V__SELECTTEXT_A}" > "${GBL_V__SELECTTEXT_B}" || ( GBL_F__ERRMSG '_SELECTTEXT' )
if [[ ! -r "${GBL_V__SELECTTEXT_B}" ]]; then GBL_F__ERRMSG '_SELECTTEXT' ; fi
if [[ ! -w "${GBL_V__SELECTTEXT_B}" ]]; then GBL_F__ERRMSG '_SELECTTEXT' ; fi
if [[ ! -s "${GBL_V__SELECTTEXT_B}" ]]; then GBL_F__ERRMSG '_SELECTTEXT' ; fi
}
# # ! Corregir palabras (segun usuario) en archivo de texto SRC
function GBL_F__KEEPSPECIALWORDSUSER() {
true
GBL_F__BNNRMSG '$ ...'
if [[ -z "${1}" ]]; then GBL_F__ERRMSG '_KEEPSPECIALWORDSUSER' ; fi ; GBL_V__KEEPSPECIALWORDSUSER_A="${1}"
if [[ ! -r "${GBL_V__KEEPSPECIALWORDSUSER_A}" ]]; then GBL_F__ERRMSG '_KEEPSPECIALWORDSUSER' ; fi
if [[ ! -w "${GBL_V__KEEPSPECIALWORDSUSER_A}" ]]; then GBL_F__ERRMSG '_KEEPSPECIALWORDSUSER' ; fi
if [[ ! -s "${GBL_V__KEEPSPECIALWORDSUSER_A}" ]]; then GBL_F__ERRMSG '_KEEPSPECIALWORDSUSER' ; fi
#sed -i -e 's/[E]nglish [Ee][Nn]/[EspañolES]/g' "${GBL_V__KEEPSPECIALWORDSUSER_A}"
GBL_U__KEEPWORDS
}
# # ! Encerrar palabras en mayuscula en archivo de texto SRC
function GBL_F__KEEPSPECIALWORDS() {
true
GBL_F__BNNRMSG '$ ...'
if [[ -z "${1}" ]]; then GBL_F__ERRMSG '_KEEPSPECIALWORDS' ; fi ; GBL_V__KEEPSPECIALWORDS_A="${1}"
if [[ ! -r "${GBL_V__KEEPSPECIALWORDS_A}" ]]; then GBL_F__ERRMSG '_KEEPSPECIALWORDS' ; fi
if [[ ! -w "${GBL_V__KEEPSPECIALWORDS_A}" ]]; then GBL_F__ERRMSG '_KEEPSPECIALWORDS' ; fi
if [[ ! -s "${GBL_V__KEEPSPECIALWORDS_A}" ]]; then GBL_F__ERRMSG '_KEEPSPECIALWORDS' ; fi
# :"Ab-Az":
sed -i -e 's/\"\([[:upper:]][[:lower:]]\+-[[:alpha:]]\+\)\"/"[\1]"/g' "${GBL_V__KEEPSPECIALWORDS_A}"
# :"Ab-Az:
sed -i -e 's/\"\([[:upper:]][[:lower:]]\+-[[:alpha:]]\+\)/"[\1]/g' "${GBL_V__KEEPSPECIALWORDS_A}"
# :Ab-Az":
sed -i -e 's/\([[:upper:]][[:lower:]]\+-[[:alpha:]]\+\)\"/[\1]"/g' "${GBL_V__KEEPSPECIALWORDS_A}"
# :"Ab-Az":
sed -i -e 's/\“\([[:upper:]][[:lower:]]\+-[[:alpha:]]\+\)\”/"[\1]"/g' "${GBL_V__KEEPSPECIALWORDS_A}"
# :"Ab-Az:
sed -i -e 's/\“\([[:upper:]][[:lower:]]\+-[[:alpha:]]\+\)/"[\1]/g' "${GBL_V__KEEPSPECIALWORDS_A}"
# :Ab-Az":
sed -i -e 's/\([[:upper:]][[:lower:]]\+-[[:alpha:]]\+\)\”/[\1]"/g' "${GBL_V__KEEPSPECIALWORDS_A}"
# :, Ab-Az:
sed -i -e 's/,[[:space:]]\([[:upper:]][[:lower:]]\+-[[:alpha:]]\+\)/, [\1]/g' "${GBL_V__KEEPSPECIALWORDS_A}"
# : Az0 Ab-Az:
sed -i -e 's/[[:space:]]\([[:alnum:]]\+\)[[:space:]]\([[:upper:]][[:lower:]]\+-[[:alpha:]]\+\)/ \1 [\2]/g' "${GBL_V__KEEPSPECIALWORDS_A}"
# : Az0] Ab-Az:
sed -i -e 's/[[:space:]]\([[:alnum:]]\+\]\)[[:space:]]\([[:upper:]][[:lower:]]\+-[[:alpha:]]\+\)/ \1 [\2]/g' "${GBL_V__KEEPSPECIALWORDS_A}"
# :Az0 Ab-Az:
sed -i -e 's/\([[:alnum:]]\+\)[[:space:]]\([[:upper:]][[:lower:]]\+-[[:alpha:]]\+\)/ \1 [\2]/g' "${GBL_V__KEEPSPECIALWORDS_A}"
# :Az0] Ab-Az:
sed -i -e 's/\([[:alnum:]]\+\]\)[[:space:]]\([[:upper:]][[:lower:]]\+-[[:alpha:]]\+\)/ \1 [\2]/g' "${GBL_V__KEEPSPECIALWORDS_A}"
#
# :"Ab":
sed -i -e 's/\"\([[:upper:]][[:lower:]]\+\)\"/"[\1]"/g' "${GBL_V__KEEPSPECIALWORDS_A}"
# :Ab":
sed -i -e 's/\([[:upper:]][[:lower:]]\+\)\"/[\1]"/g' "${GBL_V__KEEPSPECIALWORDS_A}"
# :"Ab":
sed -i -e 's/\“\([[:upper:]][[:lower:]]\+\)\”/"[\1]"/g' "${GBL_V__KEEPSPECIALWORDS_A}"
# :Ab":
sed -i -e 's/\([[:upper:]][[:lower:]]\+\)\”/[\1]"/g' "${GBL_V__KEEPSPECIALWORDS_A}"
# :, Ab:
sed -i -e 's/,[[:space:]]\([[:upper:]][[:lower:]]\+\)/, [\1]/g' "${GBL_V__KEEPSPECIALWORDS_A}"
# : Az0 Ab:
sed -i -e 's/[[:space:]]\([[:alnum:]]\+\)[[:space:]]\([[:upper:]][[:lower:]]\+\)/ \1 [\2]/g' "${GBL_V__KEEPSPECIALWORDS_A}"
# : Az0] Ab:
sed -i -e 's/[[:space:]]\([[:alnum:]]\+\]\)[[:space:]]\([[:upper:]][[:lower:]]\+\)/ \1 [\2]/g' "${GBL_V__KEEPSPECIALWORDS_A}"
# :Az0 Ab:
sed -i -e 's/\([[:alnum:]]\+\)[[:space:]]\([[:upper:]][[:lower:]]\+\)/\1 [\2]/g' "${GBL_V__KEEPSPECIALWORDS_A}"
# :Az0] Ab:
sed -i -e 's/\([[:alnum:]]\+\]\)[[:space:]]\([[:upper:]][[:lower:]]\+\)/\1 [\2]/g' "${GBL_V__KEEPSPECIALWORDS_A}"
#
# “#” "#"
# [[:punct:]] - \"
# [[:blank:]][[:space:]] \s
# [[:alnum:]] [[:alpha:]]
}
# # ! Corregir lineas/intros en archivo de texto SRC
function GBL_F__SPECIALLINESEDIT() {
true
GBL_F__BNNRMSG '$ ...'
if [[ -z "${1}" ]]; then GBL_F__ERRMSG '_SPECIALLINESEDIT' ; fi ; GBL_V__SPECIALLINESEDIT_A="${1}"
if [[ ! -r "${GBL_V__SPECIALLINESEDIT_A}" ]]; then GBL_F__ERRMSG '_SPECIALLINESEDIT' ; fi
if [[ ! -w "${GBL_V__SPECIALLINESEDIT_A}" ]]; then GBL_F__ERRMSG '_SPECIALLINESEDIT' ; fi
if [[ ! -s "${GBL_V__SPECIALLINESEDIT_A}" ]]; then GBL_F__ERRMSG '_SPECIALLINESEDIT' ; fi
sed -i -e ':a;N;$!ba;s/\n\n/\n_\n/g' "${GBL_V__SPECIALLINESEDIT_A}"
sed -i -e ':a;N;$!ba;s/\n\s\s\s/ /g' "${GBL_V__SPECIALLINESEDIT_A}"
sed -i -e 's/_\s/\n/g' "${GBL_V__SPECIALLINESEDIT_A}"
}
# # ! Editar lineas con caracteres especiales en archivo de texto SRC
function GBL_F__SPECIALCHARACTERSEDIT() {
true
GBL_F__BNNRMSG '$ ...'
if [[ -z "${1}" ]]; then GBL_F__ERRMSG '_SPECIALCHARACTERSEDIT' ; fi ; GBL_V__SPECIALCHARACTERSEDIT_A="${1}"
if [[ ! -r "${GBL_V__SPECIALCHARACTERSEDIT_A}" ]]; then GBL_F__ERRMSG '_SPECIALCHARACTERSEDIT' ; fi
if [[ ! -w "${GBL_V__SPECIALCHARACTERSEDIT_A}" ]]; then GBL_F__ERRMSG '_SPECIALCHARACTERSEDIT' ; fi
if [[ ! -s "${GBL_V__SPECIALCHARACTERSEDIT_A}" ]]; then GBL_F__ERRMSG '_SPECIALCHARACTERSEDIT' ; fi
sed -i -e 's/\./.\n[.]\n/g' "${GBL_V__SPECIALCHARACTERSEDIT_A}"
#sed -i -e 's/\,/,\n[,]\n/g' "${GBL_V__SPECIALCHARACTERSEDIT_A}"
sed -i -e 's/\!/!\n[!]\n/g' "${GBL_V__SPECIALCHARACTERSEDIT_A}"
sed -i -e 's/\?/?\n[?]\n/g' "${GBL_V__SPECIALCHARACTERSEDIT_A}"
sed -i -e 's/\“/“\n[“]\n/g' "${GBL_V__SPECIALCHARACTERSEDIT_A}"
sed -i -e 's/\”/”\n[”]\n/g' "${GBL_V__SPECIALCHARACTERSEDIT_A}"
sed -i -e 's/\"/"\n["]\n/g' "${GBL_V__SPECIALCHARACTERSEDIT_A}"
}
# # ! Corregir lineas con caracteres especiales en archivo de texto ES
function GBL_F__SPECIALCHARACTERSUNDO() {
true
GBL_F__BNNRMSG '$ ...'
if [[ -z "${1}" ]]; then GBL_F__ERRMSG '_SPECIALCHARACTERSUNDO' ; fi ; GBL_V__SPECIALCHARACTERSUNDO_A="${1}"
if [[ ! -r "${GBL_V__SPECIALCHARACTERSUNDO_A}" ]]; then GBL_F__ERRMSG '_SPECIALCHARACTERSUNDO' ; fi
if [[ ! -w "${GBL_V__SPECIALCHARACTERSUNDO_A}" ]]; then GBL_F__ERRMSG '_SPECIALCHARACTERSUNDO' ; fi
if [[ ! -s "${GBL_V__SPECIALCHARACTERSUNDO_A}" ]]; then GBL_F__ERRMSG '_SPECIALCHARACTERSUNDO' ; fi
sed -i -e ':a;N;$!ba;s/\.\n\[.]\n/. /g' "${GBL_V__SPECIALCHARACTERSUNDO_A}"
#sed -i -e ':a;N;$!ba;s/,\n\[,]\n/, /g' "${GBL_V__SPECIALCHARACTERSUNDO_A}"
#sed -i -e ':a;N;$!ba;s/:\n\[,]\n/, /g' "${GBL_V__SPECIALCHARACTERSUNDO_A}"
sed -i -e ':a;N;$!ba;s/!\n\[!]\n/! /g' "${GBL_V__SPECIALCHARACTERSUNDO_A}"
sed -i -e ':a;N;$!ba;s/?\n\[?]\n/? /g' "${GBL_V__SPECIALCHARACTERSUNDO_A}"
sed -i -e ':a;N;$!ba;s/“\n\[“]\n/ “ /g' "${GBL_V__SPECIALCHARACTERSUNDO_A}"
sed -i -e ':a;N;$!ba;s/”\n\[”]\n/ ” /g' "${GBL_V__SPECIALCHARACTERSUNDO_A}"
sed -i -e ':a;N;$!ba;s/"\n\["]\n/ " /g' "${GBL_V__SPECIALCHARACTERSUNDO_A}"
sed -i -e ':a;N;$!ba;s/\n\[.]\n/. /g' "${GBL_V__SPECIALCHARACTERSUNDO_A}"
#sed -i -e ':a;N;$!ba;s/\n\[,]\n/, /g' "${GBL_V__SPECIALCHARACTERSUNDO_A}"
sed -i -e ':a;N;$!ba;s/\n\[!]\n/! /g' "${GBL_V__SPECIALCHARACTERSUNDO_A}"
sed -i -e ':a;N;$!ba;s/\n\[?]\n/? /g' "${GBL_V__SPECIALCHARACTERSUNDO_A}"
sed -i -e ':a;N;$!ba;s/\n\[“]\n/ “ /g' "${GBL_V__SPECIALCHARACTERSUNDO_A}"
sed -i -e ':a;N;$!ba;s/\n\[”]\n/ ” /g' "${GBL_V__SPECIALCHARACTERSUNDO_A}"
sed -i -e ':a;N;$!ba;s/\n\["]\n/ " /g' "${GBL_V__SPECIALCHARACTERSUNDO_A}"
sed -i -e ':a;N;$!ba;s/\n_\n/\n\n/g' "${GBL_V__SPECIALCHARACTERSUNDO_A}"
}
function GBL_F__OKFOOTERADD() {
true
GBL_F__BNNRMSG '$ ...'
if [[ -z "${1}" ]]; then GBL_F__ERRMSG '_OKFOOTERADD' ; fi ; GBL_V__OKFOOTERADD_A="${1}"
if [[ ! -r "${GBL_V__OKFOOTERADD_A}" ]]; then GBL_F__ERRMSG '_OKFOOTERADD' ; fi
if [[ ! -w "${GBL_V__OKFOOTERADD_A}" ]]; then GBL_F__ERRMSG '_OKFOOTERADD' ; fi
if [[ ! -s "${GBL_V__OKFOOTERADD_A}" ]]; then GBL_F__ERRMSG '_OKFOOTERADD' ; fi
#[[ $(head -n1 "${GBL_V__OKFOOTERADD_A}") = "TShL1" ]] && true || ( sed -i '1i TShL1' "${GBL_V__OKFOOTERADD_A}" )
cat "${GBL_V__OKFOOTERADD_A}" | grep -q 'TShL2' && true || ( echo -e "\nTShL2" >> "${GBL_V__OKFOOTERADD_A}" )
}
# # ! Traducir archivo de texto SRC
function GLB_F__TRANSLATETEXT() {
true
GBL_F__BNNRMSG '$ ...'
if [[ -z "${1}" ]]; then GBL_F__ERRMSG '_TRANSLATETEXT' ; fi ; GBL_V__TRANSLATETEXT_A="${1}"
if [[ -z "${2}" ]]; then GBL_F__ERRMSG '_TRANSLATETEXT' ; fi ; GBL_V__TRANSLATETEXT_B="${2}"
## ####
GBL_V__TRANSLATETEXT_C='en'
GBL_V__TRANSLATETEXT_D='es'
## ####
if [[ ! -r "${GBL_V__TRANSLATETEXT_A}" ]]; then GBL_F__ERRMSG '_TRANSLATETEXT' ; fi
if [[ ! -w "${GBL_V__TRANSLATETEXT_A}" ]]; then GBL_F__ERRMSG '_TRANSLATETEXT' ; fi
if [[ ! -s "${GBL_V__TRANSLATETEXT_A}" ]]; then GBL_F__ERRMSG '_TRANSLATETEXT' ; fi
GBL_V__COUNT_A='0'
function GLB_F__TRANSLATETEXT_A() {
if [[ -f "${GBL_V__TRANSLATETEXT_B}" ]]; then
rm -rf "${GBL_V__TRANSLATETEXT_B}" || ( GBL_F__ERRMSG '_TRANSLATETEXT' )
fi
GBL_F__PINGCHECK
#echo -n 'T'
GBL_V__COUNT_AA=$((${GBL_V__COUNT_A} + 1)) ; GBL_V__COUNT_A="${GBL_V__COUNT_AA}" ; GBL_F__BNNRMSG "$ Translating(TRY:${GBL_V__COUNT_A}!)"
## #### >
# -brief
#( echo -e '...\n' ; transh -no-view -no-auto -no-autocorrect -lang "${GBL_V__TRANSLATETEXT_D}" -from "${GBL_V__TRANSLATETEXT_C}" -to "${GBL_V__TRANSLATETEXT_D}" "file://$(pwd)/${GBL_V__TRANSLATETEXT_A}" > "${GBL_V__TRANSLATETEXT_B}" ) || ( GBL_F__ERRMSG '_TRANSLATETEXT' )
( transh \
-show-original N \
-show-translation N \
-show-alternatives Y \
-show-original-phonetics N \
-show-translation-phonetics N \
-show-prompt-message N \
-show-languages N \
-show-original-dictionary N \
-show-dictionary N \
-no-theme -no-ansi -no-bidi -no-warn \
-no-autocorrect -no-auto -no-view -lang "${GBL_V__TRANSLATETEXT_D}" -from "${GBL_V__TRANSLATETEXT_C}" -to "${GBL_V__TRANSLATETEXT_D}" \
-input "${GBL_V__TRANSLATETEXT_A}" > "${GBL_V__TRANSLATETEXT_B}" ) || ( GLB_F__TRANSLATETEXT_A )
#( transh \
# -brief \
# -show-original N \
# -show-translation N \
# -show-alternatives N \
# -show-original-phonetics N \
# -show-translation-phonetics N \
# -show-prompt-message N \
# -show-languages N \
# -show-original-dictionary N \
# -show-dictionary N \
# -no-theme -no-ansi -no-bidi -no-warn \
# -no-autocorrect -no-auto -no-view -lang "${GBL_V__TRANSLATETEXT_D}" -from "${GBL_V__TRANSLATETEXT_C}" -to "${GBL_V__TRANSLATETEXT_D}" \
# -input "${GBL_V__TRANSLATETEXT_A}" -output "${GBL_V__TRANSLATETEXT_B}" ) || ( GLB_F__TRANSLATETEXT_A )
# ( GLB_F__TRANSLATETEXT_A )
#( GBL_F__ERRMSG '_TRANSLATETEXT' )
## #### <
if [[ ! -r "${GBL_V__TRANSLATETEXT_B}" ]]; then GBL_F__ERRMSG '_TRANSLATETEXT' ; fi
if [[ ! -w "${GBL_V__TRANSLATETEXT_B}" ]]; then GBL_F__ERRMSG '_TRANSLATETEXT' ; fi
if [[ ! -s "${GBL_V__TRANSLATETEXT_B}" ]]; then GBL_F__ERRMSG '_TRANSLATETEXT' ; fi
echo "${GBL_U__FOOTER}" >> "${GBL_V__TRANSLATETEXT_B}"
GLB_F__TRANSLATETEXT_B
}
function GLB_F__TRANSLATETEXT_B() {
#[[ $(head -n1 "${GBL_V__TRANSLATETEXT_B}") = "TShL1" ]] && true || ( sed -i '1i TShL1' "${GBL_V__TRANSLATETEXT_B}" )
if [[ -f "${GBL_V__TRANSLATETEXT_B}" ]]; then
cat "${GBL_V__TRANSLATETEXT_B}" | grep -q 'TShL2' && true || ( GLB_F__TRANSLATETEXT_A )
else
GLB_F__TRANSLATETEXT_A
fi
}
GLB_F__TRANSLATETEXT_B
}
# # ! Subir archivo de texto ES
function GLB_F__UPLOADTEXT() {
true
GBL_F__BNNRMSG '$ ...'
if [[ -z "${1}" ]]; then GBL_F__ERRMSG '_UPLOADTEXT' ; fi ; GBL_V__UPLOADTEXT_A="${1}"
if [[ -z "${2}" ]]; then GBL_F__ERRMSG '_UPLOADTEXT' ; fi ; GBL_V__UPLOADTEXT_B="${2}"
## ###
GBL_V__UPLOADTEXT_C='http://txet.netii.net/'
GBL_V__UPLOADTEXT_D='TXET.txt'
## ###
GBL_V__COUNT_D='0'
function GLB_F__UPLOADTEXT_A() {
GBL_F__PINGCHECK
GBL_V__COUNT_DD=$((${GBL_V__COUNT_D} + 1)) ; GBL_V__COUNT_D="${GBL_V__COUNT_DD}" ; GBL_F__BNNRMSG "$ Uploading(TRY:${GBL_V__COUNT_D}!)"
curl --silent -i -F folder=${GBL_V__UPLOADTEXT_A} -F file=@${GBL_V__UPLOADTEXT_B} "${GBL_V__UPLOADTEXT_C}" | grep -q "${GBL_V__UPLOADTEXT_D}" && true > /dev/null 2>&1 || (GLB_F__UPLOADTEXT_A)
##enscript -B --margins=10:10: -f Courier@13/18 ${GBL_V__UPLOADTEXT_B} --output=- | ps2pdf - > ${GBL_V__UPLOADTEXT_B}.pdf
#cupsfilter ${GBL_V__UPLOADTEXT_B} > ${GBL_V__UPLOADTEXT_B}.pdf
}
GLB_F__UPLOADTEXT_A
}
function GBL_F__WORKCHAPTER() {
true
if [[ -z "${1}" ]]; then GBL_F__ERRMSG '_WORKCHAPTER' ; fi ; GBL_V__FILERAW_A="${1}"
if [[ -z "${2}" ]]; then GBL_F__ERRMSG '_WORKCHAPTER' ; fi ; GBL_V__FILEEN_B="${2}"
if [[ -z "${3}" ]]; then GBL_F__ERRMSG '_WORKCHAPTER' ; fi ; GBL_V__FILEES_C="${3}"
if [[ -z "${4}" ]]; then GBL_F__ERRMSG '_WORKCHAPTER' ; fi ; GBL_V__FIRSTLINE_D="${4}"
if [[ -z "${5}" ]]; then GBL_F__ERRMSG '_WORKCHAPTER' ; fi ; GBL_V__FIRSTLINE_E="${5}"
if [[ -z "${6}" ]]; then GBL_F__ERRMSG '_WORKCHAPTER' ; fi ; GBL_V__LASTLINE_F="${6}"
if [[ -z "${7}" ]]; then GBL_F__ERRMSG '_WORKCHAPTER' ; fi ; GBL_V__LASTLINE_G="${7}"
if [[ -z "${8}" ]]; then GBL_F__ERRMSG '_WORKCHAPTER' ; fi ; GBL_V__URL_H="${8}"
if [[ -z "${9}" ]]; then GBL_V__URL_I='none' ; fi ; GBL_V__URL_I="${9}"
GBL_F__DONWLOADTEXT "${GBL_V__FILERAW_A}" "${GBL_V__URL_H}" "${GBL_V__URL_I}"
GBL_F__SELECTTEXT "${GBL_V__FILERAW_A}" "${GBL_V__FILEEN_B}" "${GBL_V__FIRSTLINE_D}" "${GBL_V__FIRSTLINE_E}" "${GBL_V__LASTLINE_F}" "${GBL_V__LASTLINE_G}"
#cat "${GBL_V__FILERAW_A}" > "${GBL_V__FILEEN_B}"
#
#cat "${GBL_V__URL_H}" > "${GBL_V__FILEEN_B}"
GBL_F__SPECIALLINESEDIT "${GBL_V__FILEEN_B}"
GBL_F__SPECIALCHARACTERSEDIT "${GBL_V__FILEEN_B}"
GBL_F__KEEPSPECIALWORDSUSER "${GBL_V__FILEEN_B}"
GBL_F__KEEPSPECIALWORDS "${GBL_V__FILEEN_B}"
GBL_F__OKFOOTERADD "${GBL_V__FILEEN_B}"
GLB_F__TRANSLATETEXT "${GBL_V__FILEEN_B}" "${GBL_V__FILEES_C}"
GBL_F__SPECIALCHARACTERSUNDO "${GBL_V__FILEES_C}"
}
function GBL_F__BNNRMSG() {
echo -en '\r '
echo -en "\r[$(date +%d%m%Y-%H%M%S)] - ${GBL_U__NVLNAME}_BOOK[${GBL_V__BOOK3}]_CHAPTER[${GBL_V__CHAPTER_}/${GBL_V__CHAPTO_C}](${GBL_V__EXT_D}) ${1}"
}
function F__TASK_() {
if [[ -z "${1}" ]]; then GBL_F__ERRMSG '_TASK_' ; fi ; GBL_V__BOOK_="${1}"
if [[ -z "${2}" ]]; then GBL_F__ERRMSG '_TASK_' ; fi ; GBL_V__CHAPFROM_B="${2}"
if [[ -z "${3}" ]]; then GBL_F__ERRMSG '_TASK_' ; fi ; GBL_V__CHAPTO_C="${3}"
if [[ -z "${4}" ]]; then GBL_F__ERRMSG '_TASK_' ; fi ; GBL_V__EXT_D="${4}"
if [[ -z "${5}" ]]; then GBL_V__MODURL_E='none' ; fi ; GBL_V__MODURL_E="${5}"
function GLB_F__TASK__A() {
if [[ -f "${GBL_V__CHAPTERFNAMEES_I}" ]]; then
cat "${GBL_V__CHAPTERFNAMEES_I}" | grep -q 'TShL2' && true || ( GLB_F__TASK__B )
else
GLB_F__TASK__B
fi
}
function GLB_F__TASK__B() {
GBL_F__WORKCHAPTER "${GBL_V__CHAPTERFNAMERAW_G}" "${GBL_V__CHAPTERFNAMEEN_H}" "${GBL_V__CHAPTERFNAMEES_I}" "${GBL_U__FIRSTLINETEXT}" "${GBL_U__FIRSTLINENUMB}" "${GBL_U__LASTLINETEXT}" "${GBL_U__LASTLINETEXT2}" "${GBL_U__URL}" "${GBL_V__MODURL_E}"
GLB_F__TASK__A
}
#for i in {1..10}
#for i in `seq 1 10`
for i in `seq ${GBL_V__CHAPFROM_B} ${GBL_V__CHAPTO_C}`
do
GBL_V__CHAPTER_="${i}"
GBL_V__CHAPTER5=$(printf "%05d" ${GBL_V__CHAPTER_})
GBL_V__BOOK3=$(printf "%03d" ${GBL_V__BOOK_})
GBL_U__VARS
if [[ -z "${GBL_U__NVLNAME}" ]]; then GBL_F__ERRMSG '_TASK_' ; fi
if [[ -z "${GBL_U__URL}" ]]; then GBL_F__ERRMSG '_TASK_' ; fi
if [[ -z "${GBL_U__FIRSTLINETEXT}" ]]; then GBL_F__ERRMSG '_TASK_' ; fi
if [[ -z "${GBL_U__FIRSTLINENUMB}" ]]; then GBL_F__ERRMSG '_TASK_' ; fi
if [[ -z "${GBL_U__LASTLINETEXT}" ]]; then GBL_F__ERRMSG '_TASK_' ; fi
if [[ -z "${GBL_U__LASTLINETEXT2}" ]]; then GBL_F__ERRMSG '_TASK_' ; fi
if [[ -z "${GBL_U__UPLOAD}" ]]; then GBL_F__ERRMSG '_TASK_' ; fi
GBL_V__CHAPTERFNAME_F="${GBL_U__NVLNAME}_B${GBL_V__BOOK3}_C${GBL_V__CHAPTER5}-${GBL_V__EXT_D}_"
GBL_V__CHAPTERFNAMERAW_G="${GBL_V__CHAPTERFNAME_F}.raw"
GBL_V__CHAPTERFNAMEEN_H="${GBL_V__CHAPTERFNAME_F}.src"
GBL_V__CHAPTERFNAMEES_I="${GBL_V__CHAPTERFNAME_F}.es.txt"
GBL_V__ERRMSG_B="${GBL_U__NVLNAME}_B${GBL_V__BOOK3}_C${GBL_V__CHAPTER5}-${GBL_V__EXT_D}"
GBL_F__BNNRMSG '!'
GLB_F__TASK__A
if [[ -f "${GBL_V__CHAPTERFNAMEEN_H}" ]]; then rm -rf "${GBL_V__CHAPTERFNAMEEN_H}" ; fi
if [[ -f "${GBL_V__CHAPTERFNAMERAW_G}" ]]; then rm -rf "${GBL_V__CHAPTERFNAMERAW_G}" ; fi
if [[ "${GBL_U__UPLOAD}" == '1' ]]; then
GLB_F__UPLOADTEXT "${GBL_U__NVLNAME}" "${GBL_V__CHAPTERFNAMEES_I}"
fi
done
}
if [[ ! -d "${GBL_U__NVLNAME}" ]]; then mkdir "${GBL_U__NVLNAME}" ; fi
chmod g+rws,u+rws "${GBL_U__NVLNAME}" ; cd "${GBL_U__NVLNAME}/"
GBL_U__WORK
echo "... !!!"
exit 0
# <?PHP //upload.php
# chdir('/home/Novels/');
#if( ( isset( $_POST['directory'] )) && ( empty( $_POST['directory'] ) == false ) && ( empty( $_FILES['ficher']['name'] ) == false ) && ( $_FILES['ficher']['type'] == 'text/plain' ) ) {
# if( !mkdir( $_POST['directory'], 0777, true ) );
# if( is_dir( $_POST['directory'] . DIRECTORY_SEPARATOR )) {
# $filepath = $_POST['directory'].DIRECTORY_SEPARATOR;
# $filename = $_FILES['ficher']['name'];
# $filedata = $_FILES['ficher']['tmp_name'];
# if( $filedata != '' && $filename != '' && $filepath != '' ) copy( $filedata, $filepath . $filename );
# //move_uploaded_file( $filedata, $filepath . $filename );
# print_r('FicherIsOK');
# exit;
# }
#}
# //curl --silent -i -F directory=${DIRNAME} -F ficher=@${FILENAME} http://txet.netoor.net/upload.php | grep -q "FicherIsOK" && true > /dev/null 2>&1 || echo " ERR "
# ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment