Skip to content

Add lb search support#140

Merged
holta merged 8 commits intomasterfrom
deldesir-patch-1
May 29, 2024
Merged

Add lb search support#140
holta merged 8 commits intomasterfrom
deldesir-patch-1

Conversation

@deldesir
Copy link
Collaborator

@deldesir deldesir commented Mar 22, 2024

🚀 Pull Request Overview:
With this PR, lb-wrapper can be used with the search command provided a search term is specified as an argument. For example:

lb-wrapper search "your search term"

This will execute the xklb search command with the provided search term

📋 Checklist:

root@box:~# lb-wrapper search welcome 
/usr/local/bin/lb
2024-03-22 08:10:07 - [Info] Running xklb command: lb search /library/calibre-web/xklb-metadata.db welcome
3 captions
Borges et la Machine à Fiction (CMS #1) - /library/calibre-web/Artificialis Code/Borges et la Machine à Fiction (CMS #1) (6)/Borges et la Machine à Fiction (CMS #1) - Artificialis Code.mp4
    0:01 friends fans of friends fans of artificial intelligence welcome to a new,. artificial intelligence welcome to a new,
         artificial intelligence welcome to a new, somewhat special video you can

I-JEPA: révolutionner l'IA par l'apprentissage auto-supervisé (5mn1p) - /library/calibre-web/Artificialis Code/I-JEPA_ révolutionner l'IA par l'apprentissage auto-supervisé (5mn1p) (5)/I-JEPA_ révolutionner l'IA par l'apprenti - Artificialis Code.mp4
    0:01 dear friend artificial intelligence enthusiast dear friend artificial intelligence enthusiast welcome to a new. welcome to a
         new welcome to a new 5-minute episode for a paper

Sur les dangers des perroquets stochastiques (5mn1p) - /library/calibre-web/Artificialis Code/Sur les dangers des perroquets stochastiques (5mn1p) (7)/Sur les dangers des perroquets stochastiqu - Artificialis Code.mp4
    0:02 friend artificial intelligence lover friend artificial intelligence lover welcome to this new video. welcome to this new
         video welcome to this new video today it's the first episode

yt_dlp_rc: 0
2024-03-22 08:10:08 - [Info] lb-wrapper's xklb command (search) completed successfully.

📌 Testing scenarios:
See Issue #97

cc @EMG70

@deldesir deldesir marked this pull request as draft March 22, 2024 09:18
@deldesir deldesir requested a review from holta March 22, 2024 12:13
@deldesir deldesir self-assigned this Mar 22, 2024
@deldesir deldesir added the enhancement New feature or request label Mar 22, 2024
@deldesir deldesir marked this pull request as ready for review March 22, 2024 12:13
@holta
Copy link
Member

holta commented Mar 22, 2024

@deldesir
Copy link
Collaborator Author

deldesir commented Mar 22, 2024

No, but #141 will require it.

@deldesir
Copy link
Collaborator Author

Related to #152

Copy link
Collaborator Author

@deldesir deldesir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR introduces the "search" argument which is used in background when a user enter something in the search field in Calibre-Web UI. This can be tested in terminal with lb-wrapper search <terms>.

Comment on lines +67 to +69
# adjust above line to also reroute the return code of the underlying command as a line saying "return code: 0" or "return code: 1" or "return code: 2" etc.
> >(while read -r line; do if [[ $line == downloading* || $line =~ \[https://.*\]:* ]] || [[ $line == "yt_dlp_rc: "* ]]; then echo "$line"; else log "Info" "$line"; fi; done) \
2> >(while read -r line; do if [[ $line == downloading* || $line =~ \[https://.*\]:* ]]; then echo "$line"; else log "Debug" "$line" 1>&2; fi; done; echo "yt_dlp_rc: $?" 1>&2) &
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to understand this.

@deldesir is the following closer to the truth, of what we're trying to accomplish?

Suggested change
# adjust above line to also reroute the return code of the underlying command as a line saying "return code: 0" or "return code: 1" or "return code: 2" etc.
> >(while read -r line; do if [[ $line == downloading* || $line =~ \[https://.*\]:* ]] || [[ $line == "yt_dlp_rc: "* ]]; then echo "$line"; else log "Info" "$line"; fi; done) \
2> >(while read -r line; do if [[ $line == downloading* || $line =~ \[https://.*\]:* ]]; then echo "$line"; else log "Debug" "$line" 1>&2; fi; done; echo "yt_dlp_rc: $?" 1>&2) &
# adjust above line to also reroute the return code of the underlying command as a line saying "xklb_rc: 0" or "xklb_rc: 1" or "xklb_rc: 2" etc.
> >(while read -r line; do if [[ $line == downloading* || $line =~ \[https://.*\]:* || $line == "xklb_rc: "* ]]; then echo "$line"; else log "Info" "$line"; fi; done) \
2> >(while read -r line; do if [[ $line == downloading* || $line =~ \[https://.*\]:* ]]; then echo "$line"; else log "Debug" "$line" 1>&2; fi; done; echo "xklb_rc: $?" 1>&2) &

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to make lb-wrapper to report underlying yt-dlp return code. We already had $rc for xklb.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return code $? on Line 69 is arising from what command exactly?

(This definitely doesn't look like yt-dlp's return code.)

In any case, please clear up what $? is really doing here, and why?
(And how this was tested please if possible!)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the exit status of the last underlying command (yt-dlp) executed by xklb.

Copy link
Collaborator Author

@deldesir deldesir May 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could see it's yt-dlp because I could reroute its output. This exit status code is not doing anything useful here. It was me debugging yt-dlp and I forgot to remove this code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This exit status code is not doing anything useful here. It was me debugging yt-dlp and I forgot to remove this code.

  1. Please remove any temporary code and confirm.

  2. Please also fix Lines 56, 58 and 60 which contain (former variable) XKLB_EXECUTABLE.

Thanks!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Temporary code removed.

Comment on lines +85 to +98
case $rc in
0)
log "Info" "lb-wrapper's xklb command (${XKLB_INTERNAL_CMD}) completed successfully."
exit 0
;;
1)
log "Error" "Error $rc occurred while running lb-wrapper's xklb commands."
exit 1
;;
*)
log "Error" "Unknown error occurred while running lb-wrapper's xklb commands. Return code: $rc"
exit $rc
;;
esac
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is a 3-way case statement really necessary?

(What's so special about Return Code 1?)

Can we instead simplify, as follows?

Suggested change
case $rc in
0)
log "Info" "lb-wrapper's xklb command (${XKLB_INTERNAL_CMD}) completed successfully."
exit 0
;;
1)
log "Error" "Error $rc occurred while running lb-wrapper's xklb commands."
exit 1
;;
*)
log "Error" "Unknown error occurred while running lb-wrapper's xklb commands. Return code: $rc"
exit $rc
;;
esac
if [ $rc -eq 0 ]; then
log "Info" "lb-wrapper's xklb command (${XKLB_INTERNAL_CMD}) completed successfully."
else
log "Error" "Error $rc occurred while running lb-wrapper's xklb commands."
exit $rc
fi

Copy link
Collaborator Author

@deldesir deldesir May 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing special. But exit 0 is missing in the if statement. So I suggest:

Suggested change
case $rc in
0)
log "Info" "lb-wrapper's xklb command (${XKLB_INTERNAL_CMD}) completed successfully."
exit 0
;;
1)
log "Error" "Error $rc occurred while running lb-wrapper's xklb commands."
exit 1
;;
*)
log "Error" "Unknown error occurred while running lb-wrapper's xklb commands. Return code: $rc"
exit $rc
;;
esac
if [ $rc -eq 0 ]; then
log "Info" "lb-wrapper's xklb command (${XKLB_INTERNAL_CMD}) completed successfully."
else
log "Error" "Error $rc occurred while running lb-wrapper's xklb commands."
exit $rc
fi

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exit $rc is the same as exit 0 on Line 87, and doesn't do anything useful.

(Programs always exit with return code 0, regardless, when they complete successfully.)

Recap: please remove exit $rc on Line 87, ok?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Thanks for clarifying.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@holta
Copy link
Member

holta commented May 2, 2024

Looks good, and sorry if that was a bit of a distraction at the bottom of scripts/lb-wrapper !

@deldesir, the key question (above) is what $? is doing on Line 69, when you have a sec: (explain &/or show test results?!)

@holta
Copy link
Member

holta commented May 2, 2024

@deldesir please resolve the simple merge conflict, arising from PR #159 having just been merged?

Thanks!!

@deldesir
Copy link
Collaborator Author

deldesir commented May 2, 2024

Done

@holta
Copy link
Member

holta commented May 4, 2024

What testing does this most need?

(Should this be tested together with... ?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants