A Bash/Python script for watching your latest video feeds from your TinyTinyRSS instance using mpv.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

112 lines
4.0 KiB

#!/usr/bin/env bash
# December 2020
# Taha Ahmed
### EDIT THESE VARIABLES WITH YOUR SETTINGS
# set URL to your TTRSS instance
ttrss_url="https://tinytinyrss.yourdomain.se"
# set your TTRSS username
ttrss_usr="your-username"
### OPTIONALLY, DEFINE THE PATH TO YOUR PASSWORDFILE
# If you use Password Store (aka zx2c4's pass), set this variable to the full path of the file
# containing your TTRSS account password (note: full path, but use tilde, please)
# If you don't use Password Store, you should comment out the following line!
pass_ttrss_path="~/.password-store/ttrss/yourpassword.gpg"
### NO MORE USER EDITS SHOULD BE NECESSARY BEYOND THIS LINE
set -euo pipefail
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
usage() {
cat <<EOF
Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-v] -c category
Connects to your TinyTinyRSS instance and auto-plays all articles
from the category you specify using mpv. Works well for videos and most podcasts.
Supply your TTRSS category id using the -c parameter, e.g., ttrss-video-mpv.sh -c 30
Note! This script requires you to edit some variables inside it *before*
running it the first time to work.
EOF
exit
}
msg() {
echo >&2 -e "${1-}"
}
die() {
local msg=$1
local code=${2-1} # default exit status 1
msg "$msg"
exit "$code"
}
parse_params() {
while :; do
case "${1-}" in
-h | --help) usage ;;
-v | --verbose) set -x ;;
-c | --category) # named parameter "category id"
category="${2-}"
shift
;;
-?*) die "Unknown option: $1" ;;
*) break ;;
esac
shift
done
args=("$@")
# Check required params and arguments
[[ -z "${category-}" ]] && die "Missing required parameter: category"
# apart from the above flags and parameters, this script takes no arguments
[[ ${#args[@]} -gt 0 ]] && die "This script does not handle arguments"
return 0
}
parse_params "$@"
# the TTRSS "category id" of the category (i.e., TTRSS folder)
# easily seen in your TTRSS URL with a category selected: "ttrss.yourdomain.se/#f=30"
ttrss_catid=$category
# check if pass_ttrss_path variable is defined, is not empty string, and path points to a file
# var is set AND var is not empty string AND path points to an existing file
# since there is no point trying to fetch password if the path specified by the user does not exist
if [[ ! -z ${pass_ttrss_path+x} && $pass_ttrss_path != "" && -f "$(eval echo $pass_ttrss_path)" ]]; then
# strip "~/.password-store/" and ".gpg" from string
# (room for improvement: handle full paths too, i.e., "/home/taha/..." instead of "~/")
# bash string substitution: ${var/pattern/replacement}
# https://wizardzines.com/comics/parameter-expansion/
# note: hashtag here is equivalent to regex caret, ^
pass_ttrss_file="${pass_ttrss_path/#\~\/\.password-store\//}"
# note: percent here is equivalent to regex dollar, $
pass_ttrss_file="${pass_ttrss_file/%\.gpg/}"
# read the specified file in the user's Password Store
pass_ttrss_file_contents=$(pass show $pass_ttrss_file)
# get the first word (we're assuming that's the password) from the password-file
# using awk and printf (this treats the variable as a file input)
ttrss_pwd=$(printf '%s' "$pass_ttrss_file_contents" | awk 'NR==1{print $1}')
else
# in this case, prompt for the password
# but just to be nice, if the user specified an invalid path in pass_ttrss_path, let them know
if [[ ! -z ${pass_ttrss_path+x} && $pass_ttrss_path != "" && ! -f "$(eval echo $pass_ttrss_path)" ]]; then
echo "\$pass_ttrss_path does not contain a path to an existing file. Did you mean to set it?"
fi
read -s -p "Password for $ttrss_usr at $ttrss_url: " ttrss_pwd
printf "\n" # newline after read command to avoid messing up the output
fi
# this python script connects to our TTRSS instance, fetches the latest video, and plays it in mpv
$script_dir/env/bin/python $script_dir/ttrss-video-mpv.py $ttrss_url $ttrss_usr $ttrss_pwd $ttrss_catid
return 0