From 7f8dfa1d30583dd1d8c40c6cd1c079d2a722c9df Mon Sep 17 00:00:00 2001 From: ryuslash Date: Fri, 19 Mar 2010 00:18:04 +0100 Subject: 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. --- 4grab.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to '4grab.py') diff --git a/4grab.py b/4grab.py index 2cb8a3f..4dfca95 100755 --- a/4grab.py +++ b/4grab.py @@ -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: -- cgit v1.2.3-54-g00ecf