../Ich glotz TV

2024-02-27

watchtv.sh Screenshot

Nicht nur Nina Hagen schaute 1978 in die Roehre, auch ich glotz TV(Youtube-Link) wenn mir danach ist. Dabei hilft mir seit Jahren ein Wrapper-Skript, welches Daten von Kodinerds mit dem Inhalt der Zwischenablage kombiniert und als Senderauswahl praesentiert (auf obigem Screenshot wird anstelle von dmenu ein Terminal mit fzf benutzt):

#!/usr/bin/env bash

# Requirements : dmenu, mpv, yt-dlp, xclip

# configuration {{{1
# the videoplayer used to view the stream (or video-URL)
player="mpv --no-resume-playback"
# the program used to select the stream (or video-URL)
chooser="dmenu -b -i -l 10"
# the online location of the file-list
filesource="https://raw.githubusercontent.com/jnk22/kodinerds-iptv/master/iptv/clean/clean_tv.m3u"
# where to store the list local
filename="/tmp/clean_tv.m3u"

# no need to change anything below this line {{{1
tmpchannels=$(mktemp /tmp/watchtv-tmpchannels_xxxx)

trap housekeeping 1 2 3 6
housekeeping() {
  rm "${tmpchannels}"
}

# grab data from kodinerds (kudos)
if [[ ! -f "${filename}" ]]; then
  wget -O "${filename}" ${filesource}
fi

# only update when file is older than 6 hours
file_time=$(stat --format='%Y' "$filename")
current_time=$(date +%s)
if (( file_time < ( current_time - ( 60 * 60 * 6 ) ) )); then
  echo "$filename is older than 6 hours. Updating..."
  wget -O "${filename}" ${filesource}
fi

# add clipboard content to selection
echo "clipboard :: $(xclip -o | head -n 1)" > ${tmpchannels}
sed '1d' "${filename}" | paste - - | cut -d, -f 2- | sed 's/^\(.*\)\(http.*\)$/\1::\ \2/;s/\s\+/\ /g' >> ${tmpchannels}

# finally: select and play
channel=$(cat "${tmpchannels}" | ${chooser})
play=$(echo "${channel}" | sed 's/^.*::\ //')
if [[ "${play}" = "" ]]; then
  exit 0
fi
echo "${play}" | xclip -i
${player} "${play}"

# modeline {{{1
# vim: set et sw=2 ts=2 fdm=marker: