[GET] BotRocket’s Imgur Album downloader

Download:
http://www.mediafire.com/file/gu2mglw8n3jmc54/Imgur Album Downloader.rar
vt:
http://www.virustotal.com/#/file/d…2ad84627a788f427b43b3279d5c7ef1c1fc/detection

This Imgur downloader scrapes current viral albums.

Just put keywords in “keywords.txt” one per line and client-id in “clientid.txt” and bot will download those images in respective keywords folder

Just coded in 15 min. in awesome F# language.

Always Happy to Help People !

Thanks for the opportunity.

Source Code:

Code:
let userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36"       

type ImgurAlbumDownloader (clientId:string) =
  let clientid = clientId
  let DownloadImage (url:string) (file:string) =
    async{try
             let! req = Http.AsyncRequest(url, headers=["User-Agent",userAgent;"Accept","text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8";"Accept-Encoding","gzip, deflate"], customizeHttpRequest = (fun req->req.AutomaticDecompression<-DecompressionMethods.GZip|||DecompressionMethods.Deflate; req.Timeout<-20000; req))
             match req.Body with |Binary bytes -> File.WriteAllBytes(file, bytes)|_->()
             printfn "Downloaded: %s" file
          with
           |_ -> printfn "Couldn't download: %A" url}
  member public __.DownloadGalleries(keyword:string) =
    try
      ConsoleMessage (sprintf "Scraping Albums for keyword: %s" keyword) (ConsoleColor.Red)
      let json= Http.RequestString("http://api.imgur.com/3/gallery/search/viral/all/0",query=["perPage","100";"q",WebUtility.UrlEncode keyword],headers=[HttpRequestHeaders.Authorization ("Client-ID "+  clientid)])   
      let root = Gallery.Parse(json)
      match root.Success with
                      |false-> ConsoleMessage ("No gallery found for this keyword: " + keyword) ConsoleColor.Yellow|> ignore; [||]
                      |true-> root.Data
                               |>Array.map (fun d-> keyword, d.Id, d.Images)
                               |>Array.fold (fun acc ele -> acc |> Array.append [|ele|]) [||]
      |>Array.iter (fun (k, id, imagArr)->
                         let dir = Path.Combine(Environment.CurrentDirectory,"Downloads",k)
                         Directory.CreateDirectory(dir)|>ignore
                         ConsoleMessage (sprintf "Scraping Images for albumId: %s" id) (ConsoleColor.Yellow)
                         imagArr
                         |>Array.map (fun img -> DownloadImage img.Link (Path.Combine(dir,Path.GetFileName(img.Link))))
                         |>Async.Parallel
                         |>Async.RunSynchronously|>ignore)
    with
     |_-> ConsoleMessage ("No gallery found for this keyword: " + keyword) ConsoleColor.Cyan |>ignore
 

Leave a Reply