Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- ######################################################################
- #Copyright (C) 2025 Kris Occhipinti
- #https://filmsbykris.com
- #This program is free software: you can redistribute it and/or modify
- #it under the terms of the GNU General Public License as published by
- #the Free Software Foundation version 3 of the License.
- #This program is distributed in the hope that it will be useful,
- #but WITHOUT ANY WARRANTY; without even the implied warranty of
- #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- #GNU General Public License for more details.
- #You should have received a copy of the GNU General Public License
- #along with this program. If not, see <http://www.gnu.org/licenses/>.
- ######################################################################
- while getopts vhq: flag; do
- case "${flag}" in
- v) view="true" ;;
- q) q=${OPTARG} ;;
- h) help="true" ;;
- esac
- done
- # fatal uses SIGUSR1 to allow clean fatal errors
- trap "exit 1" 10
- PROC=$$
- function error() {
- red=$(echo -en "\e[31m")
- normal=$(echo -en "\e[0m")
- echo -e "${red}$@${normal}" >&2
- # exit 1
- kill -10 $PROC
- }
- function help() {
- local self="${0##*/}"
- echo "Useage: $self {options}"
- echo -e "\t-h\thelp"
- echo -e "\t-v\tview image in shell"
- echo -e "\t-q\tsearch query"
- exit
- }
- [[ $help ]] && help
- [[ $q ]] || read -p "Enter Show or Movie Name: " q
- [[ $q ]] || help
- domain="https://www.themoviedb.org"
- search_url="${domain}/search?query=${q}"
- data="$(wget "$search_url" -qO- | grep 'class="result"' | grep -v 'data.name' | grep '<h2>' | grep -o "href.*" | cut -d\" -f2,3 | sed 's/?language=en-US"><h2>/|/g')"
- list="$(echo "$data" | sed 's/"><h2>/|/g' | cut -d\< -f1 | awk -F '|' '{print $2 "|" $1}' | column -s "|" -t)"
- [[ $list =~ '/' ]] || error "No results"
- selection="$(echo "$list" | fzf)"
- [[ $selection ]] || exit
- #link="$(echo "$selection" | sed 's| /movie|/\nmovie|g;s| /tv|/\ntv|g' | tail -n1)"
- link="$(echo "$selection" | sed 's| /|\n/|g' | grep -e '^/movie' -e '^/tv' | tail -n1)"
- link="${domain}${link}"
- img_url="$(wget -qO- "$link" | grep 'class="poster' | cut -d\" -f4 | grep ".jpg" | head -n1)"
- [[ $img_url ]] || error "No URL Found"
- echo "$img_url"
- [[ "$view" ]] && wget -qO- "$img_url" | chafa -
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement