woodruffw / ff2mpv

A Firefox/Chrome add-on for playing URLs in mpv.

Home Page:https://addons.mozilla.org/en-US/firefox/addon/ff2mpv/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Windows] Works on Firefox but not on Chrome

JoseHidalgo opened this issue · comments

Hi, I have successfully installed everything following the detailed "Installation on Windows" instructions:

  • mpv installed (see version in the screenshot below)
  • yt-dlp in the same folder as mpv
  • Python 3.8.8
  • Git (latest version) + cloned repository
  • mpv folder added to Windows PATH variable (same as Python and Git)
  • ff2mpv directory in C:\users{myuser}\
  • ff2mpv installation via PowerShell, for Firefox and Chrome, with no errors
  • Set-ExecutionPolicy Bypass
  • ff2mpv extension installed for Firefox and for Chrome
  • Restarted both browsers

ISSUE 1:
It works perfectly from Firefox (when clicking on the ff2mpv icon in, say, a YouTube page).
It doesn't work on Chrome (when clicking on the ff2mpv icon nothing happens). Since I have no error message I don't know what to do.
Why would it work on Firefox but not on Chrome?

ISSUE 2:
I'd like english subtitles to be added automatically in MPV.
In command line, this works perfectly:
mpv {YouTube URL} --slang=en --ytdl-raw-options=ignore-config=,sub-lang=en,write-auto-sub=
How could I achieve the same thing using ff2mpv?

Platform information

  • OS information: Windows 7 SP1 x64 (I know... migration is on the way, 3 months or so)
  • Chrome version: 109.0.5414.120 (official build) (64 bits)

Additional context (optional)

2023 05 02 - 16 18 58
2023 05 02 - 16 29 52

Thanks for the report; I don't use ff2mpv on either Windows or Chrome so I'll leave the community to triage that bit.

CC @eNV25 in particular, since they originally added that functionality.

How could I achieve the same thing using ff2mpv?

You can do something similar to the "audio only" trick, documented here: https://github.com/woodruffw/ff2mpv/wiki/How-to-just-play-audio-in-mpv-with-GUI

If you get it working, please add your example to the wiki!

Thanks for the quick reply. Let's see if eNV25 can help with Chrome.

About subtitles, I have followed the instructions, changing the ff2mpv.py script "args" line to this:
args = ["mpv", "--profile=youtube", "--no-terminal", "--", url]

Then I have added this to mpv.conf file:

[youtube]
slang=en
ytdl-raw-options=ignore-config=,sub-lang=en,write-auto-sub=

It works for all YouTube videos with auto-generated subtitles, but it doesn't work for YouTube videos with predefined subtitles.

commented

I don't use Windows.

@DanSM-5 Added the install.ps1 script, I believe.

I think I cracked the subtitles part. How could I add it to the wiki? I'm not used to such things. Here's the working code:

ff2mpv.py file:
args = ["mpv", "--profile=youtube", "--no-terminal", "--", url]

mpv.conf file:

[youtube]
ytdl-format=bestvideo[height<=?1080]+bestaudio/best
slang=en
sub-auto=fuzzy
ytdl-raw-options=ignore-config=,sub-lang=en,write-sub=,write-auto-sub=

The ytdl-format line is optional. It only limits video size to 1080p. It can be changed to 720p, 1440p or whatever.

Now I only need some help with Chrome. It all works great with Firefox.

Just tried reinstalling ff2mpv and the script is working for me in Chrome. Based on the output it looks like it was installed successfully.

@JoseHidalgo would you mind running the following commands in powershell and copying the output here?
Go to the directory where you cloned the repo $HOME\ff2mpv and run:

# Command 1
Get-Content .\ff2mpv-windows-chrome.json

# Command 2
Get-Content .\ff2mpv.bat

# Command 3
Test-Path 'Registry::HKEY_CURRENT_USER\SOFTWARE\Google\Chrome\NativeMessagingHosts\ff2mpv'

# Command 4
Get-Item 'Registry::HKEY_CURRENT_USER\SOFTWARE\Google\Chrome\NativeMessagingHosts\ff2mpv'

The output should be something like this:

PS C:\ff2mpv> Get-Content .\ff2mpv-windows-chrome.json
{
    "name":  "ff2mpv",
    "description":  "ff2mpv\u0027s native manifest",
    "path":  "ff2mpv.bat",
    "type":  "stdio",
    "allowed_origins":  [
                            "chrome-extension://ephjcajbkgplkjmelpglennepbpmdpjg/"
                        ]
}

PS C:\ff2mpv> Get-Content .\ff2mpv.bat
@echo off
call py -3 ff2mpv.py

PS C:\ff2mpv> Test-Path 'Registry::HKEY_CURRENT_USER\SOFTWARE\Google\Chrome\NativeMessagingHosts\ff2mpv'
True

PS C:\ff2mpv> Get-Item 'Registry::HKEY_CURRENT_USER\SOFTWARE\Google\Chrome\NativeMessagingHosts\ff2mpv'


    Hive: HKEY_CURRENT_USER\SOFTWARE\Google\Chrome\NativeMessagingHosts


Name                           Property
----                           --------
ff2mpv                         (default) : C:\ff2mpv\ff2mpv-windows-chrome.json

Additionally, you can see if chrome gets an error looking at the background page of the extension. Go to the 3 dot button on the top right corner > more tools > extensions > look for ff2mpv and click on 'Background page'. It will open chrome dev tools for the extension (See image).
image

Once open try to use the extension in chrome and look if something gets logged to the console.

How could I add it to the wiki?

There should be an "edit" button on each page in the wiki. You can use the editor that that button opens to make the changes.

That said, if you aren't able to figure it out, don't worry -- I'll do it in a day or so.

@woodruffw I need a bit of time to figure out the subs part. So far it kinda works on videos with auto-generated subs, and on SOME videos with predefined subs, but it still doesn't work on most videos with predefined subs. Trying to get some help on Reddit as we speak: https://www.reddit.com/r/mpv/comments/1367gh0/mpvconf_display_youtube_english_subtitles_either/

@DanSM-5 we're making some progress :) Here's the PowerShell output:
2023 05 03 - 14 42 44

And here's the background page output. There's a "File Not Found" error:
2023 05 03 - 14 42 26

@JoseHidalgo Thanks for the output. Everything that has to do with the native client seems fine.

In the background page the warning in yellow is not important. It just failed to load a source map for debugging. However the second line

Error: Failed to start native messaging host.

is an important clue about the issue. A quick search about it I found this question in stack overflow. It seems that the issue may be due to windows 7 not having the environment variable ComSpec set up. You could try it yourself with the command:

Write-Output $env:ComSpec

In my case it returns the location of cmd.exe:

C:\WINDOWS\system32\cmd.exe

If you don't get anything, you may need to add it yourself.

setx /m ComSpec "C:\WINDOWS\system32\cmd.exe"

The /m flag means that it will be set system-wide. That's the usual for that variable according to this answer. You may need to logout/login again for the variable to take effect.

@DanSM-5 understood. I have just checked, and apparently ComSpec is already set up in my system, no need to do anything unless you want me to:

2023 05 03 - 17 05 30

Also, let's remember that this issue is Chrome-specific. With Firefox everything works fine.

Yes, those questions in stack overflow are chrome specific.

I think we can roll out the ComSpec variable. In that question it also points out that for Windows 7 it was needed to remove a lock icon (change permissions) of the C:\Users directory and links to a tutorial.

As per chrome documentation:

Failed to start native messaging host.
Check whether you have sufficient permissions to execute the file.

I think it is worth to check if the files generated by the script are accesible for chrome. Try changing the permission of ff2mpv-windows-chrome.json and ff2mpv.bat to allow all users in the pc for read/write permissions.

I've checked the permissions of the two files.
System, Jose and Admins already had complete control.
I've added "Users" for both files, with complete control also:
2023 05 03 - 18 18 36

Then I've restarted Chrome. The outcome seems to be the same:
2023 05 03 - 18 17 35

Could you try to add the user everyone with full control and see if it helps?

You can also compare the permissions by looking at the output of the command Get-Acl in powershell.
For firefox it uses the file ff2mpv-windows.json (which is already provided) and for chrome a new json is created because it requires different keys.

You could try to copy the permissions from the ff2mpv-windows.json file to others to see if that helps:

Get-Acl -Path ./ff2mpv-windows.json | Set-Acl -Path ./ff2mpv-windows-chrome.json

As last resource you can try recreating the files manually in case some encoding error may be affecting the files. Just delete both ff2mpv.bat and ff2mpv-windows-chrome.json and create new files in notepad with this content:

ff2mpv.bay

@echo off
call python ff2mpv.py

ff2mpv-windows-chrome.json

{
    "name":  "ff2mpv",
    "description":  "ff2mpv's native manifest",
    "path":  "ff2mpv.bat",
    "type":  "stdio",
    "allowed_origins":  [
                            "chrome-extension://ephjcajbkgplkjmelpglennepbpmdpjg/"
                        ]
}

OK, first of all I'm sorry to be such a hassle, really :)

I've added the user everyone (Tous les utilisateurs in french) with full control, and restarted Chrome. Same issue.

I've added the user everyone to the full ff2mpv folder with full control, just in case, and restarted Chrome. Same issue.

I've copied the permissions with PowerShell:
2023 05 03 - 19 12 30
... and restarted Chrome. Same issue.

And lastly, I've deleted and recreated the two files manually, and restarted Chrome. And of course... same issue. :(
2023 05 03 - 19 15 29

I'm not sure this is a permissions problem. I think we're missing something. We can't start the native messaging host, but for what reason? Is there a more verbose way of debugging this?

Just taking a step back for a second: are you able to confirm that other native extensions work correctly in Chrome on Windows 7? It's possible that the feature as a whole is broken/slightly wonky on older Windows versions, since Chrome likely doesn't have automated tests for it.

I'm willing to perform any testing required. What native extensions are you talking about? Would you like a list of all my Chrome extensions to be sure? Or did I misunderstand?
2023 05 03 - 19 39 03

Would you like a list of all my Chrome extensions to be sure? Or did I misunderstand?

Nope, sorry for the confusion -- I was suggesting that you might want to try a different extension that uses native messaging (a lot of password manage extensions do, for example), and see if it's working.

(I don't actually know one off the top of my head, since I only use ff2mpv on Firefox and it's the only native messaging extension I use. But my guess is that 1Password and similar applications use it for their browser extensions.)

I agree with @woodruffw, I think the next step is verifying that native messaging hosts is working on chrome for windows 7.

@JoseHidalgo Some extensions like ff2mpv use the native messaging hosts to communicate with the native applications in the computer like in this case to send the url to mpv.

The only other extension I use that talks to a native application is KeepassXC browser. You could review this by opening the registry and looking at chrome's entries in HKEY_CURRENT_USER\Software\Google\Chrome\NativeMessagingHosts

Also for more logs in chrome you can launch it with the argument --enable-logging (E.g. C:\Program Files\Google\Chrome\Application\chrome.exe --enable-logging). More info.

Checked the registry. Seems to me that native messagings hosts are working on Chrome. I have four of them:
2023 05 03 - 21 44 16

I'll check the logs, gotta go now. :)

commented

Try it in other Chromium-based browsers, like Edge or Brave. Maybe that behaves differently.

@JoseHidalgo what I meant by checking the registry is to find other extensions that implement native messaging hosts. Could you confirm that the other extensions there are working? Do they interact with the native application (the application installed in windows)?

commented

I manage to get it to work on brave-browser (chromium based like google chrome) on Linux. The issue arises because chromium based browsers bundled their own libvulkan which is broken (on Linux?) #98

Not sure if the cause is the same on WIndows and if it is whether you can modify it to works on Windows as I haven't used Windows for years.

I've checked Chrome's log. Here's the error that lies within:

[12340:2828:0504/134906.320:ERROR:native_process_launcher_win.cc(191)] Failed to connect IO pipes when starting C:\Users\Jose\ff2mpv\ff2mpv.bat
[12340:3884:0504/134906.323:INFO:CONSOLE(2)] "Error: Failed to start native messaging host.", source: chrome-extension://ephjcajbkgplkjmelpglennepbpmdpjg/ff2mpv.js (2)

I can provide the whole log if needed, but that is the only mention of ff2mpv. Every time I click on the icon, a new mention is added to the log.

And yes, AFAIK my other apps using native messaging hosts work normally with Chrome (e.g. Dropbox).

Maybe it's library-based like @beew just said?

commented

Maybe chrome changes the PATH environment variable and the script can't find python.

commented

Maybe it's library-based like @beew just said?

That's unrelated. That's Linux specific.

Yesterday I looked at the issue pointed by @beew. What I understand from it is that starting mpv from a chrome process makes it inherit its environment which was overriding an important library for mpv and thus making it fail to play. I cannot say for sure but I've confirmed no issues on Windows 10 and 11 so if this were to be the case, it is a windows 7 only thing.

From the logs provided by @JoseHidalgo I see that the main issue is related to ff2mpv.bat and chrome being unable to connect to the named pipe. You can see the error message is generated in this file.

commented

@JoseHidalgo can you try other chromium based browsers like Brave or Edge?

I'll see what I can do. Give me a couple of days, we have guests staying at home. Will report back ASAP.

@eNV25 Reporting about my Win 7 system:

  • I have installed Brave + ff2mpv extension.
  • Been to YouTube, clicked on a video, then on ff2mpv icon.
  • Worked right away with Brave, no other setting needed.

So this issue seems to be Chrome-specific.

Given that this is a Chrome + Windows-specific bug, I'm going to triage this as a potential upstream issue.

@JoseHidalgo is your chrome perhaps a 32 bit version?

My Chrome is supposedly a 64-bit version...

2023 05 10 - 04 21 44

... but for unknown reasons it has been stored in C:\Program Files (x86)\Google\Chrome\Application\Chrome.exe

commented

Then try uninstalling it and installing it again, making sure to get the 64-bit version.

Wouldn't that make me lose all my settings, extensions, tabs, passwords and such?
Just wondering: uninstalling a browser is not something that I'm used to.

commented

Don't you have a Google account with data sync turned on? If so, everything should be restored if/when you reinstall.

OK, so I've safely synced / uninstalled / reinstalled Chrome 64-bit. Now it has found its proper place under Program Files.

Unfortunately the ff2mpv-related issue remains the same. Just checked the background info, same exact error.

Also, @woodruffw I think I have finally found the right syntax for subtitles:

  1. Directly in command line
    mpv {YouTube URL} --ytdl-raw-options=ignore-config=,sub-lang="en.*",write-sub=,write-auto-sub=

  2. Via mpv.conf

2.1. Put this in mpv.conf:

[youtube]
slang=en,eng,english
sub-auto=fuzzy
ytdl-raw-options=ignore-config=,sub-lang="en.*",write-sub=,write-auto-sub=

2.2. Call the now defined youtube profile in command line :
mpv {YouTube URL} --profile=youtube

Those two examples are valid for english subtitles. For other languages the relevant parts need to be adapted.

Feel free to add this to the wiki if you want.

Glad to hear you got it working! I'll add that tonight.

Yes, the subtitle part works, and ff2mpv itself works well on Firefox and Brave. Only Chrome's issue remains though.

I've just run Windows 7 in a virtual machine. The install script failed because some modules in powershell that the script expects are missing, so I proceded to install manually (add registry key, create ff2mpv.bat, create ff2mpv-windows-chrome.json). I got the extension working fine. See gif:

VirtualBoxVM_z9eAyThp3j

Programs:

  • mpv: 0.35.04
  • yt-dlp: 2023.03.04
  • powershell: 2.0.-1.-1
  • python: 3.7.8
  • chrome: 109.0.5414.120
  • windows 7 x64

@JoseHidalgo I think there must be something in your windows installation that is breaking the native messaging hosts for chrome.

Thanks Eduardo @DanSM-5 , noted.

Thankfully it doesn't bother me anymore, because thanks to the suggestions in this thread I have now officially switched to Brave Browser, so I don't use Chrome anymore. And I don't miss it one bit.

If the issue is something deep within my particular install of Win 7, then trying to find it is probably not worth it, since I'll be switching to Win 11 in a few months tops.

Thanks for all your efforts to find the issue!

I believe there's nothing left to be resolved here/nothing actionable on our part, so closing.