Skip to main content

Overview

The providers module handles fetching and caching provider lists and channels from the Cricfy service. It manages encrypted data retrieval, decryption, and intelligent caching to minimize network requests.

Functions

get_providers()

Fetches and decrypts the list of providers from Cricfy. Uses caching to avoid repeated network calls.
def get_providers()
Returns:
providers
list[dict]
List of provider dictionaries, each containing:
  • title (str): Provider name
  • image (str): Provider logo URL
  • catLink (str): M3U playlist URL for the provider
Returns empty list [] if fetch fails or no providers available.
Behavior:
  • Checks cache first using the key "cricfy_providers"
  • On cache miss, fetches from {provider_api_url}/cats.txt
  • Decrypts the response using decrypt_data()
  • Caches the decrypted JSON data indefinitely
  • Returns empty list on any error
Example:
from lib.providers import get_providers

providers = get_providers()
for provider in providers:
    print(f"Provider: {provider['title']}")
    print(f"Playlist URL: {provider['catLink']}")

get_channels()

Fetches channels for a specific provider by parsing its M3U playlist.
def get_channels(provider_url: str)
provider_url
str
required
The M3U playlist URL for the provider (typically from catLink field)
Returns:
channels
list[PlaylistItem]
List of PlaylistItem objects representing available channels. Each PlaylistItem contains channel metadata, URL, and streaming configuration.
Caching:
  • Cache key: "channels_{sha256_hash(provider_url)}"
  • Cache TTL: 3600 seconds (1 hour)
  • Cached data includes fetch timestamp for TTL validation
  • Cache stores serialized PlaylistItem dictionaries
Error Handling:
Raises exceptions on fetch or parse failures. The caller should handle exceptions appropriately.
Example:
from lib.providers import get_channels

provider_url = "https://example.com/playlist.m3u"
try:
    channels = get_channels(provider_url)
    for channel in channels:
        print(f"Channel: {channel.title}")
        print(f"URL: {channel.url}")
        print(f"Logo: {channel.tvg_logo}")
except Exception as e:
    print(f"Failed to fetch channels: {e}")

Internal Functions

_hash_key()

Internal helper to generate SHA-256 hashes for cache keys.
def _hash_key(key: str) -> str
key
str
required
String to hash (typically a URL)
Returns:
hash
str
Hexadecimal SHA-256 hash of the input string

Constants

ConstantValueDescription
PROVIDERS_CACHE_KEY"cricfy_providers"Cache key for provider list
CHANNEL_CACHE_TTL3600Channel cache lifetime in seconds (1 hour)

Dependencies

This module depends on:
  • lib.config.cache - Caching functionality
  • lib.logger - Logging functions
  • lib.crypto_utils - Decryption utilities
  • lib.req - HTTP request handling
  • lib.m3u_parser - M3U playlist parsing
  • lib.remote_config - Remote configuration fetching

Build docs developers (and LLMs) love