gullinbursti

awkin fb mobile!

Jul 31st, 2011
459
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 10.08 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # BASH login&example by http://360percents.com
  4. # v1.0
  5. #
  6. pass="derp"
  7. host_url="http://m.facebook.com"
  8.  
  9. album_ind=1
  10. album_inc=1
  11.  
  12. album_page=1
  13.  
  14. photo_ind=0
  15. photo_inc=12
  16.  
  17. ref_id=""
  18.  
  19. output_path="pages"
  20. photo_path="photos"
  21. cookie_path="/tmp/fb_cookie"
  22.  
  23.  
  24. touch $cookie_path
  25.  
  26. isLoggedIn=false
  27. host_html=$(curl -s -c ${cookie_path} -A "Mozilla/5.0" "${host_url}")
  28. form_action=$(echo "${host_html}" | tr '"' "\n" | grep "https://www.facebook.com/login.php")
  29. form_fields=$(echo "${host_html}" | sed -e 's/.*<form//' | sed -e 's/form>.*//' | tr '/>' "\n" | grep 'input ' | grep -v "email\|pass")
  30.  
  31. #FUNCTION PARSES FORM DATA LIKE HIDDEN INPUTS
  32. function parse_form() {
  33.    form_fields="${1}"
  34.    params=""
  35.    
  36.    for (( i=1; i<=`echo "${form_fields}" | wc -l`; i++ )); do
  37.       name=$(echo "${form_fields}" | sed -n "${i}"p | tr ' ' "\n" | grep 'name' | cut -d '"' -f 2)
  38.       value=$(echo "${form_fields}" | sed -n "${i}"p | tr ' ' "\n" | grep 'value' | cut -d '"' -f 2)
  39.       params="${params}${name}=${value}&"
  40.    done
  41. }
  42.  
  43. function parse_profile() {
  44.    printf "Parsing Profile...\n"
  45.    
  46.    profile_html=$(curl -s -b ${cookie_path} -c ${cookie_path} -A 'Mozilla/5.0' --location "http://m.facebook.com/profile.php?id=${1}")
  47.    echo -n "${profile_html}" > "${output_path}/m.profile_[${fb_id}].htm"
  48. }
  49.  
  50. function parse_info() {
  51.    printf "Parsing Info [%s]... " $1
  52.    
  53.    info_html=$(curl -s -b ${cookie_path} -c ${cookie_path} -A 'Mozilla/5.0' --location "http://m.facebook.com/profile.php?id=${1}&v=info")
  54.    echo -n "${info_html}" > "${output_path}/m.info_[${fb_id}].htm"
  55.    
  56.    ref_id=$(echo "${info_html}" | tr '"' "\n" | grep "refid=" | sed 's/.*=\(.*\).*$/\1/' | head -n 1)
  57.    handle_name=$(echo "${info_html}" | tr '"' "\n" | grep ">facebook\.com" | sed 's/.*com\/\(.*\)\<\/a.*/\1/')
  58.    printf "(%s)... " "${handle_name}"
  59.    
  60.    friends_tot=$(echo "${info_html}" | tr '"' "\n" | grep "Total Friends" | sed 's/.* (\(.*\)).*$/\1/' | sed 's/,//')
  61.    album_tot=0
  62.    
  63.    sex_usr=$(echo "${info_html}" | tr '"' "\n" | grep -A 4 "Sex" | tail -n 1 | sed 's/.\(.*\)\<\/div.*$/\1/')
  64.    college_info=$(echo "${info_html}" | tr '"' "\n" | grep -A 4 "College" | tail -n 1 | sed 's/\>\<div\>\(.*\)\<br \/\>.*$/\1/')
  65.    hs_info=$(echo "${info_html}" | tr '"' "\n" | grep -A 4 "High School" | tail -n 1 | sed 's/\>\<div\>\(.*\)\<\/div\>\<\/div\>.*$/\1/')
  66.    
  67.    friends_url=$(echo "${info_html}" | tr '"' "\n" | grep "friends.php?id" | sed 's/\&amp\;/\&/g' | head -n 1 | sed 's/.\(.*\)$/\1/')
  68.    if [ "${friends_url}" ]; then printf "Friends (%d)... " "${friends_tot}"; fi
  69.    
  70.    wall_url=$(echo "${info_html}" | tr '"' "\n" | grep "feed" | sed 's/\&amp\;/\&/g' | sed 's/.\(.*\)$/\1/')
  71.    if [ "${wall_url}" ]; then printf "Wall... "; fi
  72.    
  73.    photos_url=$(echo "${info_html}" | tr '"' "\n" | grep "v\=photos" | head -n 1 | sed 's/\&amp\;/\&/g' | sed 's/.\(.*\)$/\1/')
  74.    if [ "${photos_url}" ]; then printf "Photos... "; fi
  75.      
  76.    echo
  77. }
  78.  
  79. function parse_friends() {
  80.    printf "Parsing Friends [%s]...\n" "${fb_id}"
  81.      
  82.    friends_html=$(curl -s -b ${cookie_path} -c ${cookie_path} -A 'Mozilla/5.0' --location "http://m.facebook.com/${friends_url}")
  83.    echo -n "${friends_html}" > "${output_path}/m.friends_[${fb_id}].htm"
  84. }
  85.  
  86.  
  87. function parse_photos() {
  88.    printf "Parsing Photos [%s]...\n" "${fb_id}"
  89.    
  90.    local cnt="10"
  91.    
  92.    photos_html=$(curl -s -b ${cookie_path} -c ${cookie_path} -A 'Mozilla/5.0' --location "http://m.facebook.com/${photos_url}")
  93.    echo -n "${photos_html}" > "${output_path}/m.photos-1_[${fb_id}].htm"
  94.    
  95.    mkdir -p "${photo_path}/${fb_id}"
  96.    parse_albums "${photos_html}"
  97.    
  98.    #allPhotos_url=$(echo "${photos_html}" | tr '"' "\n" | grep "set\=t" | sed 's/\&amp\;/\&/g' | sed 's/.\(.*\)$/\1/')
  99.    #if [ "${allPhotos_url}" ]; then printf "All Photos... ";fi
  100.      
  101.    next_page=$(echo "${photos_html}" | tr '"' "\n" | grep "p\=${album_inc}" | sed 's/\&amp\;/\&/g' | sed 's/.\(.*\)$/\1/')
  102.    if [ "${next_page}" ]; then
  103.       album_inc=10
  104.       next_albums
  105.    fi
  106.    
  107.    echo
  108. }
  109.  
  110.  
  111. function next_albums() {
  112.    
  113.    photos_html=$(curl -s -b ${cookie_path} -c ${cookie_path} -A 'Mozilla/5.0' --location "http://m.facebook.com/photos.php?id=${fb_id}&p=${album_inc}&refid=${ref_id}")
  114.    echo -n "${photos_html}" > "${output_path}/m.photos-$(( ($album_inc / 10) + 1 ))_[${fb_id}].htm"
  115.    
  116.    parse_albums "${photos_html}"
  117.    
  118.    album_inc=$(( $album_inc + 10 ))
  119.    
  120.    next_page=$(echo "${photos_html}" | tr '"' "\n" | grep "p\=${album_inc}" | sed 's/\&amp\;/\&/g' | sed 's/.\(.*\)$/\1/')
  121.    if [ "${next_page}" ]; then
  122.       next_albums; fi
  123. }
  124.  
  125.  
  126.  
  127. function parse_albums() {
  128.    printf "Albums Page: %d [%s]\n" $(( ($album_inc / 10) + 1 )) "http://m.facebook.com/photos.php?id=${fb_id}&p=${album_inc}&refid=${ref_id}"
  129.    
  130.    album_urls=$(echo "${1}" | tr '"' "\n" | grep "set\=a" | sed 's/\&amp\;/\&/g')
  131.    
  132.    (IFS=$'\n'
  133.       for (( i=1; i<=`echo "${album_urls}" | wc -l`; i++ )); do
  134.          album_url=$(echo "${album_urls}" | sed -n "${i}"p | sed 's/\&amp\;/\&/g' | sed 's/.\(.*\)$/\1/')
  135.          album_id=$(echo "${album_url}" | sed 's/.*a\.\(.*\)\&.*$/\1/' | sed 's/\&op\='$album_inc'\&v//')
  136.          album_name=$(echo "${1}" | tr '"' "\n" | grep -A 1 "${album_id}" | tail -n 1 | sed 's/^\>\<span\>\(.*\)\<\/span\>.*$/\1/' | sed 's/\&amp\;/\&/g' | sed 's/^\>\<strong\>.*$/Profile Pictures/' | sed 's/\&\#039\;/‘/g' | sed 's/\&quot\;/‘‘/g' | sed 's/\&hearts\;/♥/g')
  137.          photo_tot=$(echo "${1}" | tr '"' "\n" | grep -A 3 "${album_id}" | tail -n 1 | sed 's/.\(.*\) photos.*$/\1/' | sed 's/.*Profile Pictures.*/0/')        
  138.          album_tot=$(( ($album_inc + $i) - 1 ))
  139.          album_page=0
  140.          photo_ind=0
  141.          printf "\t[%d] %s (%d) [%s]\n" $album_tot "${album_name}" "${photo_tot}" "${album_id}"
  142.          parse_album
  143.       done
  144.    )
  145. }
  146.  
  147.  
  148. function parse_album() {
  149.    printf "Parsing Album %s [%s]...\n" "${album_name}" "${album_id}"
  150.    
  151.    short_id=$(echo "${album_id}" | awk -F\. '{print $2}')
  152.    photos_html=$(curl -s -b ${cookie_path} -c ${cookie_path} -A 'Mozilla/5.0' --location "http://m.facebook.com/${album_url}")
  153.    echo -n "${photos_html}" > "${output_path}/m.album-${short_id}-${album_page}_[${fb_id}].htm"
  154.    
  155.    parse_photo "${photos_html}"
  156.    
  157.    next_page=$(echo "${photos_html}" | tr '"' "\n" | grep "s\=12" | sed 's/\&amp\;/\&/g' | sed 's/.\(.*\)$/\1/')
  158.    if [ "${next_page}" ]; then
  159.       photo_inc=12
  160.       next_photos; fi
  161. }
  162.  
  163. function parse_photo() {  
  164.    photo_urls=$(echo "${1}" | tr '"' "\n" | grep "\_t\.jpg" | sed 's/_t/_n/')
  165.    
  166.    if [ ! "${photo_urls}" ]; then
  167.       photo_urls=$(echo "${1}" | tr '"' "\n" | grep "\/t.*\.jpg" | sed 's/\/t\(.*\)\.jpg/\/n\1\.jpg/'); fi
  168.    
  169.    (IFS=$'\n'
  170.       for (( i=1; i<=`echo "${photo_urls}" | wc -l`; i++ )); do
  171.          photo_url=$(echo "${photo_urls}" | sed -n "${i}"p)
  172.          photo_id=$(echo "${photo_url}" | awk -F\_ '{print $2}')
  173.          photo_page=$(printf "photo.php?fbid=%s&id=%s&set=%s&refid=%s" "${photo_id}" "${fb_id}" "${album_id}" "${ref_id}")
  174.          photo_name=$(echo "${photo_url}" | awk -F\/ '{print $NF}')
  175.          photo_ind=$(( $photo_ind + 1 ))
  176.          printf "\t[%d] %s\n" $photo_ind "${photo_url}"
  177.          echo "${photo_url}" >> "${photo_path}/${fb_id}/${short_id}_${album_name}.txt"
  178.       done
  179.    )
  180. }
  181.  
  182. function next_photos() {
  183.    
  184.    short_id=$(echo "${album_id}" | awk -F\. '{print $2}')
  185.    photos_html=$(curl -s -b ${cookie_path} -c ${cookie_path} -A 'Mozilla/5.0' --location "http://m.facebook.com/${album_url}&s=${photo_inc}")
  186.    echo -n "${photos_html}" > "${output_path}/m.album-${short_id}-${album_page}_[${fb_id}].htm"
  187.    
  188.    parse_photo "${photos_html}"
  189.    
  190.    photo_inc=$(( $photo_inc + 12 ))
  191.    
  192.    next_page=$(echo "${photos_html}" | tr '"' "\n" | grep "s\=${photo_inc}" | sed 's/\&amp\;/\&/g' | sed 's/.\(.*\)$/\1/')
  193.    if [ "${next_page}" ]; then
  194.       next_photos; fi
  195.    
  196. }
  197.  
  198.  
  199. function download_photos() {
  200.    
  201.    (IFS=$'\n'
  202.       printf "Parsing Album %s [%s]...\n" "${album_name}" "${album_id}"
  203.    
  204.    
  205.       for f in `find "${photo_path}/${fb_id}" -type f -name "*.txt"`; do
  206.          echo "${f}"
  207.          
  208.          album_id=$(echo `basename ${f}` | awk -F\_ '{print $1}')
  209.          album_name=$(echo `basename ${f}` | awk -F\_ '{print $2}' | sed 's/\.txt//')
  210.          album_path="${photo_path}/${fb_id}/albums/${album_id}_${album_name}"
  211.          
  212.          mkdir -p "./${album_path}"
  213.      
  214.          while read l; do
  215.             img_name=$(echo "${l}" | awk -F\/ '{print $NF}')
  216.             echo "${img_name}"
  217.            
  218.             curl --silent --location "${l}" --output "./${album_path}/${img_name}"
  219.          done < $f
  220.       done
  221.    )
  222. }
  223.  
  224.  
  225. function parse_wall() {
  226.    wall_html=$(curl -s -b ${cookie_path} -c ${cookie_path} -A 'Mozilla/5.0' --location "http://m.facebook.com/${wall_url}")
  227.    echo -n "${wall_html}" > "${output_path}/m.wall_[${fb_id}].htm"
  228. }
  229.  
  230.  
  231.  
  232. #LOGIN
  233. function login_user() {
  234.    printf "Logging In...\n"
  235.    
  236.    params="email=${email}&pass=${pass}&"`parse_form "${form_fields}"`
  237.    
  238.    login_html=$(curl -s -b ${cookie_path} -c ${cookie_path} -A "Mozilla/5.0" -d "${params}" --location "${form_action}")
  239.    echo -n "${login_html}" > "${output_path}/m.login.htm"
  240.    
  241.    home_html=$(curl -s -b ${cookie_path} -c ${cookie_path} -A "Mozilla/5.0" --location "${host_url}/profile.php")
  242.    echo -n "${home_html}" > "${output_path}/m.home.htm"
  243.    
  244.    isDiff=$(echo "${login_html}" | grep "Log In")
  245.    
  246.    if [ -z "$isDiff" ]; then
  247.       isLoggedIn=true
  248.      
  249.    else
  250.       isLoggedIn=false;
  251.       echo "Can't login!"; fi  
  252. }
  253.  
  254.  
  255. #LOGOUT
  256. function logout_user() {
  257.    printf "Logging Out...\n"
  258.    
  259.    logout_url=$(echo "${home_html}" | tr '"' "\n" | grep "/logout.php?")
  260.    logout_html=$(curl -s -b ${cookie_path} -c ${cookie_path} -A "Mozilla/5.0" --location "${host_url}${logout_url}")
  261.    echo -n "${logout_html}" > "${output_path}/m.logout.htm"
  262.    
  263.    isLoggedIn=false
  264.    rm $cookie_path
  265. }
  266.  
  267.  
  268.  
  269.  
  270.  
  271. login_user
  272.  
  273. if $isLoggedIn; then
  274.    
  275.    parse_info "${fb_id}"
  276.    parse_wall
  277.    parse_friends
  278.    parse_photos
  279.    #download_photos
  280.    logout_user
  281. fi
  282.  
  283. exit 1;
Advertisement
Add Comment
Please, Sign In to add comment