diff --git a/scripts/galleroob b/scripts/galleroob new file mode 100644 index 0000000000000000000000000000000000000000..956853620bd48c66a3474b9b16f698eefb2b00d1 --- /dev/null +++ b/scripts/galleroob @@ -0,0 +1,25 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Copyright(C) 2010-2011 Noé Rubinstein +# +# This file is part of weboob. +# +# weboob is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# weboob is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with weboob. If not, see . + +from weboob.applications.galleroob import Galleroob + + +if __name__ == '__main__': + Galleroob.run() diff --git a/weboob/applications/galleroob/__init__.py b/weboob/applications/galleroob/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..47246df1289cf87a675b991e8aadaf4394d7b39a --- /dev/null +++ b/weboob/applications/galleroob/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- + +# Copyright(C) 2010-2011 Noé Rubinstein +# +# This file is part of weboob. +# +# weboob is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# weboob is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with weboob. If not, see . + +from .galleroob import Galleroob + +__all__ = ['Galleroob'] diff --git a/weboob/applications/galleroob/galleroob.py b/weboob/applications/galleroob/galleroob.py new file mode 100644 index 0000000000000000000000000000000000000000..52c120485a68efe59a7fe5b034e98690a9034501 --- /dev/null +++ b/weboob/applications/galleroob/galleroob.py @@ -0,0 +1,78 @@ +# -*- coding: utf-8 -*- + +# Copyright(C) 2010-2011 Noé Rubinstein +# +# This file is part of weboob. +# +# weboob is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# weboob is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with weboob. If not, see . + +import subprocess +import sys +import os +from weboob.tools.application.repl import ReplApplication +from weboob.capabilities.gallery import ICapGallery +from re import search + +__all__ = ['Galleroob'] + +class Galleroob(ReplApplication): + APPNAME = 'galleroob' + VERSION = '0.0' + COPYTIGHT = 'Copyright(C) 2011 Noé Rubinstein' + DESCRIPTION = 'galleroob browses and downloads web image galleries' + CAPS = ICapGallery + + def __init__(self, *args, **kwargs): + ReplApplication.__init__(self, *args, **kwargs) + + def do_download(self, line): + """ + download ID FOLDER + + Download a gallery + """ + _id, dest = self.parse_command_args(line, 2, 2) + gallery = None + for backend, result in self.do('get_gallery', _id): + if result: + backend = backend + gallery = result + + if not gallery: + print 'Gallery not found: %s' % _id + return 1 + + with open('/dev/null', 'w') as devnull: + process = subprocess.Popen(['which', 'wget'], stdout=devnull) + if process.wait() != 0: + print >>sys.stderr, 'Please install "wget"' + return 1 + + os.system('mkdir "%s"' % dest) + + i = 0 + for img in backend.iter_gallery_images(gallery): + backend.fillobj(img, ('url',)) + + ext = search(r"\.([^\.]{1,5})$", img.url) + if ext: + ext = ext.group(1) + else: + ext = "jpg" + + i += 1 + + os.system('wget "%s" -O "%s/%03d.%s"' % (img.url, dest, i, ext)) + +