Elementum Documentation

repository·master·Indexed 20 days ago

https://github.com/elgatito/plugin.video.elementum

Elementum is a high-performance torrent finding and streaming engine for Kodi. It orchestrates external Kodi add-on providers to locate BitTorrent links and streams them using a custom Go-based engine built on libtorrent. The project includes the elementum-web interface (built with React), a bjsonrpc server for bidirectional JSON-RPC communication over TCP/IP, and tools for compiling the daemon and bundling Kodi-installable ZIP files.

Tokens
3.7K
Snippets
13
Records
22
Agent score
69%

What's inside plugin.video.elementum

  1. What is Elementum?

    master
    Elementum is a torrent finding and streaming engine designed for Kodi. It functions as a core engine that orchestrates 'providers' (separate Kodi add-ons) to find media links. It does not search torrent websites directly; instead, it calls installed providers in parallel, collects and de-duplicates BitTorrent links, verifies seed/peer counts in real-time, and ranks them by quality and availability before sending them to its high-performance BitTorrent streaming engine (built on libtorrent).
  2. How Elementum Providers work

    master

    Elementum relies on external 'providers' to find media streams.

    • Definition: Providers are standard Kodi add-ons that search for media and return a list of BitTorrent links.
    • Workflow: When a user selects media (via a TMDB ID), Elementum enumerates all installed providers, calls them in parallel, de-duplicates the returned links, and then uses its internal engine to stream the best match.
    • Development: Providers are lightweight and can be written in as little as ~20 lines of Python code. They function as independent Kodi add-ons with their own configuration.
  3. Set up the elementum-web development environment

    master

    The elementum-web package is built using Create React App. To ensure a successful build, you must use Node.js 12.

    To start the development server, run npm start. The application will be available at http://localhost:3000. The server supports hot reloading, meaning the page will automatically reload when you make edits, and linting errors will be displayed in the console.

    npm start
  4. Bundle Elementum into a Kodi-installable ZIP

    master

    Once binaries are compiled, use the bundle.sh script located in the plugin.video.elementum folder to create a .zip file for Kodi installation. This script combines the Python logic with the compiled binaries.

    Usage Patterns:

    • To bundle all collected platforms into a zip in the current folder:

      ./bundle.sh --binaries=/path/to/elementum/build
    • To bundle a specific platform with a custom suffix and target directory:

      ./bundle.sh --binaries=/path/to/elementum/build --platform=android_arm64 --suffix=custom_suffix_to_add_into_zip --target=/destination/folder/
    • To view available options:

      ./bundle.sh --help

    Note: After installing a new zip, restart Kodi to ensure the new code is running rather than a mix of old and new files.

    # Bundle all platforms
    ./bundle.sh --binaries=/path/to/elementum/build
    
    # Bundle specific platform with custom suffix
    ./bundle.sh --binaries=/path/to/elementum/build --platform=android_arm64 --suffix=custom_suffix_to_add_into_zip --target=/destination/folder/
  5. Build plugin.video.elementum for release

    master

    To prepare a release of the plugin, you must bundle existing binaries, verify Python dependencies and syntax, check localizations, and then generate/upload zip files. The process requires a GitHub access token (GH_TOKEN) and a configured Go environment (GOPATH).

    Build Workflow Steps:

    1. Fetch Binaries: Download the latest binaries from the elementum-binaries repository and move them to resources/bin/.
    2. Verify Environment: Install dependencies via pip install -r requirements.txt and run flake8 for syntax checking.
    3. Localization & Compilation: Run ./scripts/xgettext.sh and make to ensure localizations are intact and the project compiles.
    4. Packaging: If the current Git tag is a clean version (no hyphens), run make zipfiles to create the Kodi-compatible zip files.
    5. Distribution: Run make upload to push the zip files to a GitHub release.
    #!/bin/bash
    
    set -e
    
    TAG=$(git describe --tags)
    
    export GH_TOKEN=your_github_access_token
    export PATH=$HOME/go/bin:/usr/lib/go-1.9/bin/:$PATH
    export GOPATH=$HOME/go
    
    git checkout master
    
    rm -rf plugin.video.elementum
    
    # Get current binaries
    wget https://github.com/elgatito/elementum-binaries/archive/master.zip && \
    unzip master.zip && \
    mv elementum-binaries-master/* resources/bin/ && \
    rm -rf elementum-binaries-master && \
    rm master.zip
    
    sudo -S true
    
    # Check dependencies and syntax
    pip install -r requirements.txt
    python -m flake8
    
    # Check localizations and compile
    ./scripts/xgettext.sh
    make
    
    if [[ $TAG != *-* ]]
    then
        make zipfiles
        make upload
    fi
  6. Eject from the Create React App configuration

    master

    If you need full control over the underlying build tools (Webpack, Babel, ESLint, etc.), you can run npm run eject.

    WARNING: This is a one-way operation. Once you eject, you cannot go back.

    Executing this command will remove the single build dependency and copy all configuration files and transitive dependencies directly into your project directory. After ejecting, you are responsible for managing the configuration and dependencies yourself.

    npm run eject
  7. Compile the Elementum daemon

    master

    To build the elementum daemon from source, you must work within the elementum directory. This process uses Docker images containing the necessary compilers and libtorrent-go libraries.

    1. Pull required Docker images:

      make pull-all
    2. Compile for a specific platform:

      • For Android ARM64 shared library: make android-arm64-shared
      • For Android x86: make android-x86
    3. Compile for all supported platforms:

      make all

    Compiled binary files are placed in the /build folder.

    # Pull all docker images
    make pull-all
    
    # Compile for specific platform
    make android-arm64-shared
    make android-x86
    
    # Compile for all platforms
    make all
  8. Install Elementum in Kodi

    master

    To ensure Elementum functions correctly within Kodi, you must enable specific service settings before installation:

    1. Go to Settings > Service settings > Control.
    2. Enable both Application control options.
    3. Restart Kodi if you had to enable these options.
    4. Install the Elementum add-on as you would any other Kodi add-on.
  9. Create a bjsonrpc server with createserver()

    master

    Use createserver() to instantiate a bjsonrpc.server.Server object bound to a specific host and port. This server listens for incoming TCP connections. By default, it binds to 127.0.0.1 on port 10123 for security. To allow connections from any interface, use 0.0.0.0 as the host.

    To define which remote functions are available to clients, pass a class to the handler_factory parameter. This class will be instantiated to handle incoming RPC requests.

    import bjsonrpc
    
    # Create a server listening on all interfaces
    server = bjsonrpc.createserver("0.0.0.0")
    
    # Start the server loop
    server.serve()
  10. Connect to a bjsonrpc server with connect()

    master

    Use connect() to instantiate a bjsonrpc.connection.Connection object that establishes a TCP connection to a remote bjsonrpc server.

    Once connected, you can invoke remote methods on the server using the conn.call attribute. By default, the handler_factory is set to bjsonrpc.handlers.NullHandler, which means no functions are executable by the server unless a custom handler is provided.

    import bjsonrpc
    
    # Connect to a remote server
    conn = bjsonrpc.connect("rpc.host.net")
    
    # Call a method available on the server side
    result = conn.call.some_method_in_server_side()
    print(result)