Welcome folks today in this post we will be downloading imgur images
using imgur api in python using imgur-downloader
library. All the full source code of the application is shown below.
Get Started
In order to get started you need to install the following library using pip
command as shown below
pip install imgur-downloader
After installing this library make an app.py
file and copy paste the following code
app.py
1 2 3 |
ImgurDownloader( 'http://i.imgur.com/removed.png', delete_dne=True, debug=True ).save_images() |
- Downloads imgur links with .gifv extension as a mp4 file
1 2 |
ImgurDownloader(<span class="hljs-string">'http://i.imgur.com/A61SaA1.gifv'</span>).save_images() |
- save_images & direct_download methods now return tuple of two integers. The first integer represent successful downloads and the second represent skipped download (either failed or Imgur DNE detected). For example the value on the the last line of the output is what’s returned from save_images method:
1 2 3 4 5 6 7 |
<span class="hljs-comment"># Code ran (url is an imgur Album with 5 images):</span> print( imguralbum.ImgurDownloader( url, dir1, file_name=rand_name, debug=<span class="hljs-literal">False</span> ).save_images() ) <span class="hljs-comment"># output: (5, 0)</span> |
Init function parameter changes
- Second optional parameter, dir_download=os.getcwd(), which allows for specific directory to download to (not adapted for cli), e.g.:
1 2 |
ImgurDownloader(<span class="hljs-string">'http://imgur.com/SnkkAVU'</span>, <span class="hljs-string">'/home/user/Downloads/'</span>) |
- Third optional parameter, file_name=”, which allows user to specify name of file if input is single image or folder if input is album. Note this takes priority over the imgur key and the album webpage title e.g.:
1 2 |
ImgurDownloader( <span class="hljs-string">'http://imgur.com/SnkkAVU'</span>, <span class="hljs-string">'/home/user/Downloads/'</span>, <span class="hljs-string">'my-img'</span>) |
Command Line Usage
1 2 |
$ imgur_downloader [album URL] [folder to save to] |
Download all images from an album into the folder /Users/alex/images/downloaded
1 2 |
$ imgur_downloader http://imgur.com/a/uOOju /Users/alex/images/downloaded |
Downloads all images and puts them into an album in the current directory called “uOOju”
1 |
$ imgur_downloader http://imgur.com/a/uOOju |