upload functioning version.
This commit is contained in:
19
svt.sh
19
svt.sh
@@ -3,28 +3,19 @@
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
DEBUG="${DEBUG:-0}"
|
||||
WAIT_FOR_MPV=0
|
||||
LOG_FILE="${HOME}/.svtplay.log"
|
||||
|
||||
# Parse options
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--debug) DEBUG=1; shift ;;
|
||||
--wait) WAIT_FOR_MPV=1; shift ;;
|
||||
--log) tail -f "$LOG_FILE"; exit 0 ;;
|
||||
--clear-log) rm -f "$LOG_FILE"; echo "Log cleared"; exit 0 ;;
|
||||
--help|-h)
|
||||
zenity --info --title="SVT Play" --text="Usage: ./svt.sh [--debug|--wait|--log|--help]"
|
||||
zenity --info --title="SVT Play" --text="Usage: ./svt.sh [--wait|--help]"
|
||||
exit 0 ;;
|
||||
*) break ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Logging
|
||||
log() { echo -e "\033[0;34m[$1]\033[0m $2" >&2; echo "[$(date '+%H:%M:%S')] [$1] $2" >> "$LOG_FILE"; }
|
||||
log_err() { echo -e "\033[0;31m[ERROR]\033[0m $1" >&2; echo "[$(date '+%H:%M:%S')] [ERROR] $1" >> "$LOG_FILE"; }
|
||||
|
||||
# Force dark mode - works with GTK3 (GTK_THEME) and GTK4/libadwaita (ADW_DEBUG_COLOR_SCHEME)
|
||||
zenity_dark() { GTK_THEME=Adwaita:dark ADW_DEBUG_COLOR_SCHEME=prefer-dark zenity "$@"; }
|
||||
|
||||
@@ -34,7 +25,6 @@ check_dependencies() {
|
||||
command -v "$cmd" &>/dev/null || missing+=("$cmd")
|
||||
done
|
||||
if [[ ${#missing[@]} -gt 0 ]]; then
|
||||
log_err "Missing: ${missing[*]}"
|
||||
zenity_dark --error --title="Missing Dependencies" --text="Please install: ${missing[*]}"
|
||||
exit 1
|
||||
fi
|
||||
@@ -42,8 +32,6 @@ check_dependencies() {
|
||||
|
||||
search_programs() {
|
||||
local query="$1"
|
||||
log "API" "Searching: $query"
|
||||
|
||||
local response http_code
|
||||
response=$(curl -s --connect-timeout 10 --max-time 30 -w "\n%{http_code}" -X POST \
|
||||
"https://api.svt.se/contento/graphql" -H "Content-Type: application/json" \
|
||||
@@ -52,7 +40,7 @@ search_programs() {
|
||||
http_code=$(echo "$response" | tail -1)
|
||||
response=$(echo "$response" | sed '$d')
|
||||
|
||||
[[ "$http_code" != "200" ]] && { log_err "API HTTP $http_code"; return 1; }
|
||||
[[ "$http_code" != "200" ]] && return 1
|
||||
|
||||
local results
|
||||
results=$(echo "$response" | jq -r '
|
||||
@@ -62,7 +50,6 @@ search_programs() {
|
||||
' 2>/dev/null)
|
||||
|
||||
[[ -z "$results" ]] && return 1
|
||||
log "API" "Found $(echo "$results" | wc -l) results"
|
||||
echo "$results"
|
||||
}
|
||||
|
||||
@@ -95,13 +82,11 @@ show_results_list() {
|
||||
rm -f "$temp_file"*
|
||||
|
||||
[[ -z "$slug" ]] && return 1
|
||||
log "✓" "Selected: $selected"
|
||||
echo "$slug"
|
||||
}
|
||||
|
||||
play_program() {
|
||||
local url="https://www.svtplay.se/$1"
|
||||
log "▶" "Playing: $url"
|
||||
mpv --force-window=immediate "$url" &
|
||||
[[ "$WAIT_FOR_MPV" == "1" ]] && wait $! 2>/dev/null
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user