Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- dir="directory where to save files"
- file="file where to save links to your favorite animes from https://www.thewatchcartoononline.tv"
- linksfile="this file is updated to the latest episodes of your animes"
- i=0
- while read -r l ; do
- links[$i]="$l"
- i=$((i+1))
- done < "$file"
- function get_title(){
- t=$( echo "$1" \
- |cut -d'|' -f3 \
- |cut -d'/' -f5 \
- |sed 's/-english-subbed-guide//' \
- |sed 's/-english-dubbed-guide//' \
- |sed 's/-english-subbed-episodes//' \
- |sed 's/-english-dubbed-episodes//' \
- |sed 's/-english-subbed//' \
- |sed 's/-english-dubbed//'
- )
- echo "$t"
- }
- function get_ans(){
- ans=$(
- for k in "${links[@]}" ; do
- get_title "$k"
- done |rofi -dmenu -p "my mangas" -width -180
- )
- [[ -z "$ans" ]] && exit
- }
- function get_index(){
- get_ans
- index=$(
- for (( i=0 ; i <=${#links[@]} ; i++ )) ; do
- if echo "${links[$i]}" |grep "$ans" >/dev/null
- then echo "$i"
- break
- fi
- done
- )
- }
- function CURL() {
- userAgent="Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:48.0) "
- userAgent+="Gecko/20100101 Firefox/48.0"
- curl -s -A "$userAgent" "$@"
- }
- function getInfo(){
- get_index
- echo
- echo " $ans"
- echo
- if ! [[ -f "$dir/$ans" ]] ; then
- l=$( echo "${links[$index]}" |cut -d'|' -f3 )
- CURL "$l" \
- | sed -n -e '/<h3>Info:/{N;N;N;N;s/<[^>]*>//g;p}' \
- | perl -C -MHTML::Entities -pe 'decode_entities($_);' \
- | sed 's/[^[:print:]]//g' \
- | fold -w 60 -s \
- > "$dir/$ans"
- fi
- cat "$dir/$ans"
- }
- function list_them(){
- i=1
- for k in "${links[@]}" ; do
- t=$( get_title "$k" )
- stars=$(echo "$k" | cut -d'|' -f1)
- stat=$(echo "$k" | cut -d'|' -f2)
- if echo "$k" |grep ongoing >/dev/null
- then printf '\033[1;32m'
- else printf '\033[1;0m'
- fi
- if ! [[ -f "$dir/$t" ]]
- then printf '\033[1;31m'
- fi
- printf '%12s %5s %2d: %s\n' "$stat" "$stars" "$i" "$t"
- i=$((i+1))
- done
- }
- function star_it(){
- get_index
- stars="$2"
- line=$( cat "$file" |grep -no "${links[$index]}"| cut -d: -f1)
- if [[ "$1" == s ]] ; then
- awk -i inplace -F'|' -v s="$stars" -v l="$line" 'NR==l{ $1=s }{print}' OFS="|" "$file"
- fi
- if [[ "$1" == f ]] ; then
- awk -i inplace -F'|' -v s="$stars" -v l="$line" 'NR==l{ $2=s }{print}' OFS="|" "$file"
- fi
- }
- function delete_it(){
- get_index
- t=$(get_title "${links[$index]}" )
- rm "$dir/$t"
- }
- function watch_f(){
- declare -A arr=()
- n=${#links[@]}
- modif=$(stat "$linksfile" |grep Modify | awk '{print $2}' )
- today=$(date '+%Y-%m-%d' )
- if [[ "$modif" != "$today" ]] || [[ "$1" == f ]] ; then
- > "$linksfile"
- for (( i=0 ; i<$n ; i++ )) ; do
- url=$(echo "${links[$i]}" |cut -d'|' -f3 )
- data=$( CURL "$url" | sed -E -n '/<div class="cat-eps">/{n;p;q}' )
- link=$(echo "$data" | sed -E 's/^.*href="(.*)" rel=.*$/\1/' )
- title=$(echo "$data" | sed -E 's/^.*title="(.*)" class=.*$/\1/' )
- echo "$link|$title" >> "$linksfile"
- done
- fi
- while read -r l ; do
- title="${l#*|}"
- link="${l%|*}"
- ! [[ -z "$title" ]] && arr["$title"]="$link"
- done < "$linksfile"
- LIST=$( for k in "${!arr[@]}" ; do
- printf '%s\n' "$k"
- done
- )
- ans=$(
- echo "$LIST" \
- |sort \
- |rofi -dmenu -p "watch manga" -width -80 -columns 1 -location 8
- )
- ! [[ -z "$ans" ]] && echo "${arr[$ans]}"
- }
- case "$1" in
- l) list_them ;;
- t) getInfo ;;
- w) watch_f "$2" ;;
- s) star_it s "$2" ;;
- r) delete_it ;;
- f) star_it f "$2" ;;
- a) url="$2"
- url="${url//\\/}"
- if grep -w "$url" "$file" >/dev/null
- then
- echo already added
- else echo "||$url" >> "$file"
- fi
- ;;
- o) list_them |grep ongoing ;;
- n) list_them |grep -F '[new]' ;;
- *)
- get_index
- echo "${links[$index]}" |cut -d'|' -f3
- esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement