~phate/rsmpv

9217b7636b0c77daa6909d26c69ab670c72338e4 — ValleyKnight 2 years ago
init commit
6 files changed, 312 insertions(+), 0 deletions(-)

A .gitignore
A Cargo.lock
A Cargo.toml
A NON-LICENSE.md
A README.md
A src/main.rs
A  => .gitignore +1 -0
@@ 1,1 @@
/target

A  => Cargo.lock +169 -0
@@ 1,169 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "ansi_term"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
dependencies = [
 "winapi",
]

[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [
 "hermit-abi",
 "libc",
 "winapi",
]

[[package]]
name = "bitflags"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"

[[package]]
name = "cfg-if"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"

[[package]]
name = "clap"
version = "2.33.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002"
dependencies = [
 "ansi_term",
 "atty",
 "bitflags",
 "strsim",
 "textwrap",
 "unicode-width",
 "vec_map",
]

[[package]]
name = "hermit-abi"
version = "0.1.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5aca5565f760fb5b220e499d72710ed156fdb74e631659e99377d9ebfbd13ae8"
dependencies = [
 "libc",
]

[[package]]
name = "itoa"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6"

[[package]]
name = "libc"
version = "0.2.79"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2448f6066e80e3bfc792e9c98bf705b4b0fc6e8ef5b43e5889aff0eaa9c58743"

[[package]]
name = "log"
version = "0.4.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b"
dependencies = [
 "cfg-if",
]

[[package]]
name = "mpvipc"
version = "1.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d730ce4d390da222bd5f9e37ce23744a092f19af86d7e7698d1ec03bf19a2ab5"
dependencies = [
 "log",
 "serde",
 "serde_json",
]

[[package]]
name = "rsmpv"
version = "0.1.0"
dependencies = [
 "clap",
 "mpvipc",
]

[[package]]
name = "ryu"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"

[[package]]
name = "serde"
version = "1.0.116"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96fe57af81d28386a513cbc6858332abc6117cfdb5999647c6444b8f43a370a5"

[[package]]
name = "serde_json"
version = "1.0.58"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a230ea9107ca2220eea9d46de97eddcb04cd00e92d13dda78e478dd33fa82bd4"
dependencies = [
 "itoa",
 "ryu",
 "serde",
]

[[package]]
name = "strsim"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"

[[package]]
name = "textwrap"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
dependencies = [
 "unicode-width",
]

[[package]]
name = "unicode-width"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3"

[[package]]
name = "vec_map"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"

[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
 "winapi-i686-pc-windows-gnu",
 "winapi-x86_64-pc-windows-gnu",
]

[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"

[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

A  => Cargo.toml +11 -0
@@ 1,11 @@
[package]
name = "rsmpv"
version = "0.1.0"
authors = ["Ash <valleyknight@protonmail.com>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = "2.33.3"
mpvipc = "1.1.8"
\ No newline at end of file

A  => NON-LICENSE.md +3 -0
@@ 1,3 @@
Anybody, is allowed to do anything, with ~~this software~~ these files.

*Any and all copyright restrictions are hereby revoked.*

A  => README.md +61 -0
@@ 1,61 @@
## Configuration
Requires either the flag `--input-ipc-server=/tmp/mpvsocket` to be passed at mpv runtime,<br>
or for this line `input-ipc-server=/tmp/mpvsocket` to be present in your `$HOME/.config/mpv/mpv.conf`.

## Help
`$ rsmpv -h`
```
rsmpv 0.0.1

A controller for mpv written in Rust, requires ipc to be enabled in mpv.

USAGE:
    rsmpv [SUBCOMMAND]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

SUBCOMMANDS:
    clear     Clear the current playlist in mpv
    help      Prints this message or the help of the given subcommand(s)
    set       Set different options for mpv
    toggle    Toggle various settings in mpv
```

`$ rsmpv set -h`
```
rsmpv-set 
Set different options for mpv

USAGE:
    rsmpv set [OPTIONS]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -l, --loop <y/n>               Enable or disable playback looping
    -p, --position <PERCENTAGE>    Set the position of media playback progress
    -v, --volume <PERCENTAGE>      Set the volume
```

`$ rsmpv toggle -h`
```
rsmpv-toggle
Toggle various settings in mpv

USAGE:
    rsmpv toggle [FLAGS]

FLAGS:
    -h, --help         Prints help information
    -s, --state        Pause/play mpv
    -S, --subtitles    Enable/disable visibility of subtitles
    -V, --version      Prints version information
```

## Roadmap
Nothing really, just adding features as I want. If anyone wants anything,<br>
let me know and I'll probably be more than happy to implement whatever.

A  => src/main.rs +67 -0
@@ 1,67 @@
use clap::{App, Arg, SubCommand};
use mpvipc::{ipc::run_mpv_command, Mpv};

fn main() {
    let matches = App::new("rsmpv")
        .version("0.0.1")
        .about("\nA controller for mpv written in Rust, requires ipc to be enabled in mpv.")
        .subcommand(SubCommand::with_name("clear")
            .about("Clear the current playlist in mpv"))
        .subcommand(SubCommand::with_name("set")
            .about("Set different options for mpv")
            .arg(Arg::with_name("loop")
                .short("l")
                .long("loop")
                .help("Enable or disable playback looping")
                .value_name("y/n")
                .takes_value(true))
            .arg(Arg::with_name("position")
                .short("p")
                .long("position")
                .help("Set the position of media playback progress")
                .value_name("PERCENTAGE")
                .takes_value(true))
            .arg(Arg::with_name("volume")
                .short("v")
                .long("volume")
                .help("Set the volume")
                .value_name("PERCENTAGE")
                .takes_value(true)))
        .subcommand(SubCommand::with_name("toggle")
            .about("Toggle various settings in mpv")
            .arg(Arg::with_name("state")
                .short("s")
                .long("state")
                .help("Pause/play mpv"))
            .arg(Arg::with_name("subtitles")
                .short("S")
                .long("subtitles")
                .help("Enable/disable visibility of subtitles")))
        .get_matches();
    let mpv = Mpv::connect("/tmp/mpvsocket").unwrap();
    if matches.is_present("clear") {
        run_mpv_command(&mpv, "clear-playlist", &[""])
            .expect("Could not play mpv, are you sure that the ipc-server is set to /tmp/mpvsocket?");
    } else if let Some(matches) = matches.subcommand_matches("set") {
        if matches.is_present("loop") {
            let mut arg = matches.value_of("loop").unwrap().replace("n", "no");
            arg = arg.replace("y", "inf");
            run_mpv_command(&mpv, "set_property", &["loop-file", &arg])
                .expect("Could not set the loopback property.");
        } else if matches.is_present("position") {
            run_mpv_command(&mpv, "set_property", &["percent-pos", matches.value_of("position").unwrap()])
                .expect("Could not set the position, are you sure you used a valid percentage?");
        } else if matches.is_present("volume") {
            run_mpv_command(&mpv, "set_property", &["volume", matches.value_of("volume").unwrap()])
                .expect("Could not set the volume, are you sure you used a valid percentage?");
        }
    } else if let Some(matches) = matches.subcommand_matches("toggle") {
        if matches.is_present("state") {
            run_mpv_command(&mpv, "cycle", &["pause"])
                .expect("Could not pause/play mpv, are you sure that the ipc-server is set to /tmp/mpvsocket?");
        } else if matches.is_present("subtitles") {
            run_mpv_command(&mpv, "cycle", &["sub-visibility"])
                .expect("Could not enable/disable subtitle visibility, are you sure that the ipc-server is set to /tmp/mpvsocket?");
        }
    }
}