Sample Header Ad - 728x90

ksh88 string substitution in alias | mpv streaming

0 votes
1 answer
95 views
**tl;dr** how can I substitute a string (i.e. a youtube/streaming url) in an alias such as alias mpvyt='yt-dlp -o - | mpv - ' ? I live in a mezzanine studio using a M1 macbook for a workstation (writing/editing) and my old laptop with openbsd as a local server. I play music from that *obsd* server upstairs, which thus fills the whole room down to my desktop through the plugged-in speakers. My hosted library plays fine with [mpd](https://openports.pl/path/audio/mpd) and [ncmpcpp](https://formulae.brew.sh/formula/ncmpcpp) , and I just figured out it's not so difficult to [use mpv to play streamed youtube videos](https://www.reddit.com/r/mpv/comments/opoorx/comment/j7exh1n/) , since firefox in [XQuartz](https://www.xquartz.org/) streaming from [xenocara](https://xenocara.org/) is way too slow anyhow. I use a variety of different alias**\[1\]** as shortcuts to frequent commands, and [understand](http://sylvain.sab.free.fr/cestquoi/) [the basics of programming](http://sylvain.sab.free.fr/cestquoi/programmation/) but am an absolute beginner when it comes to [shell/ksh88 syntax](https://man.openbsd.org/ksh) . I would like to use a short command for streaming youtube videos from the obsd server which I connect to using ssh. The following : yt-dlp -o - | mpv - -force-seekable=yes works well but **how can I do something like alias mpvyt='yt-dlp %s -o - | mpv -' ** so that I don't have to type the full command ? I suppose it involves a **basic string substitution using the** **ksh88** **syntax** which I am clueless about ... **or** perhaps I need to go as “far” as to use **a little standalone shell script a.k.a snippet ?** To go further, a great bonus would be if I could stream playlists, as well as separate the video and audio streams so I can play the video on the workstation screen, I will look into the [mpv documentation](https://mpv.io/manual/) for this. **\[1\]** (you may skip this irrelevant block of code, I just copy-pasted my terminal output to brag about my network and aliases) Last login: Tue Oct 31 06:54:34 on ttys002 sylvain@sylvainmac ~ % more /etc/hosts ## # Host Database # # localhost is used to configure the loopback interface # when the system is booting. Do not change this entry. ## 127.0.0.1 localhost 255.255.255.255 broadcasthost ::1 localhost #192.168.1.254 box 192.168.1.1 srv #192.168.1.11 lap 192.168.1.21 mac 192.168.1.51 droid sylvain@sylvainmac ~ % grep alias .zprofile alias u='brew update && brew upgrade ; sudo port selfupdate && sudo port upgrade outdated' #update command alias z='ncmpcpp' alias srvsh='ssh sylvain@srv' alias srvx='ssh -X sylvain@srv' #used from xquartz, deprecated alias srvm='sshfs sylvain@srv: ~/srv' alias sic='sic -n sylvainsab' alias l='ls' alias la='ls -a' alias ll='ls -l' alias lla='ls -la' sylvain@sylvainmac ~ % srvsh sylvain@srv password: Last login: Tue Oct 31 06:56:06 2023 from 192.168.1.21 OpenBSD 7.4 (GENERIC.MP) #0: Sun Oct 22 12:13:42 MDT 2023 Welcome to OpenBSD: The proactively secure Unix-like operating system. Please use the sendbug(1) utility to report bugs in the system. Before reporting a bug, please try to reproduce it with the latest version of the code. With bug reports, please try to ensure that enough information to reproduce the problem is enclosed, and if a known fix for it exists, include that as well. $grep alias .kshrc alias l='ls -F' alias ll='ls -l' alias la='ls -a' alias lla='ls -Al' alias t='tmux attach' alias z='ncmpcpp' alias fxr='firefox-esr -P remote &' #used with xquartz, deprecated alias n='doas umount /mnt' alias u='doas pkg_add -Uu && doas syspatch && doas fw_update' #update command alias macm='doas sshfs -o idmap=user,allow_other,uid=1000,gid=1000 sylvain@mac: ~/mac' alias rmds='find . -iname *.DS_Store -exec rm {} \;' alias mic_on='doas sysctl kern.audio.record=1' alias mic_off='doas sysctl kern.audio.record=0' alias cam_on='doas sysctl kern.video.record=1' alias cam_off='doas sysctl kern.video.record=0' alias ytdl='yt-dlp --prefer-free-formats -f bestvideo+bestaudio --audio-quality 0 -o "%(title)s-%(id)s.%(ext)s"' $^D Connection to srv closed. sylvain@sylvainmac ~ % Saving session... ...copying shared history... ...saving history...truncating history files... ...completed. [Opération terminée]
Asked by sylvansab (109 rep)
Oct 31, 2023, 06:29 AM
Last activity: Oct 31, 2023, 07:40 AM