Added tox to project
This commit is contained in:
parent
d91a77e115
commit
ef0efe3bb9
|
@ -7,13 +7,13 @@
|
|||
# Distributed under terms of the MIT license.
|
||||
|
||||
"""
|
||||
|
||||
IMGUR Gallery downloader.
|
||||
"""
|
||||
|
||||
import os
|
||||
import requests
|
||||
import argparse
|
||||
from urllib.parse import urlparse
|
||||
import argparse
|
||||
import requests
|
||||
from progressbar import (Bar, ETA, FileTransferSpeed, Percentage, ProgressBar)
|
||||
|
||||
|
||||
|
@ -21,34 +21,36 @@ AJAX_BASEURL = 'https://imgur.com/ajaxalbums/getimages/'
|
|||
IMAGE_BASEURL = 'https://i.imgur.com/'
|
||||
|
||||
|
||||
parser = argparse.ArgumentParser(description='Imgur Album Downloader')
|
||||
parser.add_argument('outdir', metavar='OUTPUT_DIR', type=str,
|
||||
PARSER = argparse.ArgumentParser(description='Imgur Album Downloader')
|
||||
PARSER.add_argument('outdir', metavar='OUTPUT_DIR', type=str,
|
||||
help='Download the album into OUTPUT_DIR')
|
||||
parser.add_argument('album', metavar='ALBUM_HASH', type=str,
|
||||
PARSER.add_argument('album', metavar='ALBUM_HASH', type=str,
|
||||
help='The album hash identifier to download')
|
||||
args = parser.parse_args()
|
||||
ARGS = PARSER.parse_args()
|
||||
|
||||
|
||||
def download_image(filename, out_directory):
|
||||
"""Download an image and save it locally."""
|
||||
if not os.path.exists(out_directory):
|
||||
os.makedirs(out_directory)
|
||||
|
||||
filepath = os.path.join(out_directory, filename)
|
||||
req = requests.get(IMAGE_BASEURL + filename, stream=True)
|
||||
with open(filepath, 'wb') as fd:
|
||||
with open(filepath, 'wb') as imgfd:
|
||||
widgets = ['Download: {} '.format(filename), Percentage(), ' ',
|
||||
Bar(), ' ', ETA(), ' ', FileTransferSpeed()]
|
||||
content_length = int(req.headers['content-length'])
|
||||
pbar = ProgressBar(widgets=widgets, maxval=content_length).start()
|
||||
filesize = 0
|
||||
for chunk in req.iter_content(chunk_size=8192):
|
||||
fd.write(chunk)
|
||||
imgfd.write(chunk)
|
||||
filesize += len(chunk)
|
||||
pbar.update(filesize)
|
||||
pbar.finish()
|
||||
|
||||
|
||||
def get_ajaxalbum(album_id, out_directory):
|
||||
"""Download the `hit.json` file of an album and process all images."""
|
||||
req = requests.get(AJAX_BASEURL + album_id + '/hit.json')
|
||||
jsonalbum = req.json()
|
||||
# num_images = jsonalbum['data']['count']
|
||||
|
@ -58,9 +60,6 @@ def get_ajaxalbum(album_id, out_directory):
|
|||
|
||||
|
||||
if __name__ == '__main__':
|
||||
parsed_url = urlparse(args.album)
|
||||
album = os.path.split(parsed_url.path)[-1]
|
||||
get_ajaxalbum(album, args.outdir)
|
||||
# album_id = 'ThiBLHO'
|
||||
# out_directory = 'album'
|
||||
# get_ajaxalbum(album_id, out_directory)
|
||||
PARSED_URL = urlparse(ARGS.album)
|
||||
ALBUM = os.path.split(PARSED_URL.path)[-1]
|
||||
get_ajaxalbum(ALBUM, ARGS.outdir)
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
flake8
|
||||
pylint
|
||||
progressbar2==3.37.1
|
||||
requests==2.18.4
|
|
@ -0,0 +1,21 @@
|
|||
#! /usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# vim:fenc=utf-8
|
||||
#
|
||||
# Copyright © 2018 jpk <jpk+dev@goatpr0n.de>
|
||||
#
|
||||
# Distributed under terms of the MIT license.
|
||||
|
||||
"""
|
||||
|
||||
"""
|
||||
|
||||
from setuptools import setup, find_packages
|
||||
|
||||
|
||||
setup(
|
||||
name='Imgurdl',
|
||||
version='1.0',
|
||||
packages=find_packages(),
|
||||
scripts=['imgurdl.py'],
|
||||
)
|
Loading…
Reference in New Issue