### Perform POST Request using LogicDeviceManager Source: https://github.com/wiltonsr/pyintelbras/blob/main/README.md Example of performing a POST request to the LogicDeviceManager to get camera state. The body parameter is used to send data in the request. ```python from pyintelbras import IntelbrasAPI intelbras = IntelbrasAPI("http://device-server.example.com") intelbras.login("api-user", "api-pass") response = intelbras.api.LogicDeviceManager.getCameraState.post(body={ 'uniqueChannels': [-1] }) ``` -------------------------------- ### Install PyIntelbras Source: https://github.com/wiltonsr/pyintelbras/blob/main/README.md Install the PyIntelbras library using pip. This is the first step to begin using the module. ```bash pip install pyintelbras ``` -------------------------------- ### Perform GET and POST API Requests Source: https://context7.com/wiltonsr/pyintelbras/llms.txt Demonstrates how to execute standard GET requests and POST requests by appending .post to the method chain. ```python from pyintelbras import IntelbrasAPI intelbras = IntelbrasAPI('http://192.168.1.100', 'admin', 'senha123') # Requisição GET (padrão) # GET /cgi-bin/configManager.cgi?action=getConfig&name=ChannelTitle response = intelbras.configManager(action='getConfig', name='ChannelTitle') # Equivalente explícito response = intelbras.configManager.get(action='getConfig', name='ChannelTitle') # Requisição POST # POST /cgi-bin/api/LogicDeviceManager/getCameraState.cgi response = intelbras.api.LogicDeviceManager.getCameraState.post( body={'uniqueChannels': [-1]} ) print(response.status_code) print(response.json()) ``` -------------------------------- ### Perform GET Request using configManager Source: https://github.com/wiltonsr/pyintelbras/blob/main/README.md Demonstrates performing a GET request using the configManager. This is the default request type if not explicitly specified. ```python from pyintelbras import IntelbrasAPI intelbras = IntelbrasAPI("http://device-server.example.com") intelbras.login("api-user", "api-pass") # Mesmo efeito para ambas as requisições response = intelbras.configManager(action='getConfig', name='ChannelTitle') response = intelbras.configManager.get(action='getConfig', name='ChannelTitle') ``` -------------------------------- ### Call API Endpoints Dynamically Source: https://context7.com/wiltonsr/pyintelbras/llms.txt Access any API endpoint by calling it as a method on the IntelbrasAPI object, passing parameters as keyword arguments. This example calls the configManager to get ChannelTitle settings. ```python # Qualquer endpoint da API pode ser chamado como método # GET http://192.168.1.100/cgi-bin/configManager.cgi?action=getConfig&name=ChannelTitle response = intelbras.configManager(action='getConfig', name='ChannelTitle') print(response.status_code) # 200 print(response.text) # table.ChannelTitle[0].Name=Camera01 # table.ChannelTitle[1].Name=Camera02 ``` -------------------------------- ### GET /cgi-bin/configManager.cgi Source: https://context7.com/wiltonsr/pyintelbras/llms.txt Executes dynamic configuration management commands on the Intelbras device. ```APIDOC ## GET /cgi-bin/configManager.cgi ### Description Calls a specific configuration management endpoint on the device. The library converts method calls into CGI requests. ### Method GET ### Endpoint /cgi-bin/configManager.cgi ### Parameters #### Query Parameters - **action** (string) - Required - The action to perform (e.g., getConfig) - **name** (string) - Required - The configuration parameter name to retrieve ### Response #### Success Response (200) - **body** (string) - Returns key=value formatted data, which the library can convert to a dictionary. ``` -------------------------------- ### Get Configuration using configManager Source: https://github.com/wiltonsr/pyintelbras/blob/main/README.md Use the configManager method to retrieve configuration settings, such as ChannelTitle. The library automatically appends necessary API prefixes and suffixes. ```python from pyintelbras import IntelbrasAPI intelbras = IntelbrasAPI("http://device-server.example.com") intelbras.login("api-user", "api-pass") response = intelbras.configManager(action='getConfig', name='ChannelTitle') ``` -------------------------------- ### Find Media Files Source: https://context7.com/wiltonsr/pyintelbras/llms.txt Search for media files (recordings) on the device by providing search parameters like channel, start time, and end time. This method abstracts the complex 5-step API process. ```python from pyintelbras import IntelbrasAPI intelbras = IntelbrasAPI('http://192.168.1.100', 'admin', 'senha123') # Parâmetros de busca params = { 'condition.Channel': 1, 'condition.StartTime': '2024-8-27 12:00:00', 'condition.EndTime': '2024-8-29 12:00:00' } # Busca arquivos de mídia resultado = intelbras.find_media_files(params) print(resultado) # {'found': 2, # 'items': [ # {'VideoStream': 'Main', # 'Channel': 0, # 'Type': 'dav', # 'StartTime': datetime.datetime(2024, 8, 28, 2, 40, 49), # 'EndTime': datetime.datetime(2024, 8, 28, 2, 41), ``` -------------------------------- ### Get API Version Source: https://context7.com/wiltonsr/pyintelbras/llms.txt Access the api_version property to retrieve the CGI API version of the connected Intelbras device. This is useful for checking compatibility. ```python from pyintelbras import IntelbrasAPI intelbras = IntelbrasAPI('http://192.168.1.100', 'admin', 'senha123') # Obtém a versão da API version = intelbras.api_version print(version) # {'version': 2.84} ``` -------------------------------- ### GET /rtsp_url Source: https://context7.com/wiltonsr/pyintelbras/llms.txt Generates a formatted RTSP URL for streaming video from a specific channel. ```APIDOC ## GET /rtsp_url ### Description Generates the RTSP URL required to access the live video stream of a specific camera channel. ### Method GET ### Parameters #### Query Parameters - **protocol** (string) - Optional - The streaming protocol (default: rtsp) - **port** (integer) - Optional - The RTSP port (default: 554) - **channel** (integer) - Required - The channel number to stream - **subtype** (integer) - Required - The stream quality (0 for main, 1 for secondary) ### Response #### Success Response (200) - **url** (string) - The complete RTSP connection string. ``` -------------------------------- ### Get Intelbras API Version Source: https://github.com/wiltonsr/pyintelbras/blob/main/README.md Access the `api_version` attribute to retrieve the current API version of the Intelbras device. ```python intelbras.api_version # {'version': 2.84} ``` -------------------------------- ### Initialize IntelbrasAPI Source: https://context7.com/wiltonsr/pyintelbras/llms.txt Instantiate the IntelbrasAPI class with server details and credentials. SSL verification can be disabled if necessary. Alternatively, initialize with server only and call login() separately. ```python from pyintelbras import IntelbrasAPI # Inicialização básica com login automático intelbras = IntelbrasAPI( server='http://192.168.1.100', user='admin', password='senha123', verify_ssl=False ) # Ou inicialização separada intelbras = IntelbrasAPI('http://192.168.1.100') intelbras.login('admin', 'senha123') ``` -------------------------------- ### Initialize and Login to Intelbras API Source: https://github.com/wiltonsr/pyintelbras/blob/main/README.md Initialize the IntelbrasAPI with the device server address and log in using API credentials. This is a prerequisite for making further API calls. ```python from pyintelbras import IntelbrasAPI intelbras = IntelbrasAPI("http://device-server.example.com") intelbras.login("api-user", "api-pass") ``` -------------------------------- ### Download Files from DVR Source: https://context7.com/wiltonsr/pyintelbras/llms.txt Iterates through a list of file items and downloads them using the RPC_Loadfile method. ```python import os for item in resultado.get('items', []): filepath = item.get('FilePath') filename = os.path.basename(filepath) response = intelbras.RPC_Loadfile(extra_path=filepath) if response.status_code == 200: with open(filename, 'wb') as f: f.write(response.content) print(f"Arquivo salvo: {filename}") ``` -------------------------------- ### Enable Debug Logging Source: https://context7.com/wiltonsr/pyintelbras/llms.txt Configures Python logging to output HTTP request details to stdout for troubleshooting. ```python import sys import logging from pyintelbras import IntelbrasAPI # Configura logging para stdout stream = logging.StreamHandler(sys.stdout) stream.setLevel(logging.DEBUG) log = logging.getLogger('pyintelbras') log.addHandler(stream) log.setLevel(logging.DEBUG) # Agora todas as requisições serão logadas intelbras = IntelbrasAPI('http://192.168.1.100') intelbras.login('admin', 'senha123') response = intelbras.configManager(action='getConfig', name='ChannelTitle') # DEBUG - API Server Endpoint: http://192.168.1.100 # DEBUG - Call method 'configManager' with arguments: () and {'action': 'getConfig', 'name': 'ChannelTitle'} # DEBUG - Requesting GET to URL http://192.168.1.100/cgi-bin/configManager.cgi?action=getConfig&name=ChannelTitle # DEBUG - Request status_code 200 - OK ``` -------------------------------- ### Handle Parameters with Special Characters using Argument Unpacking Source: https://github.com/wiltonsr/pyintelbras/blob/main/README.md Demonstrates how to handle query parameters with invalid Python syntax (like '.' or '[]') by using dictionary unpacking. This is necessary for parameters such as 'condition.Channel'. ```python params = { 'action': 'findFile', 'condition.Channel': 1 } response = intelbras.mediaFileFind(**params) ``` -------------------------------- ### Find Media Files with pyintelbras Source: https://github.com/wiltonsr/pyintelbras/blob/main/README.md Use the `find_media_files` method to search for media files on the Intelbras device. This method simplifies the process of finding files by abstracting multiple API calls. ```python params = { 'condition.Channel': 1, 'condition.StartTime': '2024-8-27 12:00:00', 'condition.EndTime': '2024-8-29 12:00:00' } intelbras.find_media_files(params) # {'found': 1, # 'items': [{'VideoStream': 'Main', # 'Channel': 0, # 'Type': 'dav', # 'StartTime': datetime.datetime(2024, 8, 28, 2, 40, 49), # 'EndTime': datetime.datetime(2024, 8, 28, 2, 41), # 'Disk': 2, # 'Partition': 2, # 'Cluster': 371211, # 'FilePath': '/mnt/dvr/2024-08-28/0/dav/02/0/2/371211/02.40.49-02.41.00[R][0@0][0].dav', # 'Length': 3276800, # 'Flags': ['Event'], # 'Events': ['FaceRecognition'], # 'CutLength': 3276800}]} ``` -------------------------------- ### Capture Video Snapshots Source: https://context7.com/wiltonsr/pyintelbras/llms.txt Captures JPEG snapshots from specific channels and saves them to the local filesystem. ```python from pyintelbras import IntelbrasAPI intelbras = IntelbrasAPI('http://192.168.1.100', 'admin', 'senha123') # Captura snapshot do canal 1 # type: 0=JPEG normal, 1=JPEG de alta qualidade response = intelbras.snapshot(channel=1, type=0) if response.status_code == 200: # Salva a imagem em arquivo with open('/tmp/camera_snapshot.jpeg', 'wb') as f: f.write(response.content) print("Snapshot salvo com sucesso!") else: print(f"Erro ao capturar snapshot: {response.status_code}") # Captura snapshots de múltiplos canais for canal in range(1, 5): response = intelbras.snapshot(channel=canal, type=0) if response.status_code == 200: with open(f'/tmp/camera_{canal}.jpeg', 'wb') as f: f.write(response.content) ``` -------------------------------- ### List Video Channels Source: https://context7.com/wiltonsr/pyintelbras/llms.txt Retrieve a list of all configured video channels from the DVR/NVR using the channels property. Each channel is returned as a dictionary containing its name. ```python from pyintelbras import IntelbrasAPI intelbras = IntelbrasAPI('http://192.168.1.100', 'admin', 'senha123') # Lista todos os canais configurados canais = intelbras.channels print(canais) # [{'Name': 'Entrada'}, # {'Name': 'Estacionamento'}, # {'Name': 'Recepção'}, # {'Name': 'Corredor'}, # {'Name': 'Canal5'}, # {'Name': 'Canal6'}] # Iterar sobre os canais for i, canal in enumerate(canais): print(f"Canal {i+1}: {canal['Name']}") ``` -------------------------------- ### Login Method for Authentication Source: https://context7.com/wiltonsr/pyintelbras/llms.txt Use the login() method to set up HTTP Digest authentication for subsequent API requests. This is required unless credentials are provided during class instantiation. ```python from pyintelbras import IntelbrasAPI intelbras = IntelbrasAPI('http://dvr.exemplo.com.br') # Autenticação com usuário e senha intelbras.login('api-user', 'api-pass') # Após login, todas as requisições usam autenticação Digest response = intelbras.configManager(action='getConfig', name='General') print(response.status_code) # 200 ``` -------------------------------- ### Handling API Parameters with Dictionaries Source: https://context7.com/wiltonsr/pyintelbras/llms.txt Use dictionary unpacking to pass parameters to API methods, avoiding syntax errors with keys containing dots or special characters. ```python # INCORRETO - causa SyntaxError # response = intelbras.mediaFileFind(action='findFile', condition.Channel=1) # CORRETO - usar dicionário com descompactação params = { 'action': 'findFile', 'object': 12345, 'condition.Channel': 1, 'condition.StartTime': '2024-8-27 12:00:00', 'condition.EndTime': '2024-8-29 12:00:00', 'condition.Types[0]': 'dav', 'condition.Types[1]': 'jpg' } response = intelbras.mediaFileFind(**params) print(response.status_code) ``` -------------------------------- ### Handle Case Sensitivity in API Calls Source: https://github.com/wiltonsr/pyintelbras/blob/main/README.md Illustrates the case-sensitive nature of the Intelbras API. Incorrect casing in method names will result in errors. ```python intelbras.configManager(action='getConfig', name='ChannelTitle') ``` ```python intelbras.configmanager(action='getConfig', name='ChannelTitle') ``` -------------------------------- ### List Intelbras Channels Source: https://github.com/wiltonsr/pyintelbras/blob/main/README.md Retrieve a list of available channels from the Intelbras device using the `channels` attribute. Each channel is represented as a dictionary with its name. ```python intelbras.channels # [{'Name': 'Lab01'}, # {'Name': 'Lab02'}, # {'Name': 'Lab03'}, # {'Name': 'Lab04'}, # {'Name': 'Lab05'}, # {'Name': 'Lab06'}, # {'Name': 'Canal7'}, # {'Name': 'Canal8'}, # {'Name': 'Canal9'}, # {'Name': 'Canal10'}, # {'Name': 'Canal11'}, # {'Name': 'Canal12'}, # {'Name': 'Canal13'}, # {'Name': 'Canal14'}, # {'Name': 'Canal15'}, # {'Name': 'Canal16'}] ``` -------------------------------- ### Enable pyintelbras Logging Source: https://github.com/wiltonsr/pyintelbras/blob/main/README.md Configure Python's logging system to capture DEBUG level messages from pyintelbras and output them to standard output. This is useful for debugging API requests. ```python import sys import logging from pyintelbras import IntelbrasAPI stream = logging.StreamHandler(sys.stdout) stream.setLevel(logging.DEBUG) log = logging.getLogger('pyintelbras') log.addHandler(stream) log.setLevel(logging.DEBUG) intelbras = IntelbrasAPI("http://device-server.example.com") intelbras.login("api-user", "api-pass") response = intelbras.configManager(action='getConfig', name='ChannelTitle') ``` -------------------------------- ### Handling IntelbrasAPIException Source: https://context7.com/wiltonsr/pyintelbras/llms.txt Catch custom exceptions to manage authentication failures or invalid API operations gracefully. ```python from pyintelbras import IntelbrasAPI from pyintelbras.exceptions import IntelbrasAPIException intelbras = IntelbrasAPI('http://192.168.1.100') try: # Tentativa de login com credenciais vazias intelbras.login('', '') except IntelbrasAPIException as e: print(f"Erro da API: {e}") # Erro da API: Empty user or password try: # Busca de mídia pode falhar se finder não for criado resultado = intelbras.find_media_files({'condition.Channel': 1}) except IntelbrasAPIException as e: print(f"Erro na busca: {e}") # Erro na busca: Failed to create media file finder ``` -------------------------------- ### POST /find_media_files Source: https://context7.com/wiltonsr/pyintelbras/llms.txt Searches for recorded media files on the device based on specific criteria. ```APIDOC ## POST /find_media_files ### Description Searches for media files stored on the device, abstracting the multi-step CGI search process into a single call. ### Method POST ### Parameters #### Request Body - **condition.Channel** (integer) - Required - The channel index to search - **condition.StartTime** (string) - Required - Start time for the search (YYYY-MM-DD HH:MM:SS) - **condition.EndTime** (string) - Required - End time for the search (YYYY-MM-DD HH:MM:SS) ### Response #### Success Response (200) - **found** (integer) - Number of files found - **items** (array) - List of file objects containing stream details and timestamps ``` -------------------------------- ### Handle Special API Parameters Source: https://context7.com/wiltonsr/pyintelbras/llms.txt Uses dictionary unpacking to pass parameters that contain characters invalid in Python identifiers. ```python from pyintelbras import IntelbrasAPI intelbras = IntelbrasAPI('http://192.168.1.100', 'admin', 'senha123') ``` -------------------------------- ### Generate RTSP Stream URL Source: https://context7.com/wiltonsr/pyintelbras/llms.txt Construct the RTSP URL for real-time video streaming from a specific channel. Supports specifying protocol, port, channel number, and stream type (main or secondary). ```python from pyintelbras import IntelbrasAPI intelbras = IntelbrasAPI('http://192.168.1.100', 'admin', 'senha123') # Gera URL RTSP para o canal 1 (stream principal) url_principal = intelbras.rtsp_url( protocol='rtsp', port=554, channel=1, subtype=0 # 0=principal, 1=secundário ) print(url_principal) # rtsp://admin:senha123@192.168.1.100:554/cam/realmonitor?channel=1&subtype=0 # URL para stream secundário (menor qualidade) url_secundario = intelbras.rtsp_url(channel=2, subtype=1) print(url_secundario) # rtsp://admin:senha123@192.168.1.100:554/cam/realmonitor?channel=2&subtype=1 ``` -------------------------------- ### Parse API Responses Source: https://context7.com/wiltonsr/pyintelbras/llms.txt Converts raw key-value API responses into structured Python dictionaries using the parse_response helper. ```python from pyintelbras import IntelbrasAPI from pyintelbras.helpers import parse_response intelbras = IntelbrasAPI('http://192.168.1.100', 'admin', 'senha123') # Obtém capacidades do gerenciador de gravação response = intelbras.recordManager(action='getCaps') print(response.text) # caps.MaxPreRecordTime=30 # caps.PacketLengthRange[0]=1 # caps.PacketLengthRange[1]=60 # caps.PacketSizeRange[0]=131072 # caps.PacketSizeRange[1]=2097152 # caps.SupportExtraRecordMode=true # caps.SupportHoliday=true # caps.SupportPacketType[0]=Time # caps.SupportPacketType[1]=Size # caps.SupportResumeTransmit=false # Converte para dicionário Python dados = parse_response(response.text) print(dados) # {'caps': { # 'MaxPreRecordTime': 30, # 'PacketLengthRange': [1, 60], # 'PacketSizeRange': [131072, 2097152], # 'SupportExtraRecordMode': True, # 'SupportHoliday': True, # 'SupportPacketType': ['Time', 'Size'], # 'SupportResumeTransmit': False # }} # Acessa valores específicos print(dados['caps']['MaxPreRecordTime']) # 30 print(dados['caps']['PacketLengthRange'][1]) # 60 ``` -------------------------------- ### Parse Key-Value API Responses Source: https://github.com/wiltonsr/pyintelbras/blob/main/README.md Utilize the `parse_response` helper function to convert raw key-value formatted API responses into a Python dictionary. This facilitates easier data manipulation. ```python from pyintelbras.helpers import parse_response response = intelbras.recordManager(action='getCaps') print(response.text) # caps.MaxPreRecordTime=30 # caps.PacketLengthRange[0]=1 # caps.PacketLengthRange[1]=60 # caps.PacketSizeRange[0]=131072 # caps.PacketSizeRange[1]=2097152 # caps.SupportExtraRecordMode=true # caps.SupportHoliday=true # caps.SupportPacketType[0]=Time # caps.SupportPacketType[1]=Size # caps.SupportResumeTransmit=false d = parse_response(response.text) print(d) # {'caps': {'MaxPreRecordTime': 30, # 'PacketLengthRange': [1, 60], # 'PacketSizeRange': [131072, 2097152], # 'SupportExtraRecordMode': True, # 'SupportHoliday': True, # 'SupportPacketType': ['Time', 'Size'], # 'SupportResumeTransmit': False}} print(d.get('caps').get('PacketLengthRange')[1]) # 60 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.