Advertisement
metalx1000

Instagram Crawler

Dec 28th, 2015
970
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.48 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. dir=`pwd`
  4. list="$dir/instacreep.txt";
  5.  
  6. getFile(){
  7.   prompt="Please select a file:"
  8.   options=( $(find -maxdepth 1 -print0 | xargs -0) )
  9.  
  10.   PS3="$prompt "
  11.   select opt in "${options[@]}" "Quit" ; do
  12.       if (( REPLY == 1 + ${#options[@]} )) ; then
  13.           exit
  14.  
  15.       elif (( REPLY > 0 && REPLY <= ${#options[@]} )) ; then
  16.           echo  "You picked `basename $opt` which is file $REPLY"
  17.           break
  18.  
  19.       else
  20.           echo "Invalid option. Try another one."
  21.       fi
  22.   done    
  23.   list="`pwd`/`basename $opt`"
  24.   echo $list
  25. }
  26.  
  27. if [ ! -f "$list" ]
  28. then
  29.   list="./"
  30.   while [ 1 ]
  31.   do
  32.     getFile
  33.     [[ -d "$list" ]] && cd "$list"
  34.     [[ -f "$list" ]] && break
  35.   done
  36. fi
  37.  
  38. if [ -z "$1" ]
  39. then
  40.   echo "Where do you want to save images to? [Enter for current dir]"
  41.   read savepath
  42. else
  43.   savepath="$1"
  44. fi
  45.  
  46. if [ -z "$savepath" ]
  47. then
  48.   echo "Saving to current dir"
  49. fi
  50.  
  51. creep(){
  52.   username="$1"
  53.   if cd "$savepath"
  54.   then
  55.      if [[ -d "${username}" ]]
  56.      then
  57.         echo "${username} exists, crawling."
  58.      else
  59.         mkdir "${username}"
  60.      fi
  61.      if cd "${username}"
  62.      then
  63.         mapfile -t links < <(wget --quiet -O - "https://www.instagram.com/${username}/media" | sed -e 's/standard/\n/g' | sed -e 's/_resolution":{"url":"//g'| grep -v status | sed -e 's/".*//g' -e 's/\\//g')
  64.         maxid=$(wget --quiet -O - "https://www.instagram.com/${username}/media" | sed -e 's/standard/\n/g' | grep -e "\"image\",\"id\"" | sed -e 's/.*\"image\",\"id\"\:\"//g' -e 's/\".*//g' | tail -n 1)
  65.         for i in "${links[@]}"
  66.         do
  67.               wget -nc "$i"
  68.         done
  69.         until [[ "$maxid" == "" ]]
  70.         do
  71.            mapfile -t links < <(wget --quiet -O - "https://www.instagram.com/${username}/media/?max_id=${maxid}" | sed -e 's/standard/\n/g' | sed -e 's/_resolution":{"url":"//g'| grep -v status | sed -e 's/".*//g' -e 's/\\//g')
  72.            maxid=$(wget --quiet -O - "https://www.instagram.com/${username}/media/?max_id=${maxid}" | sed -e 's/standard/\n/g' | grep -e "\"image\",\"id\"" | sed -e 's/.*\"image\",\"id\"\:\"//g' -e 's/\".*//g' | tail -n 1)
  73.            for i in "${links[@]}"
  74.            do
  75.                  wget -nc "$i"
  76.            done
  77.            sleep 1
  78.         done
  79.      fi
  80.   else
  81.      echo "INSTACREEP FAILED"
  82.   fi
  83. }
  84. if cd "$savepath"
  85. then
  86.    mapfile -t usernames < <(cat "$list")
  87.    for i in "${usernames[@]}"
  88.    do
  89.       creep "$i"
  90.    done
  91. else
  92.    echo "COULD NOT ENTER DIRECTORY"
  93. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement