-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfap-cli
More file actions
executable file
·183 lines (160 loc) · 4.74 KB
/
Copy pathfap-cli
File metadata and controls
executable file
·183 lines (160 loc) · 4.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/bin/sh
help_text() {
while IFS= read -r line; do
printf "%s\n" "$line"
done <<-EOF
Usage:
${0##*/} [-d | -p <download_dir>] [<query>]
${0##*/} [-v] [<query>]
${0##*/} -h
Options:
-h show helptext
-d download video
-p download video to specified directory
-v use VLC as the media player
EOF
}
info() {
#shellcheck disable=SC2059
printf "\033[2K\r\033[1;${2:-32}m${1}\033[0m"
}
ask() {
info "$1" "33"
}
err() {
info "$1\n" "31"
}
input() {
ask " Episode??(1-$1)> "
read -r x
while [ -z "$x" ] || ! [ "$x" -eq "$x" ] 2>/dev/null || [ "$x" -lt "1" ] 2>/dev/null || [ "$x" -gt "$1" ] 2>/dev/null; do
err "Invalid choice"
ask " Episode??(1-$1)> "
read -r x
done
ep_no=$x
unset x
}
download() {
info "Downloading $2" "34"
case $1 in
*m3u8) $terminal hls -n 300 -ro "$download_dir/$2" "$1" ;;
*) $terminal aria2c --summary-interval=0 -x 16 -s 16 --referer="$base_url" "$1" -d "$download_dir" -o "$2.mp4" --download-result=hide ;;
esac
}
get_show() {
info "Searching query.." "34"
results=$(search | fzf --bind="change:reload:$run_file {q} 1" --prompt="Search: ")
[ -z "$results" ] && err "No search results found" && exit 0
info ""
result=$(printf "%s" "$results" | fzf --layout="reverse" --border --height=10 -1)
[ -z "$result" ] && err "No hentai selected" && exit 0
info "selected $result\n" "35"
info "Fetching Episodes List.." "34"
ep_list=$(curl -sA "$agent" "$base_url/tvshows/$result/" | sed -nE "s_^[[:space:]]*<a href=\"$base_url/(.*)/\">.\$_\1_p" | tac)
noofeps=$(printf "%s\n" "$ep_list" | wc -l)
ep_no=1
[ "$noofeps" -gt 1 ] && input "$noofeps"
get_ep_link
}
get_ep_link() {
tput clear
info "Loading Episode $ep_no" "34"
ep_id=$(printf "%s" "$ep_list" | sed -n "${ep_no}p")
id=$(curl -sA "$agent" "$base_url/$ep_id/" | sed -nE "s/.*?p=(.*)'.*/\1/p")
display=$(printf "%s" "$ep_id" | cut -d'/' -f2- | tr "-" " ")
[ -z "$id" ] && err "Episode doesn't exist on this site" && return 1
play_link
}
play_link() {
info "Fetching Video Link" "34"
data="$(curl -sA "$agent" "$(curl -sA "$agent" "$base_url/wp-admin/admin-ajax.php" -d "action=get_player_contents&a=$id" -H "X-Requested-With:XMLHttpRequest" | sed 's/\\//g' | sed -nE 's/.*src="(.*)" width.*,.*/\1/p')")"
video_link="$(printf "%s" "$data" | sed -nE 's/[[:space:]]*<source src="(.*)" typ.*/\1/p')"
# trying again
[ -z "$video_link" ] && video_link="$(printf "%s" "$data" | sed -nE 's/[[:space:]]*file: "(.*)".$/\1/p')"
[ -z "$video_link" ] && err "Video Url not found" && return 1
info "\n$video_link\n"
case $player_fn in
vlc) setsid -f "$player_fn" --http-referrer="$base_url" "$video_link" >/dev/null 2>&1 ;;
mpv) setsid -f "$player_fn" "$video_link" --referrer="$base_url" --force-media-title="$display" >/dev/null 2>&1 ;;
mpv_android) am start --user 0 -a android.intent.action.VIEW -d "$video_link" -n is.xyz.mpv/.MPVActivity >/dev/null 2>&1 ;;
vlc_android) am start --user 0 -a android.intent.action.VIEW -d "$video_link" -n org.videolan.vlc/org.videolan.vlc.gui.video.VideoPlayerActivity -e "title" "$video_link" >/dev/null 2>&1 ;;
download) $player_fn "$video_link" "$display" ;;
esac
[ "$noofeps" -eq 1 ] && exit 0
}
trap "exit 0" INT HUP
base_url="https://hentaimama.io"
player_fn="mpv"
is_download=0
download_dir='.'
run_file="${TMPDIR:-/tmp}/${0##*/}_run"
agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/13$(head /dev/urandom | tr -dc '0-5' | cut -c1).0.0.0 Safari/537.36"
case $(uname -o) in
*ndroid*)
download_dir="/sdcard"
player_fn="mpv_android"
alt_fn="vlc_android"
;;
*)
download_dir="$HOME/Downloads"
player_fn="mpv"
alt_fn="vlc"
[ -t 1 ] || terminal="${TERMINAL:-foot} -e"
;;
esac
\cat <<EOF >"$run_file"
search() { curl -s -A "$agent" "$base_url/?s=\$1" | sed -nE 's_^[[:space:]]*<a href="$base_url/tvshows/(.*)/">.\$_\1_p'; }; [ -n "\$2" ] && search "\$1"
EOF
chmod +x "$run_file"
# shellcheck disable=SC1091,SC1090
. "$run_file"
while getopts 'dhp:v' OPT; do
case $OPT in
d)
player_fn="download"
;;
p)
player_fn="download"
download_dir=$OPTARG
;;
v)
player_fn=$alt_fn
;;
*)
help_text
exit 0
;;
esac
done
shift $((OPTIND - 1))
get_show
while :; do
info "\nCurrently playing $display/$noofeps\n"
[ "$ep_no" != "$noofeps" ] && info "(n) next\n" "33"
[ "$ep_no" != "1" ] && info "(p) previous\n" "36"
info "(e) select episode\n" "34"
info "(q) exit\n" "31"
ask "> "
read -r choice
case $choice in
n)
[ "$((ep_no + 1))" -gt "$noofeps" ] && err "Episode out of range" && continue
: $((ep_no += 1))
;;
p)
[ "$((ep_no - 1))" -lt "1" ] && err "Episode out of range" && continue
: $((ep_no -= 1))
;;
e)
input "$noofeps"
;;
q)
break
;;
*)
err "invalid choice"
;;
esac
get_ep_link
done