clisuite Documentation

Table of Contents

1. Index

1.1. GitHub repo / README: https://github.com/mitchellirmer/clisuite

2. Metube

Use this to stream music or videos from the internet, especially Youtube. Has a function to search Youtube via yt-dlp. Built on mpv, yt-dlp, sed, grep.

2.1. Source Code

2.1.1. Header stuff

I put these lines in my scripts so that I can grep the := to be reminded of what my scripts do.

# YouTube Search
# := CLI for searching YouTube.

2.1.2. Set up an internal path variable

This will be used to integrate speckify with metube and handle temp files generated while using this script.

path="$HOME/.clisuite/src/"
pl_loc="$HOME/Music/Stream/Playlists/"

2.1.3. Help menu

printHelp(){
    echo "========METUBE HELP=========="
    echo "metube <option> <argument(s)>"
    echo "EXAMPLE:  metube search \"nebraska football\" 5"
    echo "1)  < -s or search>  <\"search terms\">               <number of desired search results>"
    echo "2)  < -d or desc>    <line number of video title>"
    echo "3)  < -p or play>    <line number of video title>"
    echo "4)  < -a or add>     <line number of video title>   <\"Playlist_Title\">"
    echo "5)  < -c or copy>    <YouTube playlist URL>         <\"Local Title\">"
    echo "6)  < -e or export>  <\"Playlist_Title\">"
    echo "=============================="
}

2.1.4. Main program

if [ -z "$1" ]; then
    printHelp
elif [ $1 == "-s" ] || [ $1 == "search" ]; then
    rm ${path}ytreturn.txt
    yt-dlp --print title --print uploader --print webpage_url "ytsearch$3:$2" > ${path}ytreturn.txt
    sel=$(tac ${path}ytreturn.txt | fzf)
    mpv $sel
elif [ $1 == "-d" ] || [ $1 == "desc" ]; then
    declare line=$2
    line=$((${line} + 2))
    line="${line}p"
    track=$(sed -n $line ${path}ytreturn.txt)
    yt-dlp --print title --print uploader --print upload_date --print webpage_url --print description $track
elif [ $1 == "-p" ] || [ $1 == "play" ]; then
    declare line=$2
    line=$((${line} + 2))
    line="${line}p"
    track=$(sed -n $line ${path}ytreturn.txt)
    mpv $track
elif ( [ $1 == "-a" ] || [ $1 == "add" ] ) && [[ ! -z "$3" ]]; then
    declare line=$2
    address=$((${line} + 2))
    line="${line}p"
    address="${address}p"
    track=$(sed -n $line ${path}ytreturn.txt)
    url=$(sed -n $address ${path}ytreturn.txt)
    echo $track > ${path}tmptitle.txt
    echo $url > ${path}tmpurl.txt
    paste ${path}tmpurl.txt ${path}tmptitle.txt >> ${path}${3}.m3u
    rm ${path}tmptitle.txt ${path}tmpurl.txt
elif [ $1 == "-c" ] || [ $1 == "copy" ]; then
    id="$(echo $2 | cut -f2- -d=)"
    prefix='https://www.youtube.com/playlist?list='
    fullurl="${prefix}${id}"
    yt-dlp --print title --print webpage_url "$fullurl" > tempfile
    grep -e "http" tempfile > urls
    grep -v "http" tempfile > titles
    paste urls titles > "$3".m3u
    rm tempfile; rm urls; rm titles
elif [ $1 == "-e" ] || [ $1 == "export" ]; then
    cp -v -i ${path}${2}.m3u ${pl_loc}${2}.m3u
else
    printHelp
fi

2.2. License

2.2.1. GPL

A copy of the license is here.

3. Speckify

Use this to stream music from the internet or from playlist files containing file locations or URLs. Built on mpv, ytdlp, sed, grep.

3.1. Source Code

3.1.1. Header stuff

I put these lines in my scripts so that I can grep the := to be reminded of what my scripts do.

  # Speckify Music
  # := Searches all playlists in the folder; returns output to screen and out.m3u playlist.

3.1.2. Set up an internal path variable

This will be used to integrate speckify with metube and handle temp files generated while using this script.

path="$HOME/.clisuite/src/"
pl_loc="$HOME/Music/Stream/Playlists/"

3.1.3. Help menu

printHelp(){
    echo "========SPECKIFY HELP=========="
    echo "speckify <option> <argument(s)>"
    echo "EXAMPLE:  speckify search \"heads carolina\""
    echo "1)  < -s or search > <\"search terms\">"
    echo "2)  < -c or choose > <line number of track title>"
    echo "3)  < play >         <\"PlaylistName\">"
    echo "4)  < shuffle >      <\"PlaylistName\">"
    echo "5)  < library >"
    echo "=============================="
}

3.1.4. Main program

if [ -z "$1" ]; then
    printHelp
elif [ $1 == "-s" ] || [ $1 == "search" ]; then
    cd $pl_loc
    rm msearch.m3u
    grep -i "$2" *.m3u | cut -f2- -d: > msearch.m3u
    cat -n msearch.m3u
elif [ $1 == "-c" ] || [ $1 == "choose" ]; then
    cd $pl_loc
    line=$2
    line="${line}p"
    track=$(sed -n $line msearch.m3u)
    mpv --no-video $track
elif [ $1 == "play" ]; then
    cd $pl_loc
    list=$(ls *.m3u | cut -f1 -d. | fzf)
    mpv --no-video ${pl_loc}${list}.m3u
elif [ $1 == "shuffle" ]; then
    cd $pl_loc
    list=$(ls *.m3u | cut -f1 -d. | fzf)
    mpv --no-video --shuffle ${pl_loc}${list}.m3u
elif [ $1 == "library" ]; then
    cd $pl_loc
    ls *.m3u | cut -f1 -d. | more
else
    printHelp
fi

3.2. License

3.2.1. GPL

A copy of the license is here.

4. Readmode

4.1. Source code

4.1.1. Header stuff

The same header stuff I use to make it greppable

# Read Mode
# := Takes a URL as input and feeds it to Mozilla Readability.  Read in w3m.

4.1.2. Internal path for temp files

path="$HOME/.clisuite/src/"

4.1.3. Main program

Requires readability to be installed already. I used JS node.

curl $1 | readability $1 > ${path}readmodetempfile.html
w3m ${path}readmodetempfile.html

4.2. License

Mozilla readability has an Apache 2.0 license, found here. Metube Use this to stream music or videos from the internet, especially Youtube. Has a function to search Youtube via yt-dlp. Built on mpv, yt-dlp, sed, grep.

4.3. Source Code

5. pak

5.0.1. Header stuff

I put these lines in my scripts so that I can grep the := to be reminded of what my scripts do.

# Flatpak launcher
# := Faster way to start Flatpaks.

5.0.2. Set up an internal path variable

This will be used to integrate speckify with metube and handle temp files generated while using this script.

path="$HOME/.clisuite/src/"

5.0.3. Help menu

printHelp(){
    echo "========PAK HELP=========="
    echo "=============================="
}

5.0.4. Main program

# https://stackoverflow.com/questions/22727107/how-to-find-the-last-field-using-cut
if [ -z "$1" ]; then
    printHelp
else
    pak=$(flatpak list --columns application | grep -i -m 1 "$1")
    ts flatpak run $pak
fi

5.1. License

5.1.1. GPL

A copy of the license is here.

6. Dependencies

6.0.1. fzf

Fuzzy finder for command line lists, found here.

6.0.2. MPV

A lightweight, command-line video player available here.

6.0.3. yt-dlp

Command-line interface for interacting with YouTube and other video/audio hosted on https, available here.

6.0.4. readability

Mozilla readability for isolating body of HTML pages, installed from here.

7. Generate config file

alias metube='bash $HOME/.clisuite/src/metube.sh'  
alias readmode='bash $HOME/.clisuite/src/readmode.sh'  
alias speckify='bash $HOME/.clisuite/src/speckify.sh'
alias pak='bash $HOME/.clisuite/src/pak.sh'

8. Generate README.md

Command Line Suite
==================

GitHub Pages: https://mitchellirmer.github.io/clisuite/

# 0.  About
These are my personal scripts that I use to improve my user experience with streamed multi-media and written content.  They are stored here as a backup for me and reference for others that want to practice scripting for regular tasks.  Should you choose to download these, know that it is at your own risk and there is no warranty of any kind.

# 1. readmode   

readmode is a script intended to remove clutter from articles opened in newsboat or w3m/lynx.  It feeds a website URL through cURL and Mozilla readability and opens in w3m.  The idea comes from here: <https://tech.toryanderson.com/2021/06/09/how-to-get-readable-mode-in-emacs-w3m/>  I don't use EMACS (yet(?)) and so I made it a little simpler by writing this script, calling it with an alias in my .zshrc, and adding a macro to my .newsboat/config.  See dependencies.txt for a list of required dependencies, which you must install on your own before using readmode.sh.  

# 2. metube    

metube is a replacement for the youtube https website.  It uses yt-dlp -search:N to search youtube and display the results.  You can read video descriptions and play videos directly with metube commands.  Video playback comes from mpv.  metube "integrates" with speckify (see #3) as a tool to create playlists.  Instead of playing one video at a time from the results, you can use metube to save video URLs and titles to .m3u playlists and export them to the speckify playlist library to playback later.  

#  3. speckify  
speckify is a streaming library user interface.  It uses mpv --no-video to stream audio from youtube or other sources.  It reads in .m3u playlist files with URL and title and searches your "library" of URLs to stream what you want without having to search youtube or another source first.  

# 4. pak
pak launches flatpaks without needing to know the multipart application ID.
         
# 5.  Installation:

1. Save/clone into /home/user/.clisuite/  
2. Add the following to your .zshrc or .bashrc or whatever handles your aliases.  

> ####### include clisuite
>
> . /$HOME/.clisuite/src/config

3. To use readmode as a macro from newsboat, add this to your .newsboat/config  
> macro r set browser "sh $HOME/.clisuite/readmode.sh" ; open-in-browser ; set browser w3m/lynx/firefox
4. By default, speckify will save playlists to $HOME/Music/Stream/Playlists/  This can be changed by updating the "pl_loc" variable in the metube.sh and speckify.sh files.     

Author: Mitchell

Created: 2024-04-04 Thu 18:33

Validate