diff options
author | ryuslash | 2010-03-19 00:18:04 +0100 |
---|---|---|
committer | ryuslash | 2010-03-19 00:18:04 +0100 |
commit | 7f8dfa1d30583dd1d8c40c6cd1c079d2a722c9df (patch) | |
tree | 12564b5ac501f2a35b660d7f5bd7461581f3f6ae /4grab.py | |
parent | 4a9cc7e2b608332f3d41aa47f5f1a893a5eab529 (diff) | |
download | 4grab-7f8dfa1d30583dd1d8c40c6cd1c079d2a722c9df.tar.gz 4grab-7f8dfa1d30583dd1d8c40c6cd1c079d2a722c9df.zip |
Sorting, multi category, multi resolution
After a file has been downloaded a callback function can now be called.
The callback function I call checks to see if the resolution of the image appears in the collection of resolutions that has been entered in the configuration file and deletes/moves accordingly.
If a file can not be read (which I have noticed happens sometimes), it is removed, not copied and not archived so that it can be retried later.
4grab got a new command-line option, -s --sorter, to sort out old images, running python sorter.py has the same effect, but this seemed pretties.
theoretically multiple categories could now be entered into the configuration file seperated by ',', but this hasn't been tested yet.
mutliple resolutions could be entered into the configuration file, seperated by ',' like so: 1680x1050,1920x1200.
Configuration now checks to see if all the necessary properties are available in the configuration file, if one is missing, it tries to create it.
Diffstat (limited to '4grab.py')
-rwxr-xr-x | 4grab.py | 23 |
1 files changed, 21 insertions, 2 deletions
@@ -21,11 +21,13 @@ import optparse import sys +import os import config import download import progressbar +import sorter def raw_input_with_default(default, prompt): inp = raw_input("%s (default=%s): " % (prompt, default)) @@ -106,20 +108,34 @@ under certain conditions.""") dest="wizard", help="I'll put on my robe and wizard hat and help you " "get some of those pictures you like") + parser.add_option("-s", + "--sort", + action="store_true", + dest="sort", + help="Sort downloaded images, most handy if you've used " + "older versions which didn't sort yet") (options, args) = parser.parse_args() if options.confval and (options.tempcat or options.thread - or options.wizard): + or options.wizard + or options.sort): print "Can't configure something and do something else too." exit(1) if options.wizard and (options.tempcat or options.thread - or options.confval): + or options.confval + or options.sort): print "Can't take a walk with the wizard and do something else too." exit(1) + if options.sort: + sort = sorter.Sorter() + for item in os.listdir(conf.get_download_location()): + sort.act(item) + exit(0) + if options.confval: if not conf.option_exists(options.confval[0]): print ("%s: error: %s is not a valid configuration option" @@ -167,7 +183,10 @@ under certain conditions.""") if __name__ == "__main__": conf = config.Configuration() + sort = sorter.Sorter() parse_commands() + + downloader.set_on_downloaded(sort.act) for category in conf.get_categories(): base_url = "%s%s/" % (base_url, category) try: |