Exemple #1
0
def main():
    we_get = WG()
    we_get.parse_arguments()
    try:
        we_get.start()
    except (EOFError, KeyboardInterrupt):
        msg_error("[KeyboardInterrupt]", True)
Exemple #2
0
    def http_get_request(self, url):
        """ http_request: create HTTP request.
	        @return: data.
        """
        opener = urllib.request.build_opener()
        opener.addheaders = [('User-Agent', USER_AGENT), ("Accept", "*/*")]
        try:
            return opener.open(url).read().decode()
        except urllib.error.URLError:
            msg_error("connection failed (%s)" % (url), True)
Exemple #3
0
    def run(self, api_mode=False):
        items = dict()

        if self.targets[0] == "all":
            self.targets.pop()
            self.targets = list_wg_modules()

        for target in self.targets:
            if not self.results_type and not api_mode:
                msg_fetching(target)
            path = "we_get.modules.%s" % (target)
            try:
                run = import_module(path)
            except ImportError:
                msg_error("Cannot find target \'%s\'." % (target), True)
            except Exception:
                msg_info("Module: \'%s.py\' stopped!" % (target))
                msg_err_trace(True)
            try:
                items = run.main(self.pargs)
            except HTTPError:
                continue
            items = self.add_items_label(target, items)
            if items:
                self.items.update(items)
            else:
                msg_error(" \'%s\' - no results" % (target), False)
                continue
        """Sort self.items"""
        if self.filter:
            self.items = self.filter_items(self.filter)
        if self.sort_type == "name":
            self.items = self.sort_items_by_name(self.items)
        else:
            self.items = self.sort_items_by_seeds(self.items)
        # items cut must at the end of item processing.
        if self.results:
            self.items = self.cut_items(self.items, self.results)

        if api_mode:
            return self.items
        elif self.results_type == 'J':
            print(dumps(self.items, indent=2, sort_keys=True))
        elif self.results_type == 'L':
            [print(self.items[item]['link']) for item in self.items]
        else:
            # XXX: import we_get.core.shell is here for optimization.
            # we-get will load 50% faster!
            from we_get.core.shell import Shell
            self.shell = Shell()
            if hasattr(self, 'config') and self.config['item_color']:
                self.shell.item_color.update(self.config['item_color'])
            self.shell.shell(self.items, self.pargs)
Exemple #4
0
 def prompt_parse_command(self, command, args):
     if command == "show":
         self.prompt_command_show(args)
     elif command in ('list', 'l'):
         self.prompt_show_items()
     elif command in ('help', 'h', '?'):
         self.prompt_usage()
     elif command in ('exit', 'q', 'quit'):
         return False
     else:
         if not command.split()[0] in COMMANDS:
             msg_error("No such command.", False)
     return True
Exemple #5
0
    def run(self):
        items = dict()

        if self.targets[0] == "all":
            msg_warning("using 'all' is not recommended!")
            self.targets.pop()
            self.targets = list_wg_modules()

        for target in self.targets:
            if not self.results_type:
                msg_fetching(target)
            path = "we_get.modules.%s" % (target)
            try:
                run = import_module(path)
            except ImportError:
                msg_error("Cannot find target \'%s\'." % (target), True)
            except Exception:
                msg_info("Module: \'%s.py\' stopped!" % (target))
                msg_err_trace(True)
            items = run.main(self.pargs)
            items = self.add_items_label(target, items)
            if items:
                self.items.update(items)
            else:
                msg_error(" \'%s\' - no results" % (target), False)

        if not self.items:
            return
        if self.filter:
            self.items = self.filter_items(self.filter)
        if self.results:
            self.items = self.cut_items(self.items, self.results)
        if self.sort_type == "name":
            self.items = self.sort_items_by_name(self.items)
        else:
            self.items = self.sort_items_by_seeds(self.items)

        if self.results_type == 'J':
            print(dumps(self.items, indent=2, sort_keys=True))
        elif self.results_type == 'L':
            [print(self.items[item]['link']) for item in self.items]
        else:
            # XXX: import we_get.core.shell is here for optimization.
            # we-get will load 50% faster!
            from we_get.core.shell import Shell
            self.shell = Shell()
            self.shell.shell(self.items, self.pargs)
Exemple #6
0
    def prompt_command_show(self, args):
        _ = args.split()
        torrent = _[0]
        _.pop(0)
        if _:
            args = _[0]
        else:
            args = None
        """In this method we can use regex in the torrent name.
           for example only show torrents with 'S0\\d' string.
           more exmaples:
            show .Cool --link # Show all torrents with .Cool
            show Cool.Torrent\\d --target
        """
        if torrent in self.items.keys():
            items_idx = [torrent]
        else:
            try:
                items_idx = [
                    item for item in self.items.keys()
                    if re.search(torrent, item)
                ]
            except Exception as e:
                log.error('{}: {}'.format(type(e), e))
                msg_error("Invalid regular expression or torrent name.", False)
                return

        for x in items_idx:
            if args == '--link':
                print(self.items[x]['link'])
            elif args == "--target":
                print("%s src(%s)" % (color(
                    "cyan", x), color("yellow", self.items[x]['target'])))
            elif args == "--seeds":
                print(
                    "%s se(%s)" %
                    (color("cyan", x), color("green", self.items[x]['seeds'])))
            elif args == "--leeches":
                print(
                    "%s le(%s)" %
                    (color("cyan", x), color("red", self.items[x]['leeches'])))
            else:
                print("%s %s" %
                      (x, dumps(self.items[x], indent=2, sort_keys=True)))
Exemple #7
0
 def python(self):
     """Python version test.
        we are not using Python 2 due the end of support in 2020.
     """
     if sys.version_info.major != 3:
         msg_error("please use Python 3 to run we-get.", True)