def update_log(args): anime_name, episodes = read_args(args) episodes = utils.compress_range(episodes) utils.write_log(anime_name, episodes) utils.update_tracklist(anime_name, episodes) utils.write_cache(anime_name) utils.update_watchlater(anime_name, episodes)
def complete_local(self, text, line, *ignored): m = re.match(r'local +([0-9a-z-]+) +', line) if m: name = m.group(1) eps = utils.get_local_episodes(name)[name] return [utils.compress_range(utils.extract_range(eps))] return self.complete_listlocal(text, line, *ignored)
def episodes_update(updates): if len(updates) == 0: return if len(updates) == 1: anime_name = list(updates)[0] epl = len(updates[anime_name]) eps = utils.compress_range(updates[anime_name]) summary = f'{epl} New episode(s)' msg = f'{anime_name} has {epl} new episodes ({eps})' send_notification(summary, msg) else: summary = f'{len(updates)} anime updates' msg = '' for anime_name, ep in updates.items(): epl = len(updates[anime_name]) eps = utils.compress_range(updates[anime_name]) msg += f'{epl} new ({eps}) : {anime_name}\n' send_notification(summary, msg)
def continue_play(args): name, episodes = read_args(args) watched = utils.read_log().get(name) outputs.prompt_val('Watched', watched, 'success') if not watched: last = 0 else: last = int(watched.split('-')[-1]) play_anime( [name, utils.compress_range(filter(lambda e: e > last, episodes))])
def list_episodes(args): name = read_args(args, episodes=False) available_rng = gogoanime.get_episodes_range(gogoanime.get_anime_url(name)) if len(args) == 2: _, episodes = read_args(args) eps = set(episodes) avl_eps = set(utils.extract_range(available_rng)) res = eps.intersection(avl_eps) available_rng = utils.compress_range(res) outputs.prompt_val(f'Available episodes', available_rng) outputs.prompt_val(f'Watched episodes', utils.read_log(name), 'success') utils.write_cache(name)
def list_episodes(args): name, _ = read_args(args, episodes=False) available_rng = anime_source_module.get_episodes_range(anime_source_module.get_anime_url(name)) if len(args) == 2: _, episodes = read_args(args) eps = set(episodes) avl_eps = set(utils.extract_range(available_rng)) res = eps.intersection(avl_eps) available_rng = utils.compress_range(res) outputs.prompt_val("Available episodes", available_rng) log = utils.Log(utils.read_log(name)) outputs.prompt_val("Watched episodes", log.eps, "success", end=' ') outputs.normal_info(log.last_updated_fmt) utils.write_cache(name)
def get_episodes_range(anime_url): soup = utils.get_soup(anime_url) if not soup: return [] rngs_obj = soup.find_all('a', ep_end=True, ep_start=True) total_rng = [] for r in rngs_obj: rng = r.text rngs = rng.split('-') if rngs[0] == '0': rngs[0] = '1' total_rng.append('-'.join(rngs)) text = ','.join(total_rng) parsed_rng = utils.compress_range(utils.extract_range(text)) return parsed_rng
def track_anime(args): """Put an anime into the track list""" anime_name = read_args(args, episodes=False) watched_episodes = utils.read_log(anime_name) if watched_episodes is None: outputs.warning_info( 'Log entry not found. Setting only new episodes for tracking.') _, episodes = read_args(args) episodes = utils.compress_range(episodes) else: outputs.prompt_val(f'Watched', watched_episodes, 'success') episodes = watched_episodes utils.write_log(anime_name, episodes, append=False, logfile=config.ongoingfile)
def save_anime(args): """Put the anime into watch later list.""" anime_name, eps = read_args(args) watched = utils.read_log(anime_name) if watched: watched_eps = utils.extract_range(utils.Log(watched).eps) else: watched_eps = [] save_eps = set(eps).difference(set(watched_eps)) if not save_eps: outputs.warning_info('Already watched the provided episodes.') return utils.write_log(anime_name, utils.compress_range(save_eps), append=True, logfile=config.watchlaterfile)
def list_local_episodes(args): in_dict = utils.get_local_episodes(*args) out_dict = dict() for anime, eps in in_dict.items(): new_eps = utils.compress_range(utils.extract_range(eps)) if new_eps != "": out_dict[anime] = new_eps empties = set(in_dict).difference(set(out_dict)) if len(out_dict) == 0: outputs.warning_info("No local entries found.") else: outputs.bold_info("Episodes\tAnime Name") for k, v in out_dict.items(): outputs.normal_info(f"{v}\t\t{k}") if len(empties) > 0: outputs.warning_info("Directories without Episodes:") outputs.warning_info(", ".join(empties))
def track_anime(args): """Put an anime into the track list""" anime_name, episodes = read_args(args, episodes=False) log = utils.read_log(anime_name) if log is None: outputs.warning_info( "Log entry not found.") if not episodes: _, episodes = read_args(args) episodes = utils.compress_range(episodes) else: episodes = utils.Log(log).eps outputs.prompt_val("Watched", episodes, "success") utils.write_log(anime_name, episodes, append=False, logfile=config.ongoingfile)
def check_anime(args): name, episodes = read_args(args) unavail_eps = [] for e in episodes: url = anime_source_module.get_episode_url(name, e) outputs.normal_info("Testing:", url) durl, ext = anime_source_module.get_direct_video_url(url) if not durl: raise SystemExit("Url for the file not found") if not os.path.exists( os.path.join(config.anime_dir, f"./{name}/ep{e:02d}.{ext}")): unavail_eps.append(e) if len(unavail_eps) == 0: outputs.success_info( "All episodes in given range are locally available") else: outputs.prompt_val("Missing episodes", utils.compress_range(unavail_eps), "warning")
def get_updates(anime_name=''): """Check and display the updates on the tracked anime list.""" updates = anime_updates(anime_name) if len(updates) == 0: outputs.normal_info("No new episodes released.") return if anime_name == '': outputs.prompt_val(f'anime(s) has new episodes.', len(updates), 'success', sep=" ", reverse=True) outputs.normal_info('-' * 50) for anime, episodes in updates.items(): outputs.normal_info(anime, end='\n\t') outputs.success_tag(len(episodes), end=' ') outputs.prompt_val('new episodes', utils.compress_range(episodes), 'success')
def check_anime(args): name, episodes = read_args(args) unavail_eps = [] for e in episodes: url = gogoanime.get_episode_url(name, e) outputs.normal_info('Testing:', url) durl, ext = gogoanime.get_direct_video_url(url) if not durl: raise SystemExit('Url for the file not found') if not os.path.exists( os.path.join(config.anime_dir, f'./{name}/ep{e:02d}.{ext}')): unavail_eps.append(e) if len(unavail_eps) == 0: outputs.success_info( 'All episodes in given range are locally available') else: outputs.prompt_val('Missing episodes', utils.compress_range(unavail_eps), 'warning')
def get_updates(anime_name=""): """Check and display the updates on the tracked anime list.""" updates = anime_updates(anime_name) if len(updates) == 0: outputs.normal_info("No new episodes released.") return if anime_name == "": outputs.prompt_val( "anime(s) has new episodes.", len(updates), "success", sep=" ", reverse=True, ) outputs.normal_info("-" * 50) for anime, episodes in updates.items(): outputs.normal_info(anime, end="\n\t") outputs.success_tag(len(episodes), end=" ") outputs.prompt_val("new episodes", utils.compress_range(episodes), "success")
def continue_play(args, play_func=play_anime): name, _ = read_args(args, episodes=False) log = utils.Log(utils.read_log().get(name)) watch_later = utils.read_log(name, logfile=config.watchlaterfile) if watch_later: episodes = utils.extract_range(utils.Log(watch_later).eps) else: _, episodes = read_args(args) outputs.prompt_val("Watched", log._eps, "success", end='\t') outputs.normal_info(log.last_updated_fmt) if not log.eps: last = 0 else: last = int(re.split('-|,', log.eps)[-1]) to_play = utils.compress_range(filter(lambda e: e > last, episodes)) if to_play.strip(): play_func([name, to_play]) else: unsave_anime(name)
def edit_log(args): anime_name, episodes = read_args(args) utils.write_log(anime_name, utils.compress_range(episodes), append=False)