Ejemplo n.º 1
0
def updateshow_handler(args):
    config = gconfig.get()
    show_match = _match_show_name(config, args.printer, args.name)
    if not show_match:
        return

    name, [ep, reso, subdir] = show_match

    if args.episode is not None and args.episode != ep:
        ep = args.episode
        args.printer.info("Updated {} episode count to {}.".format(name, ep))

    if args.resolution is not None and args.resolution != reso:
        reso = int(args.resolution.strip('p'))
        args.printer.info("Updated {} resolution to {}.".format(name, reso))

    if args.directory is not None and args.directory != subdir:
        if args.directory == '/':
            subdir = ''
            args.printer.info(
                "Updated {} subdir to main directory.".format(name))
        else:
            subdir = args.directory
            args.printer.info("Updated {} subdir to {}.".format(name, subdir))

    config['shows'][name] = [ep, reso, subdir]
    config.persist()
Ejemplo n.º 2
0
    def _refresh_thread(self, packlist: Packlist):
        config = gconfig.get()
        logger = logging.getLogger('refresh_timer')
        logger.info("Starting packlist check for %s", packlist.name)
        with self.refresh_lock:
            for item in packlist:
                if item.show_name in config['shows']:
                    [episode_nr, resolution,
                     _subdir] = config['shows'][item.show_name]
                    if item.is_new(
                            episode_nr, resolution
                    ) and item.filename not in self.queued_downloads:
                        packlist.download_manager.queue_download(
                            packlist.current, item)
                        self.queued_downloads[item.filename] = packlist
                        logger.info("Queueing download of %s - %02d",
                                    item.show_name, item.episode_nr)
                        config.printer.prog(
                            "Queueing download of {} - {:02d}.".format(
                                item.show_name, item.episode_nr))

            packlist.download_manager.start()
            config.printer.flush()

        logger.info("Ending packlist check for %s", packlist.name)

        return True
Ejemplo n.º 3
0
 def register_packlists(self):
     config = gconfig.get()
     for key in config['packlists']:
         packlist = create_packlist(key, config['packlists'][key])
         self.register_timers(packlist)
         self.packlists[key] = packlist
     return self.packlists
Ejemplo n.º 4
0
def listarchivedshows_handler(args):
    config = gconfig.get()
    items = sorted(config['archived'].items())

    if len(items) == 0:
        args.printer.x("No shows archived")
        return

    args.printer.x("Listing {} archived shows:".format(len(items)))
    return _list_shows(args.printer, items)
Ejemplo n.º 5
0
def remotecontrol_unlink_handler(args):
    config = gconfig.get()
    del config['credentials']['telegram']

    if config.telegram_bot:
        config.telegram_bot.terminate()
        config.telegram_bot = None
    config.persist()
    args.printer.info('Telegram link has been removed')
    config.printer.remove_listener_by_class(TelegramBotPrinter)
Ejemplo n.º 6
0
def addbot_handler(args):
    config = gconfig.get()
    bots = set(config['trusted'])

    bots.add(args.name)

    config['trusted'] = list(bots)
    config.persist()

    args.printer.x("Added {} to trusted list".format(args.name))
Ejemplo n.º 7
0
def removebot_handler(args):
    config = gconfig.get()
    bots = set(config['trusted'])

    if args.name not in bots:
        args.printer.error("No such bot in trusted list: " + args.name)
        return

    bots.remove(args.name)
    config['trusted'] = list(bots)
    config.persist()

    args.printer.x("Removed {} from trusted list".format(args.name))
Ejemplo n.º 8
0
def listbots_handler(args):
    config = gconfig.get()
    items = sorted(
        config['archived']
    )  # I think here archived i meant, since 'trusted' doesn'T exist on global config object
    if len(items) == 0:
        args.printer.x("No bots archived")
        return

    args.printer.x("Listing {} bots:".format(len(items)))

    for bot in items:
        args.printer.list(bot)
Ejemplo n.º 9
0
def archiveshow_handler(args):
    config = gconfig.get()
    show_match = _match_show_name(config, args.printer, args.name)
    if not show_match:
        return

    name, [ep, reso, subdir] = show_match

    del config['shows'][name]
    config['archived'][name] = [ep, reso, subdir]
    config.persist()

    args.printer.x("Added {} at episode {} to archive.".format(name, ep))
Ejemplo n.º 10
0
def restoreshow_handler(args):
    config = gconfig.get()
    show_match = _match_show_name(config, args.printer, args.name, 'archived')
    if not show_match:
        args.printer.error("No show in archive named: " + args.name)
        return

    name, [ep, reso, subdir] = show_match

    del config['archived'][name]
    config['shows'][name] = [ep, reso, subdir]
    config.persist()

    args.printer.x("Restored {} at episode {} from archive.".format(name, ep))
Ejemplo n.º 11
0
def removeshow_handler(args):
    config = gconfig.get()
    show_match = _match_show_name(config, args.printer, args.name)
    if not show_match:
        return

    name, [ep, _reso, _subdir] = show_match

    del config['shows'][name]
    config.persist()

    if ep is not None:
        args.printer.x("Removed {} at episode {} from list.".format(name, ep))
    else:
        args.printer.x("Removed {} from list.".format(name))
Ejemplo n.º 12
0
def remotecontrol_link_handler(args):
    config = gconfig.get()
    if not args.token:
        args.printer.info(
            'To link with Telegram, you need to make a bot first. Talk to @BotFather https://t.me/botfather .'
        )
        args.printer.info(
            'After getting the API token, add it to the "link" command')
    else:
        telegram_bot = TelegramBot.init_from_config(config)
        bot_printer = TelegramBotPrinter(telegram_bot)
        telegram_bot.set_parser(create_argument_parser(bot_printer, prog=''))
        config.printer.add_listener(bot_printer)
        config.telegram_bot = telegram_bot
        bot_info = telegram_bot.get_me()
        args.printer.info(
            'To link your bot with AXDCC, send message "/start" to {0} or use this URL https://t.me/{0}'
            .format(bot_info['username']))
Ejemplo n.º 13
0
def packlist_timer_handler(args):
    config = gconfig.get()
    if args.type == 'refresh':
        packlist = config.packlist_manager.packlists[args.packlist]
        packlist.refresh_timer.unregister()
        if args.off:
            args.printer.x("Refresh timer disabled for {}.".format(packlist))
        else:
            if args.interval:
                packlist.refresh_interval = args.interval
                config['packlists'][
                    packlist.name]['refreshInterval'] = args.interval
                config.persist()

            packlist.register_refresh_timer(
                config.packlist_manager.refresh_timer_callback)
            args.printer.x(
                "Refresh timer enabled for packlist {} with interval {}s.".
                format(packlist, packlist.refresh_interval))
Ejemplo n.º 14
0
def addshow_handler(args):
    config = gconfig.get()
    resolution = int(
        args.resolution.strip('p')) if args.resolution is not None else 1080
    data = [args.episode, resolution, args.directory]

    config['shows'][args.name] = data
    config.persist()

    result = ''
    if args.episode is not None:
        result = "Added {} @ episode {} in {}p to list.".format(
            args.name, args.episode, resolution)
    else:
        result = "Added {} in {}p to list.".format(args.name, resolution)

    if args.directory:
        args.printer.x(result + " Default directory: " + args.directory)
    else:
        args.printer.x(result)
Ejemplo n.º 15
0
def create_argument_parser(printer, prog='/axdcc'):
    direct_printer = DirectPrinter(printer)
    parser = ArgumentParser(prog=prog, printer=direct_printer)
    parser.set_defaults(parser=parser, printer=direct_printer)

    subparsers = parser.add_subparsers()

    shows_subparser(subparsers.add_parser('show', printer=parser.printer))
    bots_subparser(subparsers.add_parser('bot', printer=parser.printer))
    packlist_subparser(
        subparsers.add_parser('packlist',
                              printer=parser.printer,
                              aliases=['pl']),
        gconfig.get().packlist_manager)
    remotecontrol_subparser(
        subparsers.add_parser('remotecontrol',
                              printer=parser.printer,
                              aliases=['rc']))

    return general_main(parser)
Ejemplo n.º 16
0
def run_packlist_handler(args):
    config = gconfig.get()
    packlist = config.packlist_manager.packlists[args.packlist]
    packlist.run_once()
    args.printer.x("Packlist '{}' check started".format(packlist))