Support external subtitles for plex#533
Conversation
killergerbah
left a comment
There was a problem hiding this comment.
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.
|
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. |
|
Thanks, subtitle detection is working for me now. |
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
sessionid. 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 thewebRequestpermission 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.