Active subtitle path
#1
I am looking for a way to retrieve the path to active captions currently being displayed, regardless of their location. Or is there a way to download the captions as a text variable?

Is it possible to fetch captions from a stream? Active captions.

I am working on creating an AI translator, but I cannot find a way to retrieve or download active captions.

Any help would be appreciated.

Unfortunately, my code is not functioning correctly.
 
Code:
def fetch_active_subtitle_path(kodi_ip_address: str, kodi_port: int) -> str:
# Configure logging
logging.basicConfig(filename=r"d:\_Python\KodiPlugin\log.txt", level=logging.DEBUG)
logger = logging.getLogger(__name__)

# JSON-RPC method to retrieve the current player properties
method = "Player.GetProperties"
params = {
"jsonrpc": "2.0",
"method": method,
"params": {
"playerid": 1, # Assuming the player ID is 1 for video playback
"properties": ["currentsubtitle"], # Retrieve the current subtitle property
},
"id": 1,
}

# Prepare the JSON payload
payload = json.dumps(params)

# Set the headers
headers = {
"Content-Type": "application/json",
"Connection": "Keep-Alive",
}

# Log the JSON-RPC request
logger.debug(f"JSON-RPC request: {payload}")

# Send the POST request using requests library
endpoint = f"http://{kodi_ip_address}:{kodi_port}/jsonrpc"
response = requests.post(endpoint, data=payload, headers=headers)

# Get the response content
response_content = response.text
logger.debug(f"JSON-RPC response: {response_content}")

# Check if the response is successful
if response.status_code == 200:
response_json = json.loads(response_content)
logger.debug(f"JSON-RPC response JSON: {response_json}")

if "result" in response_json and "currentsubtitle" in response_json["result"]:
current_subtitle = response_json["result"]["currentsubtitle"]
logger.debug(f"Current subtitle data: {current_subtitle}")

# Checking if the current subtitle is enabled
if current_subtitle.get("enabled", False):
active_subtitle_path = current_subtitle.get("name")
logger.debug(f"Active subtitle path: {active_subtitle_path}")

return active_subtitle_path

logger.debug("No active subtitle path found.")
return None
Reply
#2
I tested your code.  I don't see any property of "enabled" in the schema?  I do note that 'name' returned an empty string; not sure what that's supposed to be.

log here: lesiholeqo.kodi (paste)

I think you want rather
python:
params = {
    "jsonrpc": "2.0",
    "method": method,
    "params": {
    "playerid": 1, # Assuming the player ID is 1 for video playback
    "properties": ["subtitleenabled", "currentsubtitle"], # Retrieve the current subtitle property
    },
    "id": 1,
    }

but still "name" doesn't return much.  For external sub all I get is
 
Code:
DEBUG:__main__:Active subtitle path: (External)

scott s.
.
Reply
#3
Hi

Exactly how do I find the subtitle path??
Thus should be easy, but it's not.

Many thanks,
Reply
#4
Sorry, no idea.  My assumption is it would need a change to the JSON method to retrieve the path (I'm assuming it is available somewhere).

update.  I did take look at the code, and it wasn't obvious to me where to get the sub.  I'm assuming the proposed requirement is to change the JSON-RPC response for method Player.GetProperties property currentsubtitle "name" attribute so that if the current subtitle is an external sub, the full path/filename is provided in the response.  Not sure about the case of an internal text subtitle?

scott s.
.
Reply

Logout Mark Read Team Forum Stats Members Help
Active subtitle path0