some updates
This commit is contained in:
Executable
+74
@@ -0,0 +1,74 @@
|
||||
#!/bin/bash
|
||||
|
||||
tmdbid() {
|
||||
local type q url
|
||||
type="$1"
|
||||
shift
|
||||
|
||||
q=$(printf '%s' "$*" | jq -sRr @uri)
|
||||
|
||||
if [ "$type" = "tv" ]; then
|
||||
url="https://www.themoviedb.org/search/tv?query=$q"
|
||||
else
|
||||
url="https://www.themoviedb.org/search/movie?query=$q"
|
||||
fi
|
||||
|
||||
curl -sL -A 'Mozilla/5.0' "$url" \
|
||||
| grep -oE '/(movie|tv)/[0-9]+' \
|
||||
| head -1 \
|
||||
| cut -d/ -f3
|
||||
}
|
||||
|
||||
clean_title() {
|
||||
local s="$1"
|
||||
|
||||
# remove (year) or (TV Series year) style parentheses
|
||||
s=$(echo "$s" | sed -E 's/ *\([^)]*[0-9]{4}[^)]*\)//')
|
||||
|
||||
# umlaut replacement
|
||||
s="${s//ä/ae}"; s="${s//ö/oe}"; s="${s//ü/ue}"
|
||||
s="${s//Ä/Ae}"; s="${s//Ö/Oe}"; s="${s//Ü/Ue}"
|
||||
|
||||
# remove all numbers
|
||||
s=$(echo "$s" | tr -d '0-9')
|
||||
|
||||
# remove special characters except spaces and letters
|
||||
s=$(echo "$s" | tr -cd '[:alpha:] [:space:]')
|
||||
|
||||
# clean extra spaces
|
||||
s=$(echo "$s" | tr -s ' ')
|
||||
|
||||
echo "$s"
|
||||
}
|
||||
|
||||
ws="${1:-3}"
|
||||
|
||||
title=$(hyprctl clients -j | jq ".[] | select(.workspace.id == $ws)" | grep "The Movie Database" | sed 's/ — The Movie Database.*//' | sed 's/ "title": "//' | sed 's/"$//')
|
||||
|
||||
search_title=$(echo "$title" | sed -E 's/ *\([^)]*\) *//g')
|
||||
|
||||
if echo "$title" | grep -qi "TV [Ss]eries"; then
|
||||
type="tv"
|
||||
else
|
||||
type="movie"
|
||||
fi
|
||||
|
||||
tmdbid=$(tmdbid "$type" "$search_title")
|
||||
|
||||
if [ -z "$tmdbid" ]; then
|
||||
if [ "$type" = "tv" ]; then
|
||||
tmdbid=$(tmdbid "movie" "$search_title")
|
||||
else
|
||||
tmdbid=$(tmdbid "tv" "$search_title")
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ $title =~ ([0-9]{4}) ]]; then
|
||||
year="${BASH_REMATCH[1]}"
|
||||
else
|
||||
year=""
|
||||
fi
|
||||
|
||||
clean=$(clean_title "$title")
|
||||
|
||||
wtype "$clean ($year) [tmdb-$tmdbid]"
|
||||
Reference in New Issue
Block a user