Skip to content

Instantly share code, notes, and snippets.

@reinaldorauch
Created August 26, 2014 17:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reinaldorauch/ba0e950da104ac1698c3 to your computer and use it in GitHub Desktop.
Save reinaldorauch/ba0e950da104ac1698c3 to your computer and use it in GitHub Desktop.
Bash script for extracting and renaming a list of files downloaded on nipponsei.minglong.org
#!/bin/bash
# @Author: Reinaldo Antonio Camargo Rauch <reinaldorauch@gmail.com>
# @Date: 2014-08-26 13:02:39
# @Last Modified by: Reinaldo Antonio Camargo Rauch
# @Last Modified time: 2014-08-26 14:32:59
#
# Script para extrair e renomear as pastas de arquivos baixados do nipponsei
#
shopt -s nullglob
# Pega a lista de arquivos no formato
FILES=(\[Nipponsei\]*[\ _]*[\ _]\-[\ _]*[\ _]\[*\].zip)
# transforma a separação de itens de array em underline
IFS=$'_'
# itera sobre os arquivos
for i in "${FILES[@]}"; do
# pega os dados necessários do nome do arquivo (tipo, nome do album,
# single, etc. e artista)
NAMES=($(echo "$i" | sed "s/^\[Nipponsei\].\+[\ _]\(.\+\)[\ _]\-[\ _]\(.\+\)[\ _]\[\(.\+\)\].zip$/\1_\2_\3/"))
# verifica se já existe o diretório para o artista. Se não, cria
if [[ -d "./${NAMES[2]}" ]]; then
echo "Diretório já existe"
else
mkdir "./${NAMES[2]}"
fi
# Extrai os arquivos para a subpasta no formato [TIPO] NOME
unzip "$i" -d "./${NAMES[2]}/[${NAMES[0]}] ${NAMES[1]}"
done
unset IFS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment