Advertisement
metalx1000

Download Movie Poster Art

Jan 25th, 2025
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.26 KB | None | 0 0
  1. #!/bin/bash
  2. ######################################################################
  3. #Copyright (C) 2025 Kris Occhipinti
  4. #https://filmsbykris.com
  5. #This program is free software: you can redistribute it and/or modify
  6. #it under the terms of the GNU General Public License as published by
  7. #the Free Software Foundation version 3 of the License.
  8.  
  9. #This program is distributed in the hope that it will be useful,
  10. #but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. #GNU General Public License for more details.
  13.  
  14. #You should have received a copy of the GNU General Public License
  15. #along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16. ######################################################################
  17.  
  18. while getopts vhq: flag; do
  19.   case "${flag}" in
  20.   v) view="true" ;;
  21.   q) q=${OPTARG} ;;
  22.   h) help="true" ;;
  23.   esac
  24. done
  25.  
  26. # fatal uses SIGUSR1 to allow clean fatal errors
  27. trap "exit 1" 10
  28. PROC=$$
  29.  
  30. function error() {
  31.   red=$(echo -en "\e[31m")
  32.   normal=$(echo -en "\e[0m")
  33.  
  34.   echo -e "${red}$@${normal}" >&2
  35.   #  exit 1
  36.   kill -10 $PROC
  37. }
  38.  
  39. function help() {
  40.   local self="${0##*/}"
  41.   echo "Useage: $self {options}"
  42.   echo -e "\t-h\thelp"
  43.   echo -e "\t-v\tview image in shell"
  44.   echo -e "\t-q\tsearch query"
  45.  
  46.   exit
  47. }
  48.  
  49. [[ $help ]] && help
  50. [[ $q ]] || read -p "Enter Show or Movie Name: " q
  51. [[ $q ]] || help
  52.  
  53. domain="https://www.themoviedb.org"
  54. search_url="${domain}/search?query=${q}"
  55.  
  56. 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')"
  57. list="$(echo "$data" | sed 's/"><h2>/|/g' | cut -d\< -f1 | awk -F '|' '{print $2 "|" $1}' | column -s "|" -t)"
  58. [[ $list =~ '/' ]] || error "No results"
  59. selection="$(echo "$list" | fzf)"
  60.  
  61. [[ $selection ]] || exit
  62. #link="$(echo "$selection" | sed 's| /movie|/\nmovie|g;s| /tv|/\ntv|g' | tail -n1)"
  63. link="$(echo "$selection" | sed 's| /|\n/|g' | grep -e '^/movie' -e '^/tv' | tail -n1)"
  64. link="${domain}${link}"
  65. img_url="$(wget -qO- "$link" | grep 'class="poster' | cut -d\" -f4 | grep ".jpg" | head -n1)"
  66.  
  67. [[ $img_url ]] || error "No URL Found"
  68. echo "$img_url"
  69. [[ "$view" ]] && wget -qO- "$img_url" | chafa -
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement