imageDownloader

Publicado por Guilherme Moreira de Oliveira (última atualização em 24/03/2026)

[ Hits: 62 ]

Homepage: https://rapoelho.com.br/

Download imageDownloader




Eu tenho um problema: Por vezes eu gosto de uma imagem que vi no Twitter e afins e quero baixar e organizar aquelas imagens. Com isso, me veio uma ideia: Por que não fazer um Script que baixa a imagem pela URL da imagem e renomeia ela com as informações nas URLs dos posts? E assim eu fiz.

Esse script precisa do YAD para o diálogo e o Curl para baixar as imagens.

E aqui tem mais detalhes de como ele funciona: https://rapoelho.com.br/posts/image-downloader/

  



Esconder código-fonte

#!/bin/bash

tempImg="/tmp/imagedownloader.txt"
picFolder="$(xdg-user-dir PICTURES)"
idFolder="$picFolder/ImageDownloader"

clearVariables () {
   urlImage=""
   urlPost=""
   filename=""
   
   rm $tempImg
}

downloadImage () {
   clearVariables
   yad --title="Image Downloader" --text="Favor, entrar com detalhes" \
      --form --separator="\n" \
      --field="URL da Imagem" \
      --field="URL da Postagem" \
      --width=400 --center > $tempImg

   ## Retirando Linhas Vazias do Arquivo
   sed -i '/^$/d' $tempImg

   ## Definindo Variáveis
   urlImage="$(head -n 1 $tempImg)"
   urlPost="$(tail -n 1 $tempImg)"

   if ! [[ -z `echo $urlPost | grep "x.com"` ]]; then
      author="$(echo $urlPost | cut -d '/' -f4)" ## Separando o Nome do Autor do Tuíte
      
      ## O Twitter tem dois tipos finais para as URLs dos tuítes: "?s=20" e "/photo/1".   
      if [[ -z `echo $urlPost | grep "photo"` ]]; then
         idImage="$(echo $urlPost | cut -d '/' -f6 | cut -d"?" -f1)" ## Separando o ID da Imagem, com o separador sendo o "?"
      else
         idImage="$(echo $urlPost | cut -d '/' -f6)" ## Separando o ID da Imagem, com o separador sendo o "/"
      fi
      
      fileExt="$(echo $urlImage | cut -d '/' -f5 | cut -d '&' -f1 | cut -d '=' -f2)"   
      filename="$author-Twitter-$idImage.$fileExt" ## Juntando tudo num Nome de Arquivo
   
   elif ! [[ -z `echo $urlPost | grep "bsky.app"` ]];then
      author="$(echo $urlPost | cut -d '/' -f5 | cut -d '.' -f1)"
      idImage="$(echo $urlPost | cut -d '/' -f7)"
      
      fileExt="$(echo $urlImage | cut -d '@' -f2)"
      filename="$author-bsky-$idImage.$fileExt"
      
   elif ! [[ -z `echo $urlPost | grep "pinterest"` ]];then
      idImage="$(echo $urlPost | cut -d '/' -f5)"
      
      fileExt="$(echo $urlImage | cut -d '/' -f8 | cut -d '.' -f2)"
      filename="pinterest-$idImage.$fileExt"
      
   elif ! [[ -z `echo $urlPost | grep "furaffinity"` ]];then
      author="$(echo $urlImage | cut -d '/' -f5)"
      idImage="$(echo $urlPost | cut -d '/' -f5)"
      
      fileExt="$(echo $urlImage | cut -d '/' -f7 | cut -d '.' -f3)"
      filename="$author-FurAffinity-$idImage.$fileExt"
   
   elif ! [[ -z `echo $urlPost | grep "deviantart"` ]];then
      author="$(echo $urlPost | cut -d '/' -f4)"
      idImage="$(echo $urlPost | cut -d '/' -f6)"
      
      fileExt="$(echo $urlImage | cut -d '/' -f10 | cut -d '.' -f2 | cut -d '?' -f1)"
      filename="$author-deviantArt_$idImage.$fileExt"
      
   elif ! [[ -z `echo $urlPost | grep "facebook"` ]];then
      idImage="$(echo $urlPost | cut -d '=' -f2 | cut -d '&' -f1)"
      
      fileExt="$(echo $urlImage | cut -d '/' -f6 | cut -d '?' -f1 | cut -d '.' -f2)"
      filename="Facebook-$idImage.$fileExt"
   fi

   if ! [[ -z "$filename" && -z "$urlImage" ]]; then 
      echo -e "\n## Baixando $filename..."
      curl -o $idFolder/$filename $urlImage
   fi
   
   printf "%s" "$*" "$filename" | cut -d '.' -f1 | xclip -selection clipboard
   
   sleep 3
   continue
}

continue () {
   yad --center -title="Image Downloader" \
    --image="dialog-question" \
    --text="Deseja Continuar?" \
    --button="Sim:0" \
    --button="Não:1"

   ret=$?

   if [[ $ret -eq 0 ]]; then
      downloadImage
   elif [[ $ret -eq 1 ]]; then
      exit
   else
      echo "O Image Downloader foi fechado."
   fi
}


downloadImage

Scripts recomendados

ShellBase - Templates Profissionais para o seu Shell Script

Distro Recognizer 0.05

Mudar campo em arquivo txt

matrix.sh (Wake up, neo...)

Catsort - Concatenar resultado filtrando e removendo repetidas


  

Comentários

Nenhum comentário foi encontrado.


Contribuir com comentário




Patrocínio

Site hospedado pelo provedor RedeHost.
Linux banner

Destaques

Artigos

Dicas

Tópicos

Top 10 do mês

Scripts