Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- dir="${HOME}/articls/manga"
- pyS="${HOME}/myanime/myanime.py"
- function get_ans(){
- ans=$(
- python "$pyS" all|awk '{print $3}'|
- rofi -i -dmenu -p "my mangas" -width -180
- )
- [[ -z "$ans" ]] && exit
- echo "$ans"
- }
- 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(){
- title=$(get_ans)
- echo
- echo " $title"
- echo
- if ! [[ -f "$dir/$title" ]] || \
- ! [[ -f "$dir/pics/$title" ]] ; then
- l=$( python "$pyS" url "$title" )
- data=$(CURL "$l")
- text=$( echo "$data" \
- | 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 \
- )
- ! [[ -f "$dir/$title" ]] && {
- echo "$text" > "$dir/$title"
- }
- pic=$(echo "$data" |
- grep '<meta property="og:image" content='|
- sed 's/<meta property="og:image" content=//'|
- sed 's/ \/>//;s/"//'
- )
- ! [[ -f "$dir/pics/$title" ]] && {
- wget -c "$pic" -q -O "$dir/pics/$title"
- }
- fi
- cat "$dir/$title"
- #tycat "$dir/pics/$title"
- }
- function list_them(){
- python "$pyS" all|
- #sort -k2 -n |
- awk -v p="$dir" '
- {
- color="\033[1;0m"
- red="\033[1;31m"
- file=p "/" $3
- if($1 == "ongoing") color="\033[1;32m"
- if(system("[ ! -f " file " ]") == 0) color=red
- printf("%s%10s %s%d%s %s\n",color,$1,red,$2,color,$3)
- }'
- }
- function set_rank(){
- title=$(get_ans)
- python "$pyS" setr "$title" "$1"
- }
- function set_status(){
- title=$(get_ans)
- python "$pyS" sets "$title" "$1"
- echo "$title: $1"
- }
- function delete_it(){
- title=$(get_ans)
- python "$pyS" rm "$title"
- rm "$dir/$title"
- }
- function watch_f(){
- code=$(ping -c 1 8.8.8.8 2>&1 |grep unreachable >/dev/null; echo $? )
- today=$(date '+%Y-%m-%d %H:%M:%S' )
- n='^[\.0-9]*$'
- while IFS="|" read -r id title elink etitle edate episode adate entitle aa; do
- [[ "$edate" == "None" ]] && edate=$( date -d '-1 day' '+%Y-%m-%d %H:%M:%S' )
- [[ "$adate" == "None" ]] && adate=$( date -d '-1 day' '+%Y-%m-%d %H:%M:%S' )
- a=$(date -d "$edate" '+%s' )
- b=$(date -d "$today" '+%s' )
- d=$(date -d "$adate" '+%s' )
- c=$((b-a))
- color='\033[1;0m'
- if (( $(($b-$d)) > 100 )) && (( code != 0 )) ; then
- #update access date
- python "$pyS" sad "$title" "$today"
- link=$(python "$pyS" url "$title")
- data=$( CURL "$link" | sed -E -n '/<div class="cat-eps">/{n;p;q}' )
- nlink=$(echo "$data" | sed -E 's/^.*href="(.*)" rel=.*$/\1/' )
- ntitle=$(echo "$data" | sed -E 's/^.*title="(.*)" class=.*$/\1/' \
- | perl -C -MHTML::Entities -pe 'decode_entities($_);' \
- | sed 's/[^[:print:]]//g;s/Watch//' \
- )
- nepisode=$(echo "$ntitle" |
- sed -E 's/^.* Episode ([\.0-9]*) .*$/\1/g'
- )
- if [[ -z "$nepisode" ]] ; then nepisode="0" ; fi
- if ! [[ "$nepisode" =~ $n ]] ; then nepisode="0" ; fi
- if (( $(echo "$nepisode > $episode" |bc -l) )) ; then
- python "$pyS" wadd "$title" "$nlink" \
- "$ntitle" "$today" "$nepisode"
- color='\033[1;32m'
- etitle="$ntitle"
- episode="$nepisode"
- fi
- fi
- if [[ "$entitle" != "None" ]] && [[ "$1" != o ]]
- then
- etitle=" $entitle"
- else
- etitle=$(echo "$etitle" |
- sed -E 's/^(.*)Episode ([0-9]*) (.*$)/\1\3/g'
- )
- fi
- (( ${#etitle} > 70 )) && etitle="${etitle:0:70}..."
- D="$(echo "$c / 3600 / 24 " |bc )"
- c="$(echo "$c - ( $D * 3600 * 24 ) " |bc )"
- H="$(echo "$c / 3600 " |bc )"
- c="$(echo "$c - ( $H * 3600 ) " |bc )"
- M="$(echo "$c / 60 " |bc )"
- if [[ "$color" != '\033[1;32m' ]] ; then
- if (( $D < 10 )) ; then color='\033[1;33m' ; fi
- if (( $D == 0 )) ; then color='\033[1;36m' ; fi
- fi
- printf "$color"
- printf '%4d d %2d h %2d m, Episode ' "$D" "$H" "$M"
- printf '\033[1;31m%.1f' "$episode" |sed 's/\.0//'
- printf "$color$etitle\n"
- done <<< "$(python "$pyS" wl)"
- }
- function add_it(){
- url="$1"
- url="${url//\\/}"
- t=${url##*/}
- title=$( echo "$t" \
- |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//'
- )
- python "$pyS" add "$url" "$title"
- }
- function set_entitle(){
- title=$(get_ans)
- python "$pyS" seten "$title" "$1"
- }
- function help_f(){
- echo '
- l : list them
- t : get info
- w : watch current episodes
- r : set rank
- x : delete it
- s : set status: ongoing, finished
- a : add
- o : list ongoing
- f : list finished
- e : set engilsh title
- h : help
- '
- }
- case "$1" in
- l) list_them ;;
- t) getInfo ;;
- w) watch_f ;;
- wo) watch_f o ;;
- r) set_rank "$2" ;;
- x) delete_it ;;
- s) set_status "$2" ;;
- a) add_it "$2" ;;
- o) list_them |grep ongoing ;;
- f) list_them |grep finished ;;
- h) help_f ;;
- e) set_entitle "$2" ;;
- *) python "$pyS" url "$(get_ans)"
- esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement