Skip to content

Commit

Permalink
Merge pull request #77 from gmt4/master
Browse files Browse the repository at this point in the history
Pull Request from github.com/gmt4/mpvc tag 1.5-vinyl
  • Loading branch information
gmt4 authored Aug 19, 2024
2 parents 6cfb633 + f8da4cb commit 783a0dd
Show file tree
Hide file tree
Showing 16 changed files with 492 additions and 239 deletions.
33 changes: 22 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
![GitHub top language](https://img.shields.io/github/languages/top/lwilletts/mpvc)
![GitHub lines of Code](https://sloc.xyz/github/lwilletts/mpvc/?category=code)

# mpvc 🎧
# mpvc 🎧 [^install]

A terminal music player in POSIX sh(1) that interfaces mpv providing mpc(1) commands + extras.
Originally a fork of [lwillets/mpvc](https://github.com/lwilletts/mpvc) that evolved on its own, providing some extra goodies such as: improved CLI, TUI, FZF, WEB, EQ, & playing media from YouTube & streaming services.
Check the [Wiki](../../wiki), [LogBook](../../wiki#logbook) & [Casts](../../wiki#screencasts) for a detailed view of the extra features of this fork.

Skip directly to [Installation](#Installation) to try mpvc!

<details open>
<summary>mpvc-tui -T: running the mpvc TUI <i>(click to view screenshot)</i></summary>

Expand All @@ -18,24 +20,25 @@ Check the [Wiki](../../wiki), [LogBook](../../wiki#logbook) & [Casts](../../wiki

<details>
<summary>mpvc-fzf -f: running with fzf to manage the playlist <i>(click to view screenshot)</i></summary>

![mpvc-fzf screenshot](../../blob/master/docs/assets/mpvc-tui-arch.png)
</details>

<details>
<summary>mpvc-tui -n: running with mpvc-fzf and desktop notifications on the upper-right corner <i>(click to view screenshot)</i></summary>

![mpvc tui+fzf+notifications screenshot](../../blob/master/docs/assets/mpvc-tui-fzf.png)
</details>
</details>

## Overview ▶️
## Overview ▶️ [^install]

[mpvc](../../) player functionality is provided by:

- [mpvc](../../blob/master/mpvc): provides the mpvc player core CLI commands
- [extras/mpvc-tui](../../blob/master/extras/mpvc-tui): provides a console TUI, using mpvc underneath
- [extras/mpvc-fzf](../../blob/master/extras/mpvc-fzf): provides FZF integration to mpvc.
- [extras/mpvc-web](../../blob/master/extras/mpvc-web): a hack to remotely control mpvc from web (handy on mobile)
- [extras/mpvc-now](../../blob/master/extras/mpvc-now): generates a URL to share the current playlist
- [extras/mpvc-mpris](../../blob/master/extras/mpvc-mpris): speaks MPRIS to control mpv player through key-bindings.
- [extras/mpvc-equalizer](../../blob/master/extras/mpvc-equalizer): provides a basic mpv equalizer for the CLI.
- [extras/mpvc-autostart](../../blob/master/extras/mpvc-autostart): automatic mpv start/stop based on presence.
Expand All @@ -52,7 +55,7 @@ Required:
- `socat`: is preferred due to the differing implementations of `netcat` across UNIXes.
- `awk`: a sane version of `awk` for the same reason (`gawk` works)

Recommended extras:
Recommended extras:

- `curl`
- `fzf`
Expand All @@ -72,6 +75,8 @@ Check for missing dependencies using `mpvc-installer check-reqs`.
- [Gentoo](#gentoo-mpvc)
- [Nix](#nix-mpvc)

Installing is just a matter of fetching the scripts either via Git/Curl/etc., scripts can be used directly from the repo, the `mpvc-installer` bit is just there for easiness, to fetch & link them into your `BINDIR=~/bin/` by default,

### Manual

The easiest install method is just to run the [mpvc-installer](../../blob/master/extras/mpvc-installer) to install under `$HOME/bin`
Expand All @@ -83,11 +88,14 @@ curl -fsSL -o mpvc-installer https://github.com/lwilletts/mpvc/raw/master/extras

### Git

Below is a **Quick Start** guide showcasing mpvc commands usage.

```sh
# fetch a local copy of the github repo
git clone https://github.com/lwilletts/mpvc/
# use extras/mpvc-installer: just copy/link to your $HOME/bin
(cd mpvc; extras/mpvc-installer link-user)
(cd mpvc; extras/mpvc-installer check-reqs)

# use mpvc-fzf to search and play youtube media
mpvc-fzf -p 'kupla mirage'
Expand Down Expand Up @@ -121,27 +129,27 @@ pacman -Sy mpv gawk curl socat fzf rlwrap jq libnotify

### BSD

BSD (and pkg(1) based derivatives such as FreeBSD):
BSD (and pkg(1) based derivatives as FreeBSD, see [FAQ](../../wiki/FAQ)):

```console
pkg install -y mpv gawk curl socat fzf rlwrap jq libnotify
pkg install -y mpv curl socat fzf rlwrap jq libnotify # gawk gsed
```

### MacOS

MacOS (and brew(1) based derivatives see [FAQ](../../wiki/FAQ)):

```console
brew install gawk socat fzf rlwrap jq gnu-sed yt-dlp # mpv curl libnotify
brew install mpv curl socat fzf rlwrap jq libnotify yt-dlp # gawk gnu-sed
```

### Gentoo [mpvc](https://gitlab.com/xy2_/osman)

```console
emerge mpvc
```
```

### Nix [mpvc](http://github.com/nixos/nixpkgs/tree/master/pkgs/applications/misc/mpvc)
### Nix [mpvc](https://github.com/NixOS/nixpkgs/blob/master/pkgs/by-name/mp/mpvc/)

```console
nix-env -i mpvc
Expand Down Expand Up @@ -199,7 +207,7 @@ usage: mpvc-fzf -[01ab:cCd:efFg:G:hk:K:n:s:p:P:o:Or:lL:xv] args # @version v1.5

## Tricks

There's some basic tricks in [Git](#git) to get you started.
There's some basic tricks in [Git](#git) to get you started.
For more check the [LogBook](../../wiki#logbook).

This gives just a sneak peek on what's possible to manage mpv from the command-line, your best chances are to go play and have fun.
Expand All @@ -215,3 +223,6 @@ Like any piece of software, mpvc is not perfect:
all effort has been made to make mpvc as POSIX compliant as possible.

Check out the [Issue Tracker](../../issues) for further improvements to be made.

[^install]: Skip directly to [Installation](#Installation) to try mpvc

64 changes: 53 additions & 11 deletions docs/logbook.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ <h2 id="gmt4-mpvc-contents">Contents</h2>
<li> <a href="#logbook-20240301">#20240301 On support UNIXes besides GNU/Linux: BSD and MacOS</a></li>
<li> <a href="#logbook-20240405">#20240405 Introducing mpvc-chapter: helper managing chapters, 5 Apr 2024</a></li>
<li> <a href="#logbook-20240505">#20240505 Introducing mpvc-osd: interfacing mpvc with a 4x20 USB LCD, 5 May 2024</a></li>
<li> <a href="#logbook-20240704">#20240704 Some notes on my current mpvc setup, 4 July 2024</a></li>
</ul>

<hr />
Expand Down Expand Up @@ -389,6 +390,7 @@ <h3 id="logbook-20230721">Introducing mpvc-web: a mpvc-tui like hack for the web
alias mcI="mpvc chapter-list-full"
alias me="mpvc-equalizer"
alias mtt="mpvc-tui"
alias mtth="mpvc-tui -H"
alias mm="mpvc-mpris"
alias mw="mpvc-web"
alias mff="mpvc-fzf" # fzf on mpvc
Expand All @@ -405,7 +407,8 @@ <h3 id="logbook-20230721">Introducing mpvc-web: a mpvc-tui like hack for the web
alias mffo="mpvc-fzf -o" # fzf search and return first ytid URL
alias mffp="mpvc-fzf -p" # fzf search and add ytid URLs from Invidious
alias xargn="xargs -n1" # xargn mpvc cmd
rseq() { seq "$@" | tac; } # rseq | xargn mpvc cmd
rseq() { seq "$@" | tac; } # rseq | xargn mpvc cmd
mffo1() { mpvc add $(mpvc-fzf -o "$@" | mpvc-fzf -1); }
</pre>
</p>

Expand Down Expand Up @@ -542,20 +545,20 @@ <h3 id="logbook-20231117">On the security of mpvc-web, 17 Nov 2023</h3>
So, now the following alternatives are available, ordered from less to more secure:
<ol>
<li>
For local purposes, just run mpvc-web that defaults to `localhost` with: `mpvc-web`.
For local purposes, just run mpvc-web that defaults to `localhost` with: `mpvc-web`.
</li>
<li>
If its safe running plain HTTP on the home LAN, then use: `MPVC_WEB_HOST=0 mpvc-web`.
If its safe running plain HTTP on the home LAN, then use: `MPVC_WEB_HOST=0 mpvc-web`.
</li>
<li>
Otherwise, if its not safe for running plain HTTP on the LAN, then use:
`MPVC_WEB_HOST=0 MPVC_WEB_SSL_ENABLE=1 mpvc-web` to require HTTPS.
Otherwise, if its not safe for running plain HTTP on the LAN, then use:
`MPVC_WEB_HOST=0 MPVC_WEB_SSL_ENABLE=1 mpvc-web` to require HTTPS.
</li>
<li>
If additionally, the environment can get attacks from malicious users, then
require the use of peer certificates, therefore, limiting access only to those
clients/peers that have present valid `stunnel(1)` certificate with:
`MPVC_WEB_HOST=0 MPVC_WEB_SSL_ENABLE=1 MPVC_WEB_SSL_VERIFY=2 mpvc-web`
If additionally, the environment can get attacks from malicious users, then
require the use of peer certificates, therefore, limiting access only to those
clients/peers that have present valid `stunnel(1)` certificate with:
`MPVC_WEB_HOST=0 MPVC_WEB_SSL_ENABLE=1 MPVC_WEB_SSL_VERIFY=2 mpvc-web`
</li>
</ol>
</p>
Expand Down Expand Up @@ -645,15 +648,54 @@ <h3 id="logbook-20240505">Introducing mpvc-osd: interfacing mpvc with a 4x20 USB
mpvc-tui -S 'echo $(date +"T%H:%M") $(mpvc -f "[%status%] #%position%/%playlistlength% %time% %artist% - %title% - %path%")' 'false'
</pre>
And this is how it looks:
<img src="assets/mpvc-osd-usblcd.jpg" alt="mpvc-osd usblcd" width="95%" />
<p style="text-align:center">
<img src="assets/mpvc-osd-usblcd.jpg" alt="mpvc-osd usblcd" width="90%" />
</p>
</p>

<h3 id="logbook-20240704">Some notes on my current mpvc setup, 4 July 2024</h3>
<p>

Some notes on my current mpvc setup, I've setled on having the following commands continuosly running on background: mpvc-tui, mpvc-web, mpvc-autostart, and mpvc-osd:

<ul>
<li>
mpvc-tui: to manage from the CLI, with the -T option to get desktop notifications.
</li>
<li>
mpvc-web: to manage from the WEB, to access from any browser in the LAN.
</li>
<li>
mpvc-autostart: to automatically start/stop mpvc when a personal device is detected (LAN).
</li>
<li>
mpvc-osd: to have mpvc playing status updated on a USB LCD (see above entry)
</li>
</ul>

For the record, this is the list of commands currently running:

<pre>
mpvc-tui -T
mpvc-web -b 0 -s 1 -a 1 -R 60 -t dark -c start
mpvc-autostart -p 600 -n 6 -i [local_ip]
# mpvc-osd mpvcosd
</pre>

Using mpvc-web, on a device with a HDMI display, opens news possibilities of displaying video media, that is beyond just acting as a jukebox for playing music.
For setups where the mediacenter has a video display with X11 x2x(1) might come handy to send X11 input events from a ssh-client to control the remote mpv running on X11, an example invocation is:
<pre>
ssh -X $USER@$HOST x2x -west -to :0 # be sure to read x2x(1)
</pre>

</p>

<!-- SOF -->

<hr/>
<p>
<span>
<em>Last-Modified: Sunday, 5 May 2024 by <a href="https://gmt4.github.io">gmt4</a></em>
<em>Last-Modified: Thursday, 4 July 2024 by <a href="https://gmt4.github.io">gmt4</a></em>
</span>
<span style="float: right;">
<em>Powered by #HTML 🧡 💚 💙 </em>
Expand Down
7 changes: 6 additions & 1 deletion docs/now/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ <h1 id="mpvc-fork">
<h2 id="mpvc-now-listening">
<a href="">Now Listening</a>
</h2>

<div id="container" class="container">
</div>

Expand All @@ -81,17 +82,21 @@ <h2>Scrobbling Code</h2>
const urlp = new URL(window.location.href).searchParams
const dflt = [ 'ssDzysKLlpY', '667dtK7O89k', 'mEkZbWYUego', 'UzRFQ6pDqhk', '_nl3Oo4-IQ4', 'ypAIWyH13aM', 'Jls9wXOSjl4', 'Hwg7hJrDiRg', '6FJ7F6trvBc' ]
const vids = urlp.getAll('v').length > 0 ? urlp.getAll('v') : dflt
const autoplay = urlp.getAll('autoplay').length > 0 ? 1 : 0
const loop = urlp.getAll('loop').length > 0 ? 1 : 0
const cont = document.getElementById('container')
const pre = document.getElementById('pre')
pre.innerHTML = '\n'

for(i in vids)
{
if (/^([-_a-zA-Z0-9]{11})$/.test(vids[i]))
{
const video = vids[i]
const url='https://www.youtube.com/watch?v='+video+'\n'
const emb='https://www.youtube.com/embed/'+video
const html='<iframe src="'+emb+'" frameborder="0" allowfullscreen=""></iframe>'
const att='?autoplay='+( autoplay ? i == 0 : 0)+'&loop='+( loop ? 1 : 0 )
const html='<iframe src="'+emb+att+'" loading="lazy" frameborder="0" allowfullscreen="" allow="autoplay"></iframe>'
const node = document.createElement('div')

node.setAttribute('class', 'item')
Expand Down
5 changes: 3 additions & 2 deletions extras/mpvc-autostart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# @description mpvc auto pause/resume audio based on device presence
# @author gmt4 <gmt4 at github.com> (c) Copyright 2022 GPLv2+
# @url github.com/gmt4/mpvc
# SPDX-License-Identifier: GPL-2.0-or-later
#

PROGNAME=${0##*/}
Expand All @@ -18,7 +19,7 @@ mpvc_defaults()
ARGS=${ARGS:-}
}

mpvc_pingcheck() { ping -w 5 -c 5 "$@" | awk 'NR == 2 && /time=/ { sub(":.*time=",": time="); print }'; }
mpvc_pingcheck() { ping -c 5 "$@" | awk 'NR == 2 && /time=/ { sub(":.*time=",": time="); print }'; }
mpvc_btcheck() { hcitool scan | awk "/$@/ {print}"; }

# monitor presence of your phone (eg LAN IP/BT): if device is present resume audio, otherwise, pause audio.
Expand All @@ -45,7 +46,7 @@ mpvc_autoscan()
[ "$ncheck" -gt 0 ] && mpvc -q resume # n>0 pings up: resume
[ "$ncheck" -le -$NCHECK ] && mpvc -q pause # n<0 pings down: pause
fi
echo "# $(date -Imin) PERIOD=$PERIOD NCHECK=$NCHECK pause=$pause c=${#check} n=${ncheck} $check" # $@
echo "# $(date) PERIOD=$PERIOD NCHECK=$NCHECK pause=$pause c=${#check} n=${ncheck} $check" # $@
done
}

Expand Down
1 change: 1 addition & 0 deletions extras/mpvc-chapter
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# @description mpvc chapter helper utils (see mpvc chapter-list instead)
# @author gmt4 <gmt4 at github.com> (c) Copyright 2022 GPLv2+
# @url github.com/gmt4/mpvc
# SPDX-License-Identifier: GPL-2.0-or-later
#

PROGNAME=${0##*/}
Expand Down
41 changes: 35 additions & 6 deletions extras/mpvc-cut
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# @description mpvc cuts playing media between ab-loop points (idea from lwillets)
# @author gmt4 <gmt4 at github.com> (c) Copyright 2022 GPLv2+
# @url github.com/gmt4/mpvc
# SPDX-License-Identifier: GPL-2.0-or-later
#

PROGNAME=${0##*/}
Expand Down Expand Up @@ -51,6 +52,35 @@ mpvc_cutfile()
esac
}

mpvc_cut()
{
mpvc_cutfile "$operation" "$(mpvc g 'path')" "$(mpvc g 'ab-loop-a')" "$(mpvc g 'ab-loop-b')"
}

mpvc_screencast()
{
vres=$(xrandr | awk '
/^Screen 0: .* current .*/ {
r=$0; sub("^.* current ","",r); sub(", maximum .*$","",r); gsub(" ","",r); print r; exit
}'
)

asrc=$(pactl list sources | awk '
/^Source #.*/ {
s=$2; sub("#","",s);} / *Description: Monitor of Built-in Audio Analog Stereo/ {print s; exit
}'
)

fout="${fout:-mpvc-cast-$(date -Isec | sed 's/:/-/g').mkv}"
loglevel=${loglevel:-warning}
framerate=${framerate:-25}

if [ -z "$vres" ]; then usage; fi
if [ -z "$asrc" ]; then usage; fi

echo "# $PROGNAME: recording vres $vres asrc $asrc to $fout (ctl+c to finish)"
ffmpeg -hide_banner -loglevel "$loglevel" -video_size "$vres" -framerate "$framerate" -f x11grab -i :0.0 -f pulse -ac 2 -i "$asrc" "$fout"
}
usage()
{
echo "usage: $PROGNAME -[vdlLh] args # @version $PROGVERSION (c) $PROGAUTHOR $PROGURL"
Expand All @@ -63,14 +93,13 @@ main()

case "${1:-}" in
-h|--help|help) usage ;;
-l|--lossy|lossy) operation="lossy" ;;
-L|--lossless|lossless) operation="lossless" ;;
-v|--vidcord|vidcord) operation="vidcord" ;;
-d|--default|default|'') operation="default" ;;
-l|--lossy|lossy) operation="lossy" mpvc_cut ;;
-L|--lossless|lossless) operation="lossless" mpvc_cut ;;
-v|--vidcord|vidcord) operation="vidcord" mpvc_cut ;;
-d|--default|default|'') operation="default" mpvc_cut ;;
cast) mpvc_screencast "$@" ;;
*) usage ;;
esac

mpvc_cutfile "$operation" "$(mpvc g 'path')" "$(mpvc g 'ab-loop-a')" "$(mpvc g 'ab-loop-b')"
}

main "$@"
Loading

0 comments on commit 783a0dd

Please sign in to comment.