Complete Workflow

Crunchyroll Downloader โ€” Practical Scripting
Course 1 ยท Chapter 5 ยท Complete Workflow

๐Ÿ”„ Complete Workflow

Orchestrate the complete end-to-end workflow: load config, login with JWT, fetch episodes, parse data, and export to CSV. This brings all previous components together.

๐Ÿ“‹ The Workflow

def main():
    print("๐Ÿš€ CRUNCHYROLL DOWNLOADER")

    # Step 1: Load config
    config = Config()
    if not config.validate():
        return False

    # Step 2: Try cached token, or login
    token = load_cached_token(config.token_cache)
    if not token:
        print("๐Ÿ” Logging in...")
        token = login(config)
        if not token:
            return False
        save_token(token, config.token_cache)

    # Step 3: Create client and fetch episodes
    print("๐Ÿ“ก Fetching episodes...")
    client = CrunchyrollClient(config, token)
    episodes = client.get_episodes()
    print(f"โœ… Fetched {len(episodes)} episodes")

    # Step 4: Export to CSV
    print("๐Ÿ’พ Exporting to CSV...")
    export_to_csv(episodes, "episodes.csv")
    print("โœ… Saved to episodes.csv")

    return True

if __name__ == "__main__":
    main()

๐Ÿ’ป Coding Challenges

Challenge 1: JWT Login Flow

Implement complete login: config โ†’ login โ†’ cache token โ†’ return token.

Challenge 2: Episode Export

Export episode data to CSV with columns: show, episode, date watched.

Challenge 3: Complete Script

Build main() that orchestrates entire workflow with error handling.