Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # get plex id from imdb id
- source /drive/drive/.rtorrent/scripts/master.sh
- omdb_query="$(curl -s "http://www.omdbapi.com/?i=$1&apikey=$o_key")" #query omdb
- omdb_title="$(echo "$omdb_query" |jq -r '.Title')" #get title from omdb
- omdb_type="$(echo "$omdb_query" |jq -r '.Type')" #Get type
- case $omdb_type in
- 'series')
- omdb_type="show";; #align with output from plex
- esac
- xxd_title="$(echo "$omdb_title"| xxd -plain | tr -d '\n' | sed 's/\(..\)/%\1/g' |sed s'/%0a//g')" #convert to ascii
- search_data="$(curl -H "X-Plex-Token: $p_key" -s "http://localhost:32400/search?query=$xxd_title" | x2j |sed 's/@//g')" #search query
- #echo "$omdb_title"
- #echo "$xxd_title"
- #echo "$search_data";exit;
- search_hits="$(echo "$search_data" | jq -r '.' |grep -c 'originallyAvailableAt":')" #get matches
- hit=0
- while [ "$counter" -lt "$search_hits" ]; do
- #Do we need counter or not?
- if [ "$search_hits" = "1" ]; then
- int=""
- elif [ "$search_hits" -gt "1" ]; then
- int="[$counter]"
- fi
- media_type="$(echo "$search_data" |jq -r ".MediaContainer.Video$int.type")" #get current iteration media type
- container="video"
- if [ "$media_type" = "null" ]; then
- media_type="$(echo "$search_data" |jq -r ".MediaContainer.Directory$int.type")"
- container="directory"
- fi
- case "$container" in
- 'video')
- rating_key="$(echo "$search_data" |jq -r ".MediaContainer.Video$int.key" |awk -F "/" '{print $4}')" #get current iteration rating key
- if [ "$rating_key" != "null" ]; then # skip if null
- 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
- 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
- meta_type="$(echo "$metadata_query" | jq -r '.MediaContainer.Video.type')"
- if [ "$1" = "$query_id" ]; then
- echo "$meta_type - $1 - $query_id - $rating_key - $omdb_title"
- let hit=hit+1
- fi
- fi;;
- 'directory')
- rating_key="$(echo "$search_data" |jq -r ".MediaContainer.Directory$int.key" |awk -F "/" '{print $4}')" #get current iteration rating key
- if [ "$rating_key" != "null" ]; then # skip if null
- 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
- if [ "$media_type" = "show" ]; then
- query_id="$(echo "$metadata_query" | jq -r '.MediaContainer.Directory.guid' |awk -F "//" '{print $2}' |awk -F '/' '{print $1}')" #get imdb/thetvdb of this match
- 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}')"
- fi
- if [ "$1" = "$query_id" ]; then
- echo "$media_type - $1 - $query_id - $rating_key - $omdb_title"
- let hit=hit+1
- fi
- fi
- esac
- #echo "$search_data"
- let counter=counter+1
- done
- if [ "$hit" = "0" ]; then
- exit 1
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement