Advertisement
Guest User

Untitled

a guest
Oct 13th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.54 KB | None | 0 0
  1. #!/bin/bash
  2. # get plex id from imdb id
  3. source /drive/drive/.rtorrent/scripts/master.sh
  4. omdb_query="$(curl -s "http://www.omdbapi.com/?i=$1&apikey=$o_key")" #query omdb
  5. omdb_title="$(echo "$omdb_query" |jq -r '.Title')" #get title from omdb
  6. omdb_type="$(echo "$omdb_query" |jq -r '.Type')" #Get type
  7. case $omdb_type in
  8.         'series')
  9.         omdb_type="show";; #align with output from plex
  10. esac
  11. xxd_title="$(echo "$omdb_title"| xxd -plain | tr -d '\n' | sed 's/\(..\)/%\1/g' |sed s'/%0a//g')" #convert to ascii
  12. search_data="$(curl -H "X-Plex-Token: $p_key" -s "http://localhost:32400/search?query=$xxd_title" | x2j |sed 's/@//g')" #search query
  13. #echo "$omdb_title"
  14. #echo "$xxd_title"
  15. #echo "$search_data";exit;
  16. search_hits="$(echo "$search_data" | jq -r '.' |grep -c 'originallyAvailableAt":')" #get matches
  17. hit=0
  18. while [ "$counter" -lt "$search_hits" ]; do
  19.         #Do we need counter or not?
  20.         if [ "$search_hits" = "1" ]; then
  21.                 int=""
  22.         elif [ "$search_hits" -gt "1" ]; then
  23.                 int="[$counter]"
  24.         fi
  25.         media_type="$(echo "$search_data" |jq -r ".MediaContainer.Video$int.type")"  #get current iteration media type
  26.         container="video"
  27.         if [ "$media_type" = "null" ]; then
  28.                 media_type="$(echo "$search_data" |jq -r ".MediaContainer.Directory$int.type")"
  29.                 container="directory"
  30.         fi
  31.  
  32.         case "$container" in
  33.         'video')
  34.                 rating_key="$(echo "$search_data" |jq -r ".MediaContainer.Video$int.key" |awk -F "/" '{print $4}')" #get current iteration rating key
  35.                 if [ "$rating_key" != "null" ]; then # skip if null
  36.                         metadata_query="$(curl -H "X-Plex-Token: $p_key" -s "http://localhost:32400/library/metadata/$rating_key/" | x2j |sed 's/@//g')" #grab metadata of this match
  37.                         query_id="$(echo "$metadata_query" | jq -r '.MediaContainer.Video.guid' |awk -F "//" '{print $2}' |awk -F '/' '{print $1}' |awk -F '?' '{print $1}')" #get imdb/thetvdb of this match
  38.                         meta_type="$(echo "$metadata_query" | jq -r '.MediaContainer.Video.type')"
  39.                                 if [ "$1" = "$query_id" ]; then
  40.                                         echo "$meta_type - $1 - $query_id - $rating_key - $omdb_title"
  41.                                         let hit=hit+1
  42.                                 fi
  43.                 fi;;
  44.         'directory')
  45.         rating_key="$(echo "$search_data" |jq -r ".MediaContainer.Directory$int.key" |awk -F "/" '{print $4}')" #get current iteration rating key
  46.         if [ "$rating_key" != "null" ]; then # skip if null
  47.                 metadata_query="$(curl -H "X-Plex-Token: $p_key" -s "http://localhost:32400/library/metadata/$rating_key/" | x2j |sed 's/@//g')" #grab metadata of this match
  48.                 if [ "$media_type" = "show" ]; then
  49.                         query_id="$(echo "$metadata_query" | jq -r '.MediaContainer.Directory.guid' |awk -F "//" '{print $2}' |awk -F '/' '{print $1}')" #get imdb/thetvdb of this match
  50.                         query_id="$(curl -s "https://www.thetvdb.com/index.php?tab=series&id=$query_id" |grep "IMDB_ID" |awk -F "=" '{print $4}' | sed 's/"//g' |awk -F " " '{print $1}')"
  51.                 fi
  52.                 if [ "$1" = "$query_id" ]; then
  53.                         echo "$media_type - $1 - $query_id - $rating_key - $omdb_title"
  54.                         let hit=hit+1
  55.                 fi
  56.         fi
  57.  
  58.         esac
  59. #echo "$search_data"
  60. let counter=counter+1
  61. done
  62. if [ "$hit" = "0" ]; then
  63. exit 1
  64. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement