archivador.sh: probar con wget

This commit is contained in:
Cat /dev/Nulo 2021-12-01 13:06:10 -03:00
parent c782daefa7
commit e56454e223
2 changed files with 40 additions and 28 deletions

View file

@ -1,7 +1,7 @@
#!/bin/sh -e
if ! type aria2c > /dev/null; then
echo "Te falta instalar aria2."
if ! type wget > /dev/null; then
echo "Te falta instalar wget."
exit 1
fi
if ! type curl > /dev/null; then
@ -19,36 +19,18 @@ fi
echo "¡Gracias por contribuir!"
if ! curl -q localhost:6850 >/dev/null 2>/dev/null; then
echo "> Iniciando aria2..."
mkdir -p datos/
cd datos/
aria2c --enable-rpc --rpc-listen-all=false --rpc-listen-port=6850 --rpc-max-request-size=200M --max-concurrent-downloads=50 --max-connection-per-server=16 --continue --auto-file-renaming=false >> ../aria2.log &
sleep 3 # Esperar a que inicie
cd ..
fi
if test "$1" = "reintentar"; then
echo "Voy a alimentar a aria2 con las paginas que fallaron en bajarse."
echo "> Alimentando a aria2..."
cd aria2-feeder/
grep errorCode=22 ../aria2.log \
| grep -o "https\?://[^\"']\+" \
| lua feed-aria2.lua /dev/stdin \
| curl --data "@-" http://localhost:6850/jsonrpc >/dev/null
echo "Terminé de alimentar."
echo "> Moviendo el aria2.log actual a otra ubicación para no volver a descargar cosas..."
mv ../aria2.log "../aria2-$(date -Iseconds).log"
echo "Listo, ¡suerte!"
elif test -f lista-paginas.zst; then
if test -f lista-paginas.zst; then
echo "Voy a descargar las páginas en lista-paginas.zst."
echo "> Descomprimiendo lista..."
zstd -f -d lista-paginas.zst
echo "Son $(cat lista-paginas | wc -l) páginas."
echo "> Alimentando a aria2..."
cd aria2-feeder/
lua feed-aria2.lua ../lista-paginas | curl --data "@-" http://localhost:6850/jsonrpc >/dev/null
echo "Terminé de alimentar. ¡Suerte!"
echo "> Separando en varias listas..."
rm lista-*
lua otros-scripts/shard.lua < ./lista-paginas
echo "> Empezando a descargar..."
for lista in lista-*; do
wget --header='accept-encoding: br' --no-verbose --no-clobber --input-file="$lista" &
done
else
echo "No tengo ninguna lista para descargar. ¡Chau!"
fi

30
otros-scripts/shard.lua Normal file
View file

@ -0,0 +1,30 @@
local stdin = io.open("/dev/stdin")
local list = stdin:read("*a")
stdin:close()
local lineas = 0
-- Pass 1: contar lineas
for line in (list):gmatch('[^\r\n]+') do
lineas = lineas + 1
end
local cantidad_de_listas = 16
local cada_lista = lineas / cantidad_de_listas
local listas = {}
for i = 1,cantidad_de_listas do
listas[i] = io.open("lista-"..i, "w")
end
local index = 1
-- Pass 2: hacer listas
for line in (list):gmatch('[^\r\n]+') do
local lista = listas[math.ceil(index / cada_lista)]
lista:write(line,"\n")
index = index + 1
end
for _, lista in ipairs(listas) do
lista:close()
end