Skip to content

Commit 323c068

Browse files
71zenithport19xCoolnsX
authored
fix: cut posix compliance (#993)
* fix: literal . in grep * chore: bump v4.0.2 -> v4.0.3 * fix: posix compliance for cut * feat : random user-agent, fix vrv provider, catt support * fix: add back posix compliance fix: add back execution bit docs: remove media locale from man page and add catt as player * refactor: replace sed with tr * fix: add episode link to custom player * fix: readd literal . reversed by previous commit * fix: add exit on end and title flag for vlc Co-authored-by: port19 <[email protected]> Co-authored-by: coolnsx <[email protected]>
1 parent 8d72a7c commit 323c068

File tree

2 files changed

+22
-24
lines changed

2 files changed

+22
-24
lines changed

ani-cli

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh
22

3-
version_number="4.0.1"
3+
version_number="4.0.3"
44

55
# UI
66

@@ -22,8 +22,8 @@ nth() {
2222
prompt="$1"
2323
multi_flag=""
2424
[ $# -ne 1 ] && shift && multi_flag="$1"
25-
line=$(printf "%s" "$stdin" | cut -f1,3 --output-delimiter " " | launcher "$multi_flag" "$prompt" | cut -d " " -f 1)
26-
[ -n "$line" ] && printf "%s" "$stdin" | grep -w "^${line}" | cut -f2,3 || exit 1
25+
line=$(printf "%s" "$stdin" | cut -f1,3 | tr '\t' ' ' | launcher "$multi_flag" "$prompt" | cut -d " " -f 1)
26+
[ -n "$line" ] && printf "%s" "$stdin" | grep -E '^'"${line}"'($|\s)' | cut -f2,3 || exit 1
2727
}
2828

2929
die() {
@@ -100,11 +100,10 @@ dep_ch() {
100100

101101
# extract the video links from reponse of embed urls, extract mp4 links form m3u8 lists
102102
get_links() {
103-
episode_link="$(wget -q -O - "https://blog.allanime.pro/apivtwo/clock.json?id=$*" -U "$agent" | sed 's|},{|\n|g' | sed -nE 's|.*link":"([^"]*)".*"resolutionStr":"([^"]*)".*|\2 >\1|p')"
103+
episode_link="$(wget -q -O - "https://blog.allanime.pro/apivtwo/clock.json?id=$*" -U "$agent" | sed 's|},{|\n|g' | sed -nE 's|.*link":"([^"]*)".*"resolutionStr":"([^"]*)".*|\2 >\1|p;s|.*hls","url":"([^"]*)".*"hardsub_lang":"en-US".*|\1|p')"
104104
case "$episode_link" in
105-
*v.vrv.co*)
106-
extract_link=$(printf "%s" "$episode_link" | grep "$media_locale" | cut -d'>' -f2)
107-
wget -q -O - "$extract_link" -U "$agent" | sed 's|^#.*x||g; s|,.*|p|g; /^#/d; $!N; s|\n| >|; s|\/index-v1-a1\.m3u8||g' | sort -nr
105+
*crunchyroll*)
106+
wget -q -O - "$episode_link" -U "$agent" | sed 's|^#.*x||g; s|,.*|p|g; /^#/d; $!N; s|\n| >|' | sort -nr
108107
;;
109108
*repackager.wixmp.com*)
110109
extract_link=$(printf "%s" "$episode_link" | cut -d'>' -f2 | sed 's|repackager.wixmp.com/||g;s|\.urlset.*||g')
@@ -135,10 +134,11 @@ provider_init() {
135134
# generates links based on given provider
136135
generate_link() {
137136
case $1 in
138-
1) provider_init 'vrv|wixmp' '/Default :/p' ;; # vrv,wixmp(default)(m3u8)(multi) -> (mp4)(multi)
137+
1) provider_init 'wixmp' '/Default :/p' ;; # wixmp(default)(m3u8)(multi) -> (mp4)(multi)
139138
2) provider_init 'pstatic' '/Default B :/p' ;; # pstatic(default backup)(mp4)(multi)
140-
3) provider_init 'sharepoint' '/S-mp4 :/p' ;; # sharepoint(mp4)(single)
141-
4) provider_init 'usercloud' '/Uv-mp4 :/p' ;; # usercloud(mp4)(single)
139+
3) provider_init 'vrv' '/Ac :/p' ;; # vrv(crunchyroll)(m3u8)(multi)
140+
4) provider_init 'sharepoint' '/S-mp4 :/p' ;; # sharepoint(mp4)(single)
141+
5) provider_init 'usercloud' '/Uv-mp4 :/p' ;; # usercloud(mp4)(single)
142142
*) provider_init 'gogoanime' '/Luf-mp4 :/p' ;; # gogoanime(m3u8)(multi)
143143
esac
144144
[ -n "$provider_id" ] && get_links "$provider_id"
@@ -157,13 +157,13 @@ select_quality() {
157157
# gets embed urls, collects direct links into provider files, selects one with desired quality into $episode
158158
get_episode_url() {
159159
# get the embed urls of the selected episode
160-
resp=$(wget -q -O - "https://allanime.site/watch/$id/$allanime_title/episode-$ep_no-$mode" -U "$agent" | tr '{}' '\n' | sed 's|\\u002F|\/|g;s|\\||g' | sed -nE 's|.*sourceUrl":".*clock\?id=([^"]*)".*sourceName":"([^"]*)".*|\2 :\1|p')
160+
resp=$(wget -q -O - "https://allanime.site/watch/$id/episode-$ep_no-$mode" -U "$agent" | tr '{}' '\n' | sed 's|\\u002F|\/|g;s|\\||g' | sed -nE 's|.*sourceUrl":".*clock\?id=([^"]*)".*sourceName":"([^"]*)".*|\2 :\1|p')
161161
# generate links into sequential files
162162
provider=1
163163
i=0
164-
while [ "$i" -lt 5 ]; do
164+
while [ "$i" -lt 6 ]; do
165165
generate_link "$provider" >"$cache_dir"/"$i" &
166-
provider=$((provider % 5 + 1))
166+
provider=$((provider % 6 + 1))
167167
: $((i += 1))
168168
done
169169
wait
@@ -217,18 +217,19 @@ play_episode() {
217217
android_vlc) nohup am start --user 0 -a android.intent.action.VIEW -d "$episode" -n org.videolan.vlc/org.videolan.vlc.gui.video.VideoPlayerActivity -e "title" "${allanime_title}episode-${ep_no}-${mode}" >/dev/null 2>&1 & ;;
218218
iina) nohup "$player_function" --no-stdin --keep-running --mpv-force-media-title="${allanime_title}episode-${ep_no}-${mode}" "$episode" >/dev/null 2>&1 & ;;
219219
flatpak_mpv) flatpak run io.mpv.Mpv --force-media-title="${allanime_title}episode-${ep_no}-${mode}" "$episode" >/dev/null 2>&1 & ;;
220-
vlc*) nohup "$player_function" --video-title="${allanime_title}episode-${ep_no}-${mode}" "$episode" >/dev/null 2>&1 & ;;
220+
vlc*) nohup "$player_function" --play-and-exit --meta-title="${allanime_title}episode-${ep_no}-${mode}" "$episode" >/dev/null 2>&1 & ;;
221221
*yncpla*) nohup "$player_function" "$episode" -- --force-media-title="${allanime_title}episode-${ep_no}-${mode}" >/dev/null 2>&1 & ;;
222222
download) "$player_function" "$episode" "${allanime_title}episode-${ep_no}-${mode}" ;;
223-
*) nohup "$player_function" >/dev/null 2>&1 & ;;
223+
catt) nohup catt cast "$episode" >/dev/null 2>&1 & ;;
224+
*) nohup "$player_function" "$episode" >/dev/null 2>&1 & ;;
224225
esac
225226
update_history
226-
[ "$use_external_menu" = "1" ] && wait
227+
wait
227228
}
228229

229230
play() {
230-
start=$(printf "%s" "$ep_no" | grep -Eo "^[0-9]+(.[0-9])?")
231-
end=$(printf "%s" "$ep_no" | grep -Eo "[0-9]+(.[0-9])?$")
231+
start=$(printf "%s" "$ep_no" | grep -Eo "^[0-9]+(\.[0-9])?")
232+
end=$(printf "%s" "$ep_no" | grep -Eo "[0-9]+(\.[0-9])?$")
232233
[ -z "$end" ] || [ "$end" = "$start" ] && unset start end
233234
line_count=$(printf "%s\n" "$ep_no" | wc -l)
234235
if [ "$line_count" != 1 ] || [ -n "$start" ] ; then
@@ -251,9 +252,9 @@ play() {
251252
# MAIN
252253

253254
# setup
254-
agent="Mozilla/5.0 (X11; Linux x86_64; rv:99.0) Gecko/20100101 Firefox/100.0"
255+
firefox_version=$(shuf -i '106-109' -n1)
256+
agent="Mozilla/5.0 (X11; Linux x86_64; rv:${firefox_version}.0) Gecko/20100101 Firefox/${firefox_version}.0"
255257
mode="${ANI_CLI_MODE:-sub}"
256-
media_locale="${ANI_CLI_MEDIA_LOCALE:-en-US}"
257258
download_dir="${ANI_CLI_DOWNLOAD_DIR:-.}"
258259
quality="${ANI_CLI_QUALITY:-best}"
259260
case "$(uname -a)" in

ani-cli.1

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,14 @@ ani-cli v4 uses environment variables to control unstable/untested and niche fea
5454
\fBANI_CLI_MODE\fR
5555
Controls the scraped media's mode, valid options are sub or dub. Default is sub.
5656
.TP
57-
\fBANI_CLI_MEDIA_LOCALE\fR
58-
Controls the scraped media's locale, check allanime for valid options. Default is en-US.
59-
.TP
6057
\fBANI_CLI_DOWNLOAD_DIR\fR
6158
Controls the directory where files are downloaded. Default is the current dir.
6259
.TP
6360
\fBANI_CLI_QUALITY\fR
6461
Controls the scraped media's quality, check allanime for valid options or set to worst/best. Default is best.
6562
.TP
6663
\fBANI_CLI_PLAYER\fR
67-
Sets the player ani-cli uses. Can be debug (print links), download (equivalent to -d), android_mpv (apk and am start), android_vlc (apk and am start), flatpak_mpv (for flatpak) or any player that can play urls. For defaults see working without arguments.
64+
Sets the player ani-cli uses. Can be debug (print links), download (equivalent to -d), android_mpv (apk and am start), android_vlc (apk and am start), flatpak_mpv (for flatpak), catt (for streaming to tv), or any player that can play urls. For defaults see working without arguments.
6865
.TP
6966
\fBANI_CLI_EXTERNAL_MENU\fR
7067
Controls the frontend of ani-cli. Can be 0 (uses fzf) or 1 (uses rofi dmenu). Default is 0.

0 commit comments

Comments
 (0)