Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support external subtitles for plex #533

Merged
merged 2 commits into from
Oct 13, 2024
Merged

Conversation

ShanaryS
Copy link
Contributor

@ShanaryS ShanaryS commented Oct 8, 2024

Fixes: #531

Tested on Chrome and Firefox with admin and non-admin accounts.

Supports external subtitles as well as subtitles from Plex's subtitle search feature. However internal subtitles don't work as we need the session id. I cannot find this anywhere as I did with the other values. The only way might be to monitor requests as plenty contain it, but that would require the webRequest permission on the extension. Even if internal subtitles are supported, they would work only if currently selected and not being burned in at the time the user loads the subtitles.


It seems downloading the subtitles from the session is finnicky. So even if we were to have all the information, the endpoint wasn't really designed for full downloads so would probably need some extra care. So I don't think it's worth trying to get internal subtitles to work at least for now. The way external subtitles are being downloaded is using an endpoint designed for downloading.

Copy link
Owner

@killergerbah killergerbah left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution!
I'm not familiar with Plex but I tested this out using a local Plex server and wasn't able to get it to work immediately. This line:

const imgTags = document.querySelectorAll('img[src*="plex.direct"]');

excludes image tags with source URLs that look like http://127.0.0.1/..., which is what they looked like when I was testing.

My suggestion is to change the overall approach to one that depends less on the specific UI elements on the page and instead inspect the network traffic directly. For example, on my computer Plex is already automatically downloading the metadata in JSON. If you filter by "metadata" in your browser's network traffic inspector then you will see it.

Therefore, I believe Plex will be compatible with the JSON hijacking approach that is used in other asbplayer scripts. The server URL can be derived by hijacking the fetch call that fetches metadata. See nrk-tv-page.ts for an example of how JSON and fetch hijacking are combined to get subtitle data.

@ShanaryS
Copy link
Contributor Author

ShanaryS commented Oct 13, 2024

Hijacking is definitely much better, this is how I originally wanted to do it. External subtitles should hopefully work for you now.

It now allows getting the subtitle stream but it's still is unusable currently. Trying to download the entire subtitle at once seems brittle, so the best way forward would be to support streaming subtitles in the extension and let it update as the video plays. If the video was resumed midway through, then the subtitles before would be missing. Also would probably need to handle seeking around. It wouldn't be worth going for internal subtitles without these. If it is to be implemented in the future, the commented code should suffice with the streaming being handled elsewhere.

@killergerbah
Copy link
Owner

Thanks, subtitle detection is working for me now.
It is not likely that subtitle streaming is implemented any time soon but thanks for the note on internal subtitles.

@killergerbah killergerbah merged commit b417348 into killergerbah:main Oct 13, 2024
1 check passed
@killergerbah killergerbah added this to the Extension v1.6.0 milestone Oct 13, 2024
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.

Plex Support
2 participants