mini updates
This commit is contained in:
+37
-14
@@ -1,15 +1,20 @@
|
||||
#!/bin/bash
|
||||
|
||||
tmdbid() {
|
||||
local q url
|
||||
local type q url
|
||||
type="$1"
|
||||
shift
|
||||
|
||||
# encode query safely
|
||||
q=$(printf '%s' "$*" | jq -sRr @uri)
|
||||
|
||||
url="https://www.themoviedb.org/search/movie?query=$q"
|
||||
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/[0-9]+' \
|
||||
| grep -oE '/(movie|tv)/[0-9]+' \
|
||||
| head -1 \
|
||||
| cut -d/ -f3
|
||||
}
|
||||
@@ -17,8 +22,8 @@ tmdbid() {
|
||||
clean_title() {
|
||||
local s="$1"
|
||||
|
||||
# remove (year) style parentheses
|
||||
s=$(echo "$s" | sed -E 's/ *\([0-9]{4}\)//')
|
||||
# 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}"
|
||||
@@ -36,16 +41,34 @@ clean_title() {
|
||||
echo "$s"
|
||||
}
|
||||
|
||||
title=$(hyprctl clients -j | jq '.[] | select(.workspace.id == 3)' | grep "The Movie Database" | sed 's/ — The Movie Database.*//' | sed 's/ "title": "//g')
|
||||
tmdbid=$(tmdbid "$title")
|
||||
ws="${1:-3}"
|
||||
|
||||
year="${title: -6}"
|
||||
title=$(hyprctl clients -j | jq ".[] | select(.workspace.id == $ws)" | grep "The Movie Database" | sed 's/ — The Movie Database.*//' | sed 's/ "title": "//' | sed 's/"$//')
|
||||
|
||||
if [ -z "$tmdbid" ]; then
|
||||
new_title="${title//\ ([0-9][0-9][0-9][0-9])/}"
|
||||
tmdbid=$(tmdbid "$new_title")
|
||||
search_title=$(echo "$title" | sed -E 's/ *\([^)]*\) *//g')
|
||||
|
||||
if echo "$title" | grep -qi "TV [Ss]eries"; then
|
||||
type="tv"
|
||||
else
|
||||
type="movie"
|
||||
fi
|
||||
|
||||
clean=$(clean_title "$title")
|
||||
tmdbid=$(tmdbid "$type" "$search_title")
|
||||
|
||||
wtype "$clean $year [tmdb-$tmdbid]"
|
||||
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