Skip to content

Conversation

@medape
Copy link
Contributor

@medape medape commented Aug 4, 2025

Hello again! These commits add some conveniences to toggle subtitles:

Allow the use of TTML subtitles

Because why not? Even my 1st-gen ChromeCast supports them... partially.

Like VTT; only positioning, bold, italics and underline are honoured. Unlike VTT, some HTML codes cause the receiver to stop interpreting subtitles at all.

Automatically find subtitles on YouTube (default app only)

When using the catt cast -f URL (catt cast --force-default URL) command, all available subtitles are automatically found, and the best options (VTT > TTML > SRT) sent to the ChromeCast through the pychromecast parameter media_info.

  • This extends to any platform that yt-dlp is compatible with.
  • In the future, it should be possible to use the same mechanism to fix font size subtitles #412
  • If a subtitle URL is provided with the flag -s of --subtitles, only that subtitle file is loaded. This is the undocumented behaviour of the pychromecast module when both arguments subtitles and media_info are used, and I didn't find it prudent to work around this for now.

Add a new menu to toggle subtitles on and off

The menu is quite basic, and TRACK_ID is always a number:

Usage: catt subs [OPTIONS] [TRACK_ID]

Options:
  -n, --off   Hides all subtitles
  -l, --list  Lists all subtitles
  -h, --help  Show this message and exit.

These work for the default app. The YouTube app uses a different controller, and I couldn't find the relevant documentation, so only catt subs --off is compatible with it.

MIME type is only guessed for local files

Subtitle files in web servers are already served with MIME types, so we just read the MIME type from the HTTP response. This way, we don't need to check the URL, and we can use URLs that don't end with .srt, .vtt or .ttml (like YouTube's URLs)

What I couldn't do

medape added 4 commits July 6, 2025 23:11
- TTML is also supported.
- Limits of support are better described.
- Both online and local files are supported.
- A web server is only started if a local file needs to be served.
Not tested with other platforms.
Only disabling subtitles is compatible with the YouTube controller
If an URL is specified, the MIME type is read directly from the HTML response,
not guessed from the file termination. With this, we can use URLs that do not
end with .srt, .ttml or .vtt (e.g. URLs with subtitles in YouTube).

To allow this, the file extension is only checked if the file is local.
self.local_subs will be True; CATT will detect this and start a web
server so that ChromeCast can fetch it. Only devices in the same network
can access this file.
local_ip and port params are used for this purpose.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this forgotten from the previous docstring?

Copy link
Contributor Author

@medape medape Aug 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry I'm late. The answer's yes and no.

self.local_subs is still used, but now it's not directly provided by self._read_subs(). instead, self._read_subs() provides a MIME type only if the subtitles file was originally remote, AND the script uses the existence of the MIME type to infer if the file was remote or not.

This behaviour isn't documented anywhere, though, so I'll update the docstring right away.

EDIT: Done! But I might have overexplained it. Is there anything you want to change?

Also adding an annotation to the url() method
@skorokithakis
Copy link
Owner

This looks good to me, thank you! Have you tested it, and does it work well?

skorokithakis and others added 3 commits August 20, 2025 20:35
yt-dlp cannot always retrieve a name and an extension for a subtitles files.
In these cases, the keys 'ext' and 'name' do not exist, and CATT failed.

Example page: https://iandevlin.github.io/mdn/video-player-with-captions/
@medape
Copy link
Contributor Author

medape commented Aug 21, 2025

Not enough, as it turns out!

I had tested it several times in:

  • YouTube, with captioned videos;
  • YouTube, with non captioned videos;
  • with the Spanish TV app (set up the video through the app, and only used CATT to turn off and change subtitles)

but your question reminded me that I hadn't tried it in a random website besides those. I looked for any webpage I didn't already know, and found a test page referenced in the Mozilla docs.

yt-dlp doesn't always provide all the keys I expected, so I added a commit to supply default values, and now it works with the example page too. This should be enough.

Copy link
Owner

@skorokithakis skorokithakis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@skorokithakis skorokithakis merged commit 7bd7788 into skorokithakis:master Sep 6, 2025
1 check passed
@medape medape deleted the subtitles branch October 18, 2025 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

font size subtitles catt doesn't allow to select subtitles inside the container

2 participants