Content Core

repository·main·Indexed 41 days ago

https://github.com/lfnovo/content-core

A unified tool for extracting, processing, and summarizing content from URLs, documents (PDF, DOCX), media (audio/video), and raw text. Available as a Python library, CLI, and MCP server, version 2.1.0. It supports various extraction engines including Docling, Crawl4AI, and Firecrawl, and provides built-in tool wrappers for LangChain.

Tokens
19.1K
Snippets
60
Records
88
Agent score
50%

What's inside Content Core

  1. How configuration priority works

    main

    Content Core resolves configuration using the following priority order (highest to lowest):

    1. Command flags (e.g., --engine)
    2. Environment variables (prefixed with CCORE_, e.g., export CCORE_URL_ENGINE=firecrawl)
    3. Config file (~/.content-core/config.toml)
    4. Defaults

    Environment Variables: To override config file values for a specific session, use the CCORE_ prefix. For example:

    export CCORE_URL_ENGINE=firecrawl
    export OPENAI_API_KEY=sk-...
    export CCORE_URL_ENGINE=firecrawl
  2. How Content Core selects processors

    main

    Content Core automatically routes input to the appropriate processor based on the input type:

    • URL provided: Routes to a URL processor (or the YouTube processor specifically for YouTube links).
    • File path provided: The system detects the file type using binary signatures and content analysis (no libmagic required), then routes it to the matching document or media processor.
    • Text provided: Handled by the text processor.

    File type detection is performed in pure Python by reading the first 512 bytes for binary signatures or 1024 bytes for text-based content analysis, making it independent of file extensions.

  3. Understanding the raise/degrade error boundary

    main

    Content Core distinguishes between a genuinely empty source and a processing failure. It is critical to handle exceptions correctly based on this distinction:

    • Total Failure (Raises Exception): Any failure related to routing, input, configuration, network, or parsing will raise a typed exception from common/exceptions.py. You should not treat an exception as an empty string.
    • Degradation (Internal to Source): Degradation is only permitted within a single source. For example, if a single page in a PDF fails to parse, the processor may log the error and skip that unit, but the overall file processing should continue. If the entire file cannot be processed, it must raise an error.
    • Empty Content: A return value of content="" signifies that the source was successfully processed but contained no text. It does not mean an error occurred.
  4. Core Operations in Content Core v2.0

    main

    In version 2.0, the clean/cleanup functionality has been removed. The library is now focused on two primary core operations:

    1. extract: Detects the input type and routes it to the appropriate processor to retrieve content.
    2. summarize: Processes existing content to generate a summary.

    The guiding principle of the architecture is a simple pipeline: detect input type $\rightarrow$ route to the right processor $\rightarrow$ return content.

  5. Transcribe Audio and Video Media

    main

    The media pipeline handles audio and video files by extracting audio streams and performing Speech-to-Text (STT).

    Workflow:

    1. Video: Uses ffprobe to identify audio streams, selects the highest quality stream, and then transcribes it.
    2. Audio: Transcribes the file using the configured audio_provider and audio_model (defaulting to settings in ContentCoreConfig).

    Concurrency: Audio transcription can be parallelized. The audio_concurrency setting (default: 3, max: 10) controls how many segments are processed simultaneously using a semaphore. Results are returned in the original order.

  6. Use the Content Core MCP Server

    main

    Content Core provides an MCP (Model Context Protocol) server that exposes two primary tools for AI agents and LLM environments. Both tools return plain text results.

    Available Tools

    1. extract_content: Extracts content from a given source.
    2. summarize_content: Summarizes provided text.

    You can launch the server via the CLI using the content-core mcp command.

    content-core mcp
  7. How engine selection and fallback works

    main

    When configuring engines (such as url_engine or document_engine), the system follows a strict rule regarding explicit vs. automatic selection:

    1. Explicit Selection: If you specify a particular engine, the system will honor it. If that engine is unavailable or fails, the operation will raise an error rather than switching to a different one. This ensures you get the specific quality level you requested.
    2. Automatic Selection (auto): If you set the engine to auto, the system is permitted to fall back to alternative engines if the preferred one fails. This is the only mode that allows for graceful degradation.

    This behavior applies to all implementation selectors, including LLM or STT providers.

  8. Extract content from Reddit posts

    main

    Content Core automatically detects Reddit URLs and extracts data via the public .json endpoint. This requires no API key or authentication for public posts. It extracts:

    • Post title and body
    • Metadata (author, score, subreddit)
    • Full comment tree with nested replies

    If JSON extraction fails, it falls back to the configured url_engine.

  9. Understand Content Core Routing and Input Types

    main

    The orchestrator automatically routes inputs to the appropriate processor based on the input type or MIME type:

    Input TypeRouting Action
    Plain TextCalls process_text
    YouTube URL (youtube.com or youtu.be)Calls extract_youtube
    URL (Article MIME)Calls extract_from_url
    URL (PDF MIME)Downloads file and calls extract_pdf_file
    File (PDF MIME)Calls extract_pdf_file
    File (DOCX MIME)Calls extract_office
    File (Video MIME)Calls extract_video
    File (Audio MIME)Calls transcribe_audio
    File (Text/Plain MIME)Calls extract_text_file

    Errors:

    • InvalidInputError: Raised when no source is provided.
    • UnsupportedTypeException: Raised when the MIME type is unknown.
  10. Dependency model: Formats vs. Engines

    main

    Content Core separates dependencies into two categories:

    • Core Formats: Libraries required to read standard file formats (e.g., python-docx, openpyxl, pdfplumber) are included in the main project dependencies. You can expect these to work upon installation.
    • Optional Engines: Heavyweight libraries used as alternative engines (e.g., docling, crawl4ai) are treated as optional extras.

    If an optional engine is missing, the system will raise an ImportError that includes the specific installation command required to enable that feature.

  11. Process Audio and Video Files

    main

    When extracting from audio or video files, Content Core automatically extracts the audio track and transcribes it using a Speech-to-Text (STT) engine.

    Key Features:

    • Parallel Transcription: Long audio files are split into segments and transcribed in parallel to improve speed.
    • Concurrency Control: Use audio_concurrency (1-10, default 3) to manage simultaneous transcriptions. Higher values increase speed but may trigger API rate limits.
    • Custom STT: You can override the STT provider and model for specific calls using audio_provider and audio_model in the ContentCoreConfig object.
    # Custom STT model for a specific call
    from content_core import ContentCoreConfig
    
    config = ContentCoreConfig(audio_provider="openai", audio_model="whisper-1")
    result = await content_core.extract_content(file_path="audio.mp3", config=config)
  12. Configure AI Providers (LLM and STT)

    main

    Content Core uses the Esperanto abstraction layer, allowing you to switch between providers by updating configuration without changing code.

    Supported Providers:

    ProviderLLM SupportSTT SupportAPI Key
    openai (default)GPT-4o, etc.WhisperOPENAI_API_KEY
    anthropicClaude models—ANTHROPIC_API_KEY
    googleGemini models—GOOGLE_API_KEY
    groqLLaMA, Mixtral, etc.WhisperGROQ_API_KEY
    deepseekDeepSeek models—DEEPSEEK_API_KEY
    ollamaLocal models—— (local)
    openrouterMultiple providers—OPENROUTER_API_KEY

    Usage Patterns:

    • Global LLM: Set llm_provider and llm_model.
    • Summarization Specific: Use summary_model to override the default LLM for summaries.
    • Global STT: Set stt_provider and stt_model.
    • Per-call STT Override: Use audio_provider and audio_model in the ContentCoreConfig passed to extract_content.