stabbedbybrick / freevine

A Download Utility for Free Streaming Services
MIT License
170 stars 30 forks source link

"Place required tools inside Freevine folder" doesn't work #72

Open simonbcn opened 8 months ago

simonbcn commented 8 months ago
Arch Linux
Python 3.11.7
freevine git master

I have downloaded the latest version of hola-proxy and put it in the same folder as freevine.py, but freevine does not find it:

$ python freevine.py get --proxy es -t https://pluto.tv/es/on-demand/movies/655cca2a1d1d8e00135ef27e

❯_freevine v1.1.7

10:21:30.637 INFO : PlutoTV
10:21:30.641 INFO : + Adding Hola proxy location: ES
Traceback (most recent call last):
  File "/multimedia2/scripts-descarga/freevine/freevine.py", line 15, in <module>
    cli()
  File "/multimedia2/scripts-descarga/freevine/.freevine-env/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/multimedia2/scripts-descarga/freevine/.freevine-env/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/multimedia2/scripts-descarga/freevine/.freevine-env/lib/python3.11/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/multimedia2/scripts-descarga/freevine/.freevine-env/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/multimedia2/scripts-descarga/freevine/.freevine-env/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/multimedia2/scripts-descarga/freevine/utils/commands.py", line 90, in get
    Service(config, **kwargs)
  File "/multimedia2/scripts-descarga/freevine/services/pluto/pluto.py", line 50, in __init__
    super().__init__(config, **kwargs)
  File "/multimedia2/scripts-descarga/freevine/utils/config.py", line 118, in __init__
    uri = get_proxy(cli=self)
          ^^^^^^^^^^^^^^^^^^^
  File "/multimedia2/scripts-descarga/freevine/utils/proxies.py", line 154, in get_proxy
    hola = Hola()
           ^^^^^^
  File "/multimedia2/scripts-descarga/freevine/utils/proxies.py", line 76, in __init__
    raise ValueError(
ValueError: Required hola-proxy executable was not found on your system

The problem is get_binary function in utilities.py. shutil.which just looks for that program in some of the system's PATH folders but not in freevine folder.

PlaceboPRS commented 8 months ago

Have you renamed it to hola-proxy.exe ?

simonbcn commented 8 months ago

Have you renamed it to hola-proxy.exe ?

It's on Linux, not Windows.

PlaceboPRS commented 8 months ago

Have you renamed it to hola-proxy.exe ?

It's on Linux, not Windows.

Apologies missed that part...

stabbedbybrick commented 8 months ago

Shutil just checks if the program can be called, which means that it works for both current working directory (freevine) and system PATH. The name of the file should be hola-proxy in order to be easily found on any system. If you're on linux, you'll also need to make the file executable with chmod +x. I assume you know this already, but it's worth mentioning anyway.

simonbcn commented 8 months ago

Shutil just checks if the program can be called, which means that it works for both current working directory (freevine) and system PATH.

Sorry, but this is not true. See the python info about this command: https://docs.python.org/3/library/shutil.html#shutil.which

$ python
Python 3.11.7 (main, Dec  8 2023, 08:53:52) [GCC 13.2.1 20231110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os, shutil
>>> shutil.which('hola-proxy')
>>> shutil.which('python')
'/usr/bin/python'
>>> os.getcwd()
'/multimedia2/scripts-descarga/freevine'
>>> os.environ
environ({'PWD': '/home/juan/scripts-descarga/freevine', 'MANPAGER': "sh -c 'col -bx | bat -l man -p'", 'LC_TIME': 'da_DK.UTF-8', 'LC_PAPER': 'da_DK.UTF-8', 'LC_IDENTIFICATION': 'da_DK.UTF-8', 'LC_TELEPHONE': 'da_DK.UTF-8', 'LC_ADDRESS': 'da_DK.UTF-8', 'LANG': 'es_ES.UTF-8', 'XDG_RUNTIME_DIR': '/run/user/1000', 'DBUS_SESSION_BUS_ADDRESS': 'unix:path=/run/user/1000/bus', 'MANROFFOPT': '-c', 'SSH_CONNECTION': '192.168.1.5 49298 192.168.1.3 22', 'SHLVL': '1', '_tide_color_separator_same_color': '\x1b[38;5;246m', 'PATH': '/home/juan/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl', 'USER': 'juan', 'SUDO_EDITOR': 'micro', 'LOGNAME': 'juan', 'EDITOR': 'micro', 'QT_QPA_PLATFORMTHEME': 'qt5ct', 'SHELL': '/bin/fish', '_tide_location_color': '\x1b[38;5;76m', 'XDG_SESSION_ID': '5', 'LC_MONETARY': 'da_DK.UTF-8', 'SSH_CLIENT': '192.168.1.5 49298 22', 'XDG_SESSION_CLASS': 'user', 'MAIL': '/var/spool/mail/juan', 'HOME': '/home/juan', 'SSH_TTY': '/dev/pts/1', 'MICRO_TRUECOLOR': '1', 'TERM': 'xterm-256color', 'LC_MEASUREMENT': 'da_DK.UTF-8', 'XDG_SESSION_TYPE': 'tty', 'VIRTUAL_ENV_DISABLE_PROMPT': '1', 'MOTD_SHOWN': 'pam', 'LC_NAME': 'da_DK.UTF-8', 'LC_NUMERIC': 'da_DK.UTF-8'})
$ file hola-proxy
hola-proxy: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, Go BuildID=BteXhjX4jNL3_rcjY9GX/MKdJONoPUcMo-m0swW50/qQpT_KaNqYJDUq_j4qCW/S1JyoTmKgZ7AweL_aNwP, 
stripped

$ ls -lh
Permissions Size User Date Modified Name
.rw-r--r--  2,2k 1000  3 feb 10:21  config.yaml
.rw-r--r--   238 1000  3 feb 09:41  freevine.py
.rwxr-xr-x   10M 1000 26 dec  2023  hola-proxy
.rw-r--r--  1,1k 1000  3 feb 09:41  LICENSE
.rw-r--r--  6,8k 1000  3 feb 09:41  README.md
.rw-r--r--   149 1000  3 feb 09:41  requirements.txt
drwxr-xr-x     - 1000  3 feb 09:41  services
.rw-r--r--   627 1000  3 feb 09:41  supportedsites.md
drwxr-xr-x     - 1000  3 feb 09:41  update
drwxr-xr-x     - 1000  3 feb 10:00  utils
stabbedbybrick commented 8 months ago

Shutil just checks if the program can be called, which means that it works for both current working directory (freevine) and system PATH.

Sorry, but this is not true. See the python info about this command: https://docs.python.org/3/library/shutil.html#shutil.which

Yes, it's true. But apparently Unix systems can't handle it and do require it to be in PATH. On Windows it works as expected.

>>> shutil.which("hola-proxy")
'.\\hola-proxy.EXE'

But as mentioned in the instructions, having everything in PATH is the recommended method no matter what system you're using. Just put them in the proper place and things should work just fine.

simonbcn commented 8 months ago

In Windows it works because that OS automatically adds the current directory to the PATH when you try to run something. However in Linux, for security, it does not add anything to PATH automatically. You have to explicitly tell it the path if the executable is not in any of the folders in PATH.

I think a better way to get the path to the executable on any OS would be:

def get_binary(*names: str) -> Path:
    for name in names:
        path = shutil.which(name)
        if path:
            return Path(path)
        else:
           try:
            return Path(name).resolve(strict=True)
           except:
            return None
BobHasNoSoul commented 8 months ago

i use ubuntu with freevine an the workaround i did was add it to the global folder for binaries that is called

sudo cp NameOfBinaryHere /usr/bin/

then chmod +x the binary and freevine can find it by calling it with just the binary name

simonbcn commented 8 months ago

@BobHasNoSoul I know that, thanks anyway. In any case, the project documentation should be changed to indicate that the executables have to be all accessible in any of the system PATH folders or the function in question is modified (I have already put the solution, it is only 4 lines of code).

By the way, although it is not relevant, yesterday I tried this application to download something from PlutoTV and I think it is very good and very complete. Thanks for your work.