Closed 0next closed 4 months ago
let me spin up my freebsd VM.
we had this issue before. the bsd cut
does not act identical to gnu variant
ah, yes it's there in logs sent above
printf %s wm2zBXuqhdKM7L7ALtSerial Experiments Lain (13 episodes)
cut -f1 #this didn't work properly on BSD
id=wm2zBXuqhdKM7L7ALtSerial Experiments Lain (13 episodes) #should be wm2zBXuqhdKM7L7AL
episodes_list wm2zBXuqhdKM7L7ALtSerial Experiments Lain (13 episodes) #should be wm2zBXuqhdKM7L7AL
ep_list=
[ -z ]
printf %s
nth Select episode: -m
ep_no=
[ -z ]
exit 1
ah, yes it's there in logs sent above
printf %s wm2zBXuqhdKM7L7ALtSerial Experiments Lain (13 episodes) cut -f1 #this didn't work properly on BSD id=wm2zBXuqhdKM7L7ALtSerial Experiments Lain (13 episodes) #should be wm2zBXuqhdKM7L7AL episodes_list wm2zBXuqhdKM7L7ALtSerial Experiments Lain (13 episodes) #should be wm2zBXuqhdKM7L7AL ep_list= [ -z ] printf %s nth Select episode: -m ep_no= [ -z ] exit 1
Can you check if it works with a space? Like cut -f 1
I'm surprised we don't have spaces in there
From man 1p cut
Hey there, another OpenBSD user out there, after a few hours of debugging I see that the first cause is not the cut
itself but rather sed
on line 190 which uses \t
to insert tab, on which the next cut
relies. While it works everywhere else, it somehow does not on OpenBSD, since \t
inserts literal letter t
there. If I replace it manually with actual tab
symbol the next error appears from a similar cause on lines 197, 190, 141, 130, 120 and 116, where \n
is used to insert newline. Here the fix would be to use \
and actual newline instead of \n
, like this:
# Before
sed 's|,|\n|g; s|"||g'
# After
sed 's|,|\
|g; s|"||g'
Also seems like grep
isn't doing well with escaped characters either, so I replaced \s
with [[:space:]]
on line 26. Everything tested on the latest commit e90dd8b
on branch master. Below is the diff which sums this all up, I'd make a pull request but not sure if these changes will work on other platforms (and I kinda don't want to test this rn, might do in a few days on different Linux distros) or if there is a more elegant way around this issue since these newlines look really ugly to me at least
--- ani-cli Wed Feb 14 16:10:37 2024
+++ ani-cli-fixed Wed Feb 14 16:09:51 2024
@@ -23,7 +23,7 @@
multi_flag=""
[ $# -ne 1 ] && shift && multi_flag="$1"
line=$(printf "%s" "$stdin" | cut -f1,3 | tr '\t' ' ' | launcher "$multi_flag" "$prompt" | cut -d " " -f 1)
- [ -n "$line" ] && printf "%s" "$stdin" | grep -E '^'"${line}"'($|\s)' | cut -f2,3 || exit 1
+ [ -n "$line" ] && printf "%s" "$stdin" | grep -E '^'"${line}"'($|[[:space:]])' | cut -f2,3 || exit 1
}
die() {
@@ -113,11 +113,14 @@
# extract the video links from reponse of embed urls, extract mp4 links form m3u8 lists
get_links() {
- episode_link="$(curl -e "$allanime_refr" -s "https://${allanime_base}$*" -A "$agent" | sed 's|},{|\n|g' | sed -nE 's|.*link":"([^"]*)".*"resolutionStr":"([^"]*)".*|\2 >\1|p;s|.*hls","url":"([^"]*)".*"hardsub_lang":"en-US".*|\1|p')"
+ episode_link="$(curl -e "$allanime_refr" -s "https://${allanime_base}$*" -A "$agent" | sed 's|},{|\
+|g' | sed -nE 's|.*link":"([^"]*)".*"resolutionStr":"([^"]*)".*|\2 >\1|p;s|.*hls","url":"([^"]*)".*"hardsub_lang":"en-US".*|\1|p')"
+
case "$episode_link" in
*repackager.wixmp.com*)
extract_link=$(printf "%s" "$episode_link" | cut -d'>' -f2 | sed 's|repackager.wixmp.com/||g;s|\.urlset.*||g')
- for j in $(printf "%s" "$episode_link" | sed -nE 's|.*/,([^/]*),/mp4.*|\1|p' | sed 's|,|\n|g'); do
+ for j in $(printf "%s" "$episode_link" | sed -nE 's|.*/,([^/]*),/mp4.*|\1|p' | sed 's|,|\
+|g'); do
printf "%s >%s\n" "$j" "$extract_link" | sed "s|,[^/]*|${j}|g"
done | sort -nr
;;
@@ -127,7 +130,8 @@
else
extract_link=$(printf "%s" "$episode_link" | head -1 | cut -d'>' -f2)
relative_link=$(printf "%s" "$extract_link" | sed 's|[^/]*$||')
- curl -e "$allanime_refr" -s "$extract_link" -A "$agent" | sed 's|^#.*x||g; s|,.*|p|g; /^#/d; $!N; s|\n| >|' | sed "s|>|>${relative_link}|g" | sort -nr
+ curl -e "$allanime_refr" -s "$extract_link" -A "$agent" | sed 's|^#.*x||g; s|,.*|p|g; /^#/d; $!N; s|\
+| >|' | sed "s|>|>${relative_link}|g" | sort -nr
fi
;;
*) [ -n "$episode_link" ] && printf "%s\n" "$episode_link" ;;
@@ -138,7 +142,8 @@
# innitialises provider_name and provider_id. First argument is the provider name, 2nd is the regex that matches that provider's link
provider_init() {
provider_name=$1
- provider_id=$(printf "%s" "$resp" | sed -n "$2" | head -1 | cut -d':' -f2 | sed 's/../&\n/g' | sed 's/^01$/9/g;s/^08$/0/g;s/^05$/=/g;s/^0a$/2/g;s/^0b$/3/g;s/^0c$/4/g;s/^07$/?/g;s/^00$/8/g;s/^5c$/d/g;s/^0f$/7/g;s/^5e$/f/g;s/^17$/\//g;s/^54$/l/g;s/^09$/1/g;s/^48$/p/g;s/^4f$/w/g;s/^0e$/6/g;s/^5b$/c/g;s/^5d$/e/g;s/^0d$/5/g;s/^53$/k/g;s/^1e$/\&/g;s/^5a$/b/g;s/^59$/a/g;s/^4a$/r/g;s/^4c$/t/g;s/^4e$/v/g;s/^57$/o/g;s/^51$/i/g;' | tr -d '\n' | sed "s/\/clock/\/clock\.json/")
+ provider_id=$(printf "%s" "$resp" | sed -n "$2" | head -1 | cut -d':' -f2 | sed 's/../&\
+/g' | sed 's/^01$/9/g;s/^08$/0/g;s/^05$/=/g;s/^0a$/2/g;s/^0b$/3/g;s/^0c$/4/g;s/^07$/?/g;s/^00$/8/g;s/^5c$/d/g;s/^0f$/7/g;s/^5e$/f/g;s/^17$/\//g;s/^54$/l/g;s/^09$/1/g;s/^48$/p/g;s/^4f$/w/g;s/^0e$/6/g;s/^5b$/c/g;s/^5d$/e/g;s/^0d$/5/g;s/^53$/k/g;s/^1e$/\&/g;s/^5a$/b/g;s/^59$/a/g;s/^4a$/r/g;s/^4c$/t/g;s/^4e$/v/g;s/^57$/o/g;s/^51$/i/g;' | tr -d '\n' | sed "s/\/clock/\/clock\.json/")
}
# generates links based on given provider
@@ -187,14 +192,16 @@
search_anime() {
search_gql="query( \$search: SearchInput \$limit: Int \$page: Int \$translationType: VaildTranslationTypeEnumType \$countryOrigin: VaildCountryOriginEnumType ) { shows( search: \$search limit: \$limit page: \$page translationType: \$translationType countryOrigin: \$countryOrigin ) { edges { _id name availableEpisodes __typename } }}"
- curl -e "$allanime_refr" -s -G "${allanime_api}/api" --data-urlencode "variables={\"search\":{\"allowAdult\":false,\"allowUnknown\":false,\"query\":\"$1\"},\"limit\":40,\"page\":1,\"translationType\":\"$mode\",\"countryOrigin\":\"ALL\"}" --data-urlencode "query=$search_gql" -A "$agent" | sed 's|Show|\n|g' | sed -nE "s|.*_id\":\"([^\"]*)\",\"name\":\"([^\"]*)\".*${mode}\":([1-9][^,]*).*|\1\t\2 (\3 episodes)|p"
+ curl -e "$allanime_refr" -s -G "${allanime_api}/api" --data-urlencode "variables={\"search\":{\"allowAdult\":false,\"allowUnknown\":false,\"query\":\"$1\"},\"limit\":40,\"page\":1,\"translationType\":\"$mode\",\"countryOrigin\":\"ALL\"}" --data-urlencode "query=$search_gql" -A "$agent" | sed 's|Show|\
+|g' | sed -nE "s|.*_id\":\"([^\"]*)\",\"name\":\"([^\"]*)\".*${mode}\":([1-9][^,]*).*|\1 \2 (\3 episodes)|p"
}
# get the episodes list of the selected anime
episodes_list() {
episodes_list_gql="query (\$showId: String!) { show( _id: \$showId ) { _id availableEpisodesDetail }}"
- curl -e "$allanime_refr" -s -G "${allanime_api}/api" --data-urlencode "variables={\"showId\":\"$*\"}" --data-urlencode "query=$episodes_list_gql" -A "$agent" | sed -nE "s|.*$mode\":\[([0-9.\",]*)\].*|\1|p" | sed 's|,|\n|g; s|"||g' | sort -n -k 1
+ curl -e "$allanime_refr" -s -G "${allanime_api}/api" --data-urlencode "variables={\"showId\":\"$*\"}" --data-urlencode "query=$episodes_list_gql" -A "$agent" | sed -nE "s|.*$mode\":\[([0-9.\",]*)\].*|\1|p" | sed 's|,|\
+|g; s|"||g' | sort -n -k 1
}
# PLAYING
@0next please let me know if this solution worked for you as well
Thank you for investigating. Please consider making a pull request, we can do linux testing for you. The diff doesn't seem so large that this would be much of an undertaking.
@xezo360hye sorry for the late reply, I've tested the new patch, and it seems to get farther, however doesn't work still.. It now shows fzf, and prompts for what anime I want to watch, but gives me numbers for choice.. And quits right after..
@0next that's strange, it works perfectly fine for me. Could you please upload new debug info with sh -x ani-cli
? Can you also verify if it's (α) working when you download instead of playing, and (β) when you preselect the title and episode with -e NUMBER TITLE
? Also please enclose your terminal output in back quotes so that it does not appear as a list (since every line starts with +
). By the way, it seems there is some other problem with sed
which I noticed just now: it reports error about some "unterminated substitution pattern" while fetching links, but it doesn't break anything so I'll leave it as it is for now, should be investigated later on probably
@port19x since the OP says it doesn't work yet I'll continue working on this and will send pull request when ~I feel like it~ this will work for everyone and not just me
Here's the output of sh -x ani-cli lain:
Yeah I see why it's happening now, for some reasons GitHub decided to replace a literal tab
character with multiple spaces in my diff. Thank you so much, piece of broken software. @0next check out my PR #1296 and try it out, should be fine now since cut -f1
relies on that tab
Nice job! That worked perfectly! Just to be sure I tested it on my T400 running Arch; it worked fine as well! :+1: Now we just need to push the edits...
Thanks for confirming @0next
Version: 4.7.4 OS: OpenBSD 7.4 Shell: zsh Anime: Serial Experiments Lain
Describe the bug When Running on OpenBSD, $ ani-cli lain Prints: "Checking dependencies..." Then returns 1 and quits.
I tried it with Arch Linux and it worked.
When I run " sh -x $(which ani-cli) lain" on it, it returns: