def unignore(alias, chapters): """Unignore chapters for a series. Enter one or more chapters after the alias to mark them as new. Enter the chapter identifiers as they are listed when using the chapters command. To unignore all of the chapters for a particular series, use the word "all" in place of the chapters. """ s = db.Series.alias_lookup(alias) query = db.session.query(db.Chapter).filter(db.Chapter.series == s, db.Chapter.downloaded == -1) if len(chapters) == 1 and chapters[0].lower() == 'all': click.echo('Unignoring {} chapters for {}'.format(len(s.chapters), s.name)) click.confirm('Do you want to continue', prompt_suffix='? ', abort=True) else: query = query.filter(db.Chapter.chapter.in_(chapters)) chapters = [x.to_object() for x in query.all()] for chapter in chapters: chapter.mark_new() if len(chapters) == 1: output.chapter('Unignored chapter {} for {}'.format( chapters[0].chapter, s.name )) else: output.series('Unignored {} chapters for {}'.format( len(chapters), s.name ))
def edit(alias, setting, value): """Modify settings for a follow. The following settings can be edited: alias, directory. """ series = db.Series.alias_lookup(alias, unfollowed=True) alias = series.alias if value.lower() == 'none' or value.lower() == '-': value = None if setting == 'alias': series.alias = value elif setting == 'directory': series.directory = value else: setting = click.style(setting, bold=True) output.error('Invalid setting {}'.format(setting)) exit(1) if not value: value = click.style('none', dim=True) else: value = click.style(value, bold=True) try: db.session.commit() except exceptions.DatabaseIntegrityError: db.session.rollback() output.error('Illegal value {}'.format(value)) exit(1) else: output.chapter('Changed {} for {} to {}'.format(setting, alias, value))
def follow(urls, directory, download, ignore): """Follow a series.""" chapters = [] for url in urls: try: series = utility.series_by_url(url) except exceptions.ScrapingError: output.warning('Scraping error ({})'.format(url)) continue except exceptions.LoginError as e: output.warning('{} ({})'.format(e.message, url)) continue if not series: output.warning('Invalid URL "{}"'.format(url)) continue series.directory = directory if ignore: series.follow(ignore=True) output.chapter('Ignoring {} chapters'.format(len(series.chapters))) else: series.follow() chapters += db.Chapter.find_new(alias=series.alias) if download: output.chapter('Downloading {} chapters'.format(len(chapters))) for chapter in chapters: try: chapter.get() except exceptions.LoginError as e: output.warning( 'Could not download {c.alias} {c.chapter}: {e}'.format( c=chapter, e=e.message))
def follow(urls, directory, download, ignore): """Follow a series.""" chapters = [] for url in urls: try: series = series_by_url(url) except exceptions.ScrapingError: output.warning('Scraping error ({})'.format(url)) continue except exceptions.LoginError as e: output.warning('{} ({})'.format(e.message, url)) continue if not series: output.warning('Invalid URL "{}"'.format(url)) continue series.directory = directory if ignore: series.follow(ignore=True) output.chapter('Ignoring {} chapters'.format(len(series.chapters))) else: series.follow() chapters += db.Chapter.find_new(alias=series.alias) if download: output.chapter('Downloading {} chapters'.format(len(chapters))) for chapter in chapters: try: chapter.get() except exceptions.LoginError as e: output.warning('Could not download {c.alias} {c.chapter}: {e}' .format(c=chapter, e=e.message)) continue
def alias(alias, new_alias): """Assign a new alias to series.""" s = db.Series.alias_lookup(alias) s.alias = new_alias try: db.session.commit() except: db.session.rollback() else: output.chapter('Changing alias "{}" to "{}"'.format(alias, new_alias))
def download(aliases): """Download all available chapters. If an optional alias is specified, the command will only download new chapters for that alias. """ chapters = [] if not aliases: chapters = db.Chapter.find_new() for alias in aliases: chapters += db.Chapter.find_new(alias=alias) output.chapter('Downloading {} chapters'.format(len(chapters))) for chapter in chapters: chapter.get()
def download(aliases): """Download all available chapters. If an optional alias is specified, the command will only download new chapters for that alias. """ chapters = [] if not aliases: chapters = db.Chapter.find_new() for alias in aliases: chapters += db.Chapter.find_new(alias=alias) output.chapter('Downloading {} chapters'.format(len(chapters))) for chapter in chapters: try: chapter.get() except exceptions.LoginError as e: output.warning('Could not download {c.alias} {c.chapter}: {e}' .format(c=chapter, e=e.message))
def download(aliases): """Download all available chapters. If an optional alias is specified, the command will only download new chapters for that alias. """ chapters = [] if not aliases: chapters = db.Chapter.find_new() for alias in aliases: chapters += db.Chapter.find_new(alias=alias) output.chapter('Downloading {} chapters'.format(len(chapters))) for chapter in chapters: try: chapter.get() except exceptions.LoginError as e: output.warning( 'Could not download {c.alias} {c.chapter}: {e}'.format( c=chapter, e=e.message))
def set_ignored(mark_ignored, alias, chapters): """Helper function for `cum ignore` and `cum unignore` commands, which will either ignore chapters if mark_ignored is True or unignore chapters if mark_ignored is False. """ if mark_ignored: downloaded = 0 message_start = 'I' method = 'ignore' else: downloaded = -1 message_start = 'Uni' method = 'mark_new' s = db.Series.alias_lookup(alias) query = (db.session.query(db.Chapter) .filter(db.Chapter.series == s, db.Chapter.downloaded == downloaded)) if len(chapters) == 1 and chapters[0].lower() == 'all': click.echo('{}gnoring {} chapters for {}' .format(message_start, len(s.chapters), s.name)) click.confirm('Do you want to continue', prompt_suffix='? ', abort=True) else: query = query.filter(db.Chapter.chapter.in_(chapters)) chapters = [x.to_object() for x in query.all()] for chapter in chapters: function = getattr(chapter, method) function() if len(chapters) == 1: output.chapter('{}gnored chapter {} for {}' .format(message_start, chapters[0].chapter, s.name)) else: output.series('{}gnored {} chapters for {}' .format(message_start, len(chapters), s.name))