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

How to open Plex video in any player with 3 clicks in any web browser (no plugin needed!) #51

Open
porg opened this issue Mar 23, 2023 · 11 comments

Comments

@porg
Copy link
Contributor

porg commented Mar 23, 2023

Play Plex Video in other video player

@porg
Copy link
Contributor Author

porg commented Mar 23, 2023

That last step nr.3 can be expedited with a script / macro / service, tied to a global hotkey.

  • On macOS you can simply create a service (aka quick action) with /Applications/Automator.app
  • The code may be as simple as mpv $(pbpaste) which runs mpv with the content of the clipboard as its sole argument, which holds the HTTP video streaming URL we copied in step 2.
    • Note: Automator's Run Shell Script environment may not have the same $PATH as your user, so you may need to use full pathnames to the binaries such as /usr/local/bin/mpv $(/usr/bin/pbpaste). Then it worked for me.
  • And then go to System Preferences → Keyboard → Shortcuts → Services
  • Then you can assign a shortcut to a service, e.g.
    • ⌃ ⌥ ⌘ V to "Play with VLC"
    • ⌃ ⌥ ⌘ M to "Play with mpv"
    • ⌃ ⌥ ⌘ Q to "Play with QuickTime Player"

@porg
Copy link
Contributor Author

porg commented Mar 23, 2023

  • This info here is not meant to diminish the work which went and goes into the plex-to-vlc plugin!
  • It is to show a solution for use cases where this may be the only possibility
  • Or as an alternative workflow, e.g. choosing the video player ad hoc by invoking a particular global shortcut in step 3.

@soerenkampschroer
Copy link
Owner

Just wanted to add that for cases where the download link works, the extension will also work in the next version I'm currently working on. I'm all for providing alternative ways to get this functionality though, I just wanted to point that out.

I can leave this as an open issue here but I thought it might make more sense for you to make a gist that I can link to in the readme? Or I can incorporate it into the repo as a markdown file which would be linked to in the main readme. Let me know what you think.

@porg
Copy link
Contributor Author

porg commented Mar 24, 2023

I do not know too much about the "Download Link" yet. But if you say that download link sometimes works and sometimes not, I have a suspicion:

Plex tries to stream the video as-is:

  1. if it uses streaming-friendly (compatible) container format and/or codec format
  2. the bitrate is below the bitrate-limit (a preference!)
  • Plex Preferences > Web Player > Video quality > Internet Streaming > Video quality: By default is set to 2 MBps
  • Despite "Internet" in "Internet Streaming" this setting seems to also affect LAN.
  • Hence I always set it to maximum, because my LAN is fast enough for all my video bandwidths

Otherwise Plex transcodes on the fly or uses pre-transcoded variants. And I guess in these instances the "Download Link" may differ?

@porg
Copy link
Contributor Author

porg commented Mar 24, 2023

Now regarding my alternative method I outlined in this issue:

  • Glad that you understood the constructive nature of my proposal!
  • Let's not do a concrete followup of this yet (gist, readme, links, etc) but first collect ideas (I have more) and you can later decide on the actions to take and attribution to give. Let's give this some time.

@porg
Copy link
Contributor Author

porg commented Mar 24, 2023

I have one more idea for an alternative Mac solution, which needs only a single shortcut!

  • I'm a UX designer by profession, only an amateurish scripter/hacker, no proper developer.
  • Let me outline my idea, and maybe you work out a proper user-installable software from this?

Hotkey/App opens Plex video from Safari's top window in video player of choice

Pseudo code:

  1. Tell application Safari (or also Chrome if you deem its scripting interface is adequate )
  2. set $URL to value of attribute href of HTML element <a> with target="downloadFileFrame" inside submenu of first encountered <button> instance in viewport with attribute data-testid="preplay-more" (the "more" menu with the 3 dots)
  • If you are viewing a video detail page there is only one "more" menu anyhow.
  • If you are in any sort of listing (genre listing, episode list, etc) the script gets the download link of the first video visible in the viewport. Our software is context sensitive.
  1. if ( $videoPlayerPreferred) { openURLinPlayer($videoPlayerPreferred, $URL) }, else { videoPlayerChooser($URL) }
  • videoPlayerChooser() --> Opens a chooser with all video players for which we have openURLinPlayer() methods with a Cancel and PLAY button.
    • Benefits: Only need to memorize one shortcut + Choose desired player ad hoc.
    • Each supported video player has its run script. Over time the catalog of supported apps will increase.
    • The dialog lists those which are supported AND present on your system (simple "filepath to app binary exists?" check during runtime) alphabetically.
    • The player you recently used is preselected. Never used yet? → Fallback is the first item.
    • Up/down arrow to navigate list, ENTER to play, ESC to cancel.
  • $videoPlayerPreferred - This can either be a preference (to avoid the dialog). Or our software if implemented as a service could have duplicate instances, and in each instance you set the $videoPlayerPreferred variable and assign this service instance its own dedicated vide player specific hotkey.

Want to develop this software?

  • Ideally a standalone app which lets you assign your shortcuts to the supported video players or the video-player-chooser-dialog.
  • But if you are not in native MacOS development, I think we could achieve quite something user friendly with little effort:
  • Make a service with Automator which uses Applescript (to access Safari) and use Applescript or Run Shell Script to implement the video-player-macros and the video-player-chooser-dialog.
  • Make a .pkg installer
    • Puts the service into ~/Library/Services
    • Runs a post-install-script which is an AppleScript dialog:
      • Hotkey for "Play video URL with…"
      • We will now open System Preferences → Keyboard → Shortcuts → Services for you.
      • There please find the service "Play video URL with…" and assign it a shortcut of your liking.

@soerenkampschroer
Copy link
Owner

I've never really worked with swift or objective-c so I'm probably not the right person to implement this. But I did a little research just now and as far as I can tell this will only work with Safari through Applescript, like you said. Applescript can be invoked by Swift so in theory what you describe is possible. It's just that it will only work with Safari. Technically it might still work in Chrome, but who knows how long they will support the scripting interface.

There could be another way using ui automation but that seems a bit involved. I feel like the more appropriate way of extending the feature set of a browser or a webpage is a browser extension. Speaking of other Browsers, I do have plans to support Firefox in the future which would broaden the scope of this project a bit.

I can see the usecase for people using Safari and wanting to use an external player for Plex but I'm afraid I don't have the time to write an app like that and maintain it at the moment.

@porg
Copy link
Contributor Author

porg commented Mar 24, 2023

Estimate with my scripting skills

  • 16-24 hours to get °2 working in °1 Safari only
    • Someone savvy with how Safari's AppleScript can access the DOM and savvy with proper CSS selectors or xpath, has that in 4hours
  • °3 videoPlayerChooser() with preference handling is beyond my capabilities.
    • I would be able to design the "Open URL" macros/command-lines for 2-3 video-players .
    • And simple create separate services (with code duplication ofc, I'm admittedly an amateur) with 1 macro each, and assign that a custom hotkey.
    • But doing °3 properly certainly takes a pro also 16 hours (with testing).
  • Packaging/installer: 4-8 hours for a pro I'd estimate.

@soerenkampschroer
Copy link
Owner

I had a go at it for fun and it's pretty easy to do with Shortcuts. This works for Safari, you can have it listen to a keyboard shortcut etc. It doesn't have a picker for the player but you can just change vlc to mpv or iina in the shell script either manually or with a prompt. Check it out:

https://www.icloud.com/shortcuts/2734fbb767474c3f8ab5ce5a72f2a3f6

Screenshot 2023-03-24 at 20 00 30

You need to enable "Allow JavaScript from Apple Events" in the Developer menu of Safari for it to work. I imagine you could make it work without that by using the "Get Details of Safari Web Page" block inside Shortcuts, but you would need to build the download link yourself and I didn't try that.

@porg
Copy link
Contributor Author

porg commented Mar 25, 2023

Cool to know, but only possible for me in the future as I'm on macOS Big Sur which does not yet have Shortcuts.app

@porg
Copy link
Contributor Author

porg commented Mar 25, 2023

Did this experiment make you eager to do the whole software as I outlined it?

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

No branches or pull requests

2 participants