├── README.md ├── ani-cli └── LICENSE /README.md: -------------------------------------------------------------------------------- 1 | # ani-cli 2 | 3 | This is a fork of pystardust's [old-ani-cli](https://github.com/pystardust/ani-cli/tree/old-ani-cli) 4 | 5 | A cli to browse and watch anime. 6 | 7 | This tool scrapes the site [gogoanime](https://gogoanime.vc). 8 | 9 | 10 | ## Usage 11 | 12 | # watch anime 13 | ani-cli 14 | 15 | # download anime 16 | ani-cli -d 17 | 18 | # resume watching anime 19 | ani-cli -H 20 | 21 | Multiple episodes can be viewed/downloaded by giving the episode range like so 22 | 23 | Choose episode [1-13]: 1 6 24 | 25 | This would open/download episodes 1 2 3 4 5 6 26 | 27 | ## Dependencies 28 | 29 | * grep 30 | * curl 31 | * sed 32 | * mpv 33 | * ffmpeg 34 | -------------------------------------------------------------------------------- /ani-cli: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # dependencies: grep sed curl video_player 4 | # video_player ( needs to be able to play urls ) 5 | player_fn="mpv" 6 | 7 | prog="ani-cli" 8 | logfile="${XDG_CACHE_HOME:-$HOME/.cache}/ani-hsts" 9 | base_url=$(curl -s -L -o /dev/null -w "%{url_effective}\n" https://gogoanime.cm) 10 | 11 | c_red="\033[1;31m" 12 | c_green="\033[1;32m" 13 | c_yellow="\033[1;33m" 14 | c_blue="\033[1;34m" 15 | c_magenta="\033[1;35m" 16 | c_cyan="\033[1;36m" 17 | c_reset="\033[0m" 18 | 19 | 20 | help_text () { 21 | while IFS= read line; do 22 | printf "%s\n" "$line" 23 | done <<-EOF 24 | USAGE: $prog 25 | -h show this help text 26 | -d download episode 27 | -H continue where you left off 28 | EOF 29 | } 30 | 31 | 32 | die () { 33 | printf "$c_red%s$c_reset\n" "$*" >&2 34 | exit 1 35 | } 36 | 37 | err () { 38 | printf "$c_red%s$c_reset\n" "$*" >&2 39 | } 40 | 41 | search_anime () { 42 | # get anime name along with its id 43 | search=$(printf '%s' "$1" | tr ' ' '-') 44 | titlepattern='/{ 75 | s/.*href="([^"]*)".*/\1/p 76 | q 77 | }' 78 | } 79 | 80 | get_links () { 81 | dpage_url="$1" 82 | 83 | curl -s "$dpage_url" | 84 | sed -n -E ' 85 | /href="([^"]*)" download>Download/{ 86 | s/href="([^"]*)" download>Download/\1/p 87 | q 88 | }' | tr -d ' ' | sed "s/amp;//" 89 | } 90 | 91 | dep_ch () { 92 | for dep; do 93 | if ! command -v "$dep" >/dev/null ; then 94 | die "Program \"$dep\" not found. Please install it." 95 | fi 96 | done 97 | } 98 | 99 | # get query 100 | get_search_query () { 101 | if [ -z "$*" ]; then 102 | printf "Search Anime: " 103 | read -r query 104 | else 105 | query=$* 106 | fi 107 | } 108 | 109 | # create history file 110 | [ -f "$logfile" ] || : > "$logfile" 111 | 112 | ##################### 113 | ## Anime selection ## 114 | ##################### 115 | 116 | anime_selection () { 117 | search_results=$* 118 | menu_format_string='[%d] %s\n' 119 | menu_format_string_c1="$c_blue[$c_cyan%d$c_blue] $c_reset%s\n" 120 | menu_format_string_c2="$c_blue[$c_cyan%d$c_blue] $c_yellow%s$c_reset\n" 121 | 122 | count=1 123 | while read anime_id; do 124 | # alternating colors for menu 125 | [ $((count % 2)) -eq 0 ] && 126 | menu_format_string=$menu_format_string_c1 || 127 | menu_format_string=$menu_format_string_c2 128 | 129 | printf "$menu_format_string" "$count" "$anime_id" 130 | count=$((count+1)) 131 | done <<-EOF 132 | $search_results 133 | EOF 134 | 135 | # User input 136 | printf "$c_blue%s$c_green" "Enter number: " 137 | read choice 138 | printf "$c_reset" 139 | 140 | # Check if input is a number 141 | [ "$choice" -eq "$choice" ] 2>/dev/null || die "Invalid number entered" 142 | 143 | # Select respective anime_id 144 | count=1 145 | while read anime_id; do 146 | if [ $count -eq $choice ]; then 147 | selection_id=$anime_id 148 | break 149 | fi 150 | count=$((count+1)) 151 | done <<-EOF 152 | $search_results 153 | EOF 154 | 155 | [ -z "$selection_id" ] && die "Invalid number entered" 156 | 157 | read last_ep_number <<-EOF 158 | $(search_eps "$selection_id") 159 | EOF 160 | } 161 | 162 | ################## 163 | ## Ep selection ## 164 | ################## 165 | 166 | episode_selection () { 167 | [ $is_download -eq 1 ] && 168 | printf "Range of episodes can be specified: start_number end_number\n" 169 | 170 | printf "${c_blue}Choose episode $c_cyan[1-%d]$c_reset:$c_green " $last_ep_number 171 | read ep_choice_start ep_choice_end 172 | printf "$c_reset" 173 | 174 | } 175 | 176 | open_episode () { 177 | anime_id=$1 178 | episode=$2 179 | 180 | # clear the screen 181 | printf '\x1B[2J\x1B[1;1H' 182 | if [ $episode -lt 1 ] || [ $episode -gt $last_ep_number ]; then 183 | err "Episode out of range" 184 | printf "${c_blue}Choose episode $c_cyan[1-%d]$c_reset:$c_green " $last_ep_number 185 | read episode 186 | printf "$c_reset" 187 | fi 188 | 189 | printf "Getting data for episode %d\n" $episode 190 | 191 | dpage_url=$(get_dpage_link "$anime_id" "$episode") 192 | video_url=$(get_links "$dpage_url") 193 | 194 | case $video_url in 195 | *streamtape*) 196 | # If direct download not available then scrape streamtape.com 197 | BROWSER=${BROWSER:-firefox} 198 | printf "scraping streamtape.com\n" 199 | video_url=$(curl -s "$video_url" | sed -n -E ' 200 | /^