#!/usr/bin/env bash # https://gitlab.com/uoou/dotfiles/-/tree/master/stow/bin/home/drew/.local/bin/pop function usage { echo -e "\n\tUsage: $(basename "$0") \"name of film or show\" [season] [ep] [resolution (e.g.: 720)]" exit 1 } function play { [[ -z "$magnet" ]] && echo -e "\n\tNo torrent found" && exit echo "$magnet" exit } [[ "$#" -lt 1 ]] && usage if [[ "$1" == *"magnet:?"* ]];then magnet="$1" play fi apiurl="https://tv-v2.api-fetch.sh" title=$(echo "$1" | sed 's/ /%20/g') imdbid=$(curl -s "https://www.imdb.com/find?ref_=nv_sr_fn&s=all&q=$title" | grep -io '/dev/null | sed -e 's/"//g') else ! [[ "$2" =~ ^[0-9]+$ ]] && usage magnet=$(curl -s "$apiurl/movie/$imdbid" | jq " .torrents | .[] | .\"$2p\" | .url " 2>/dev/null | sed -e 's/"//g') fi play fi # TV Show ( name season episode [resolution] ) [[ "$#" -ne 3 ]] && [[ "$#" -ne 4 ]] && usage ! [[ "$2" =~ ^[0-9]+$ ]] || ! [[ "$3" =~ ^[0-9]+$ ]] && usage if [[ "$#" -eq 3 ]];then magnet=$(curl -s "$apiurl/show/$imdbid" | jq ".episodes[] | select(.season==$2) | select(.episode==$3) | .torrents | [.[]] | sort_by(.seeds) | reverse | .[0] | .url " 2>/dev/null | sed -e 's/"//g') else ! [[ "$4" =~ ^[0-9]+$ ]] && usage magnet=$(curl -s "$apiurl/show/$imdbid" | jq ".episodes[] | select(.season==$2) | select(.episode==$3) | .torrents | .\"$4p\" | .url" 2>/dev/null | sed -e 's/"//g') fi play