Added zip content filter

- images that exist in the zip-file won't be downloaded
master
Julius 5 years ago
parent 22624bc625
commit 44b953bc3a

@ -1,4 +1,3 @@
yaml
PyYaml
praw
optparse
zipfile

@ -142,6 +142,22 @@ def download_images(images: list, dl_dir: str):
(realcount, imgcount, dl_dir, preexist))
def filter_zip_files(images: list, zip_fname: str):
"""
Removes the images that already exist in the zip-file
:param images:
:param zip_fname:
:return:
"""
if os.path.isfile(zip_fname):
zfile = zipfile.ZipFile(zip_fname, 'r')
zfnames = [f.filename for f in zfile.infolist()]
print('[~] Removing entries already in zip-file')
return [img for img in images if img.split('/')[-1] not in zfnames]
else:
return images
def compress_folder(folder: str, zip_fname: str):
"""
Zips the contents of a folder to the destination zipfile name.
@ -187,6 +203,7 @@ def main():
dldest = options.output # uses the -o output destination instead of a folder with the subreddit name
images = get_images(client, subreddit, limit=options.count, nsfw=options.nsfw)
if options.zip: # downloads to a cache-folder first before compressing it to zip
images = filter_zip_files(images, dldest+'.zip')
download_images(images, '.cache')
compress_folder('.cache', dldest+'.zip')
shutil.rmtree('.cache')

Binary file not shown.
Loading…
Cancel
Save