justfoolingaround / animdl

A highly efficient, fast, powerful and light-weight anime downloader and streamer for your favorite anime.
GNU General Public License v3.0
1.31k stars 107 forks source link

[Feature Request] Passing options to mpv #19

Closed shadow5013 closed 3 years ago

shadow5013 commented 3 years ago

It would be very useful to be able to pass options to mpv. For instance, it is possible to play video without x server with --vo=drm etc.

justfoolingaround commented 3 years ago

Added that option in the config. The new config for player would look like:

{
    "players": {
        "mpv": {
            "executable": "mpv",
            "opts": [],
        },   
    }
}
shadow5013 commented 3 years ago

It works. But it would be nice to also have something like --player-opts "options here" for temporary options.

justfoolingaround commented 3 years ago

Passing options, multiple at that, would be difficult with that method (for the user). The quotes would require to be escaped and it'd be a hassle anyway. In my opinion, modifying the config would be the only reasonable and simpler way.

shadow5013 commented 3 years ago

Firstly, the quotes wouldn't require to be escaped. Everything inside quotes will be passed as an argument of --player-opts. Quotes just preserve the literal value of each character. In other words, everything inside quotes is escaped. Here is the output of a test file where i echoed the arguments of player-opts

$ python cli.py --player-opts "--vo=gpu --gpu-context=drm"
--vo=gpu --gpu-context=drm
Code ```python import click @click.command() @click.option('--player-opts', help='player options.') def echo(player_opts): click.echo(player_opts) if __name__ == '__main__': echo() ```

You can just parse opts from configuration file, concatenate it with opts from --player-opts and then pass it to mpv.

Secondly, modifying the config file is fine for permanent options. But it'd rather be hassle for one-time options. Hope you can understand.

justfoolingaround commented 3 years ago

Alright, I've added the player-opts to stream. The format however is not --player-opts "--vo=gpu --gpu-context=drm", it is a much simpler --player-opts "--vo=gpu" "--gpu-context=drm" and yes, it is appended to the default args (args in the config of course.)

shadow5013 commented 3 years ago

There might be a problem with parsing.

$ ./animdl.py stream 'jujutsu' --player-opts "--speed=1.5" "--mute=yes"
░█████╗░███╗░░██╗██╗███╗░░░███╗██████╗░██╗░░░░░
██╔══██╗████╗░██║██║████╗░████║██╔══██╗██║░░░░░
███████║██╔██╗██║██║██╔████╔██║██║░░██║██║░░░░░
██╔══██║██║╚████║██║██║╚██╔╝██║██║░░██║██║░░░░░
██║░░██║██║░╚███║██║██║░╚═╝░██║██████╔╝███████╗
╚═╝░░╚═╝╚═╝░░╚══╝╚═╝╚═╝░░░░░╚═╝╚═════╝░╚══════╝v1.3.0
A highly efficient anime downloader and streamer

Usage: animdl.py stream [OPTIONS] QUERY
Try 'animdl.py stream --help' for help.

Error: no such option: --mute
justfoolingaround commented 3 years ago

So, the click.options with multiple works kinda differently than I thought. It works rather with

animdl.py stream 'jujutsu' --player-opts "--speed=1.5" --player-opts "--mute=yes"

than listing the commands one after other. This is a bit too weird. If you're fine with this, let me know or I'll just add a regex argument parser that does parsing through a single string.

shadow5013 commented 3 years ago

A single string would be more convenient.

justfoolingaround commented 3 years ago

Aight, done. (Just recalled that click has shlex.split, ignore the wrong referencing on the latest commit)

shadow5013 commented 3 years ago

Working correctly. Thank you.