forked from janeczku/calibre-web
-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor lb-wrapper for command separation #110
Merged
Merged
Changes from 5 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
83b9187
Refactor lb-wrapper for command separation
deldesir 2c0bb32
Enforce exactly 2 input parameters : scripts/lb-wrapper
deldesir 322c440
Keep all CONSTANTS near the top of the script
deldesir 0fd0292
Log "Two arguments are required..." : scripts/lb-wrapper
deldesir e05ac28
Add missing quotes
deldesir 4c67670
Remove comments: lb-wrapper
deldesir d5abb0c
XKLB_FULL_CMD > xklb_full_cmd: scripts/lb-wrapper
deldesir 57e9ac3
Ensure xklb is installed
deldesir f4384ad
Adjust xklb_full_cmd : scripts/lb-wrapper
deldesir f8ddeb6
scripts/lb-wrapper: Fix 'lb dl' command
holta ed23aec
scripts/lb-wrapper: Clean & clarify
holta 1c2e886
lb-wrapper: Restore damage test for "xklb could not be found"
holta 4ad08eb
lb-wrapper: Articulating Intent (AI!) of PR #110
holta 31a166b
lb-wrapper: Explain $1 param (XKLB_INTERNAL_CMD)
holta b9a4392
Output xklb result to know when the download is done
deldesir File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,8 @@ XKLB_EXECUTABLE="${XKLB_EXECUTABLE:-lb}" | |
VERBOSITY="-vv" | ||
TMP_DOWNLOADS_DIR="/library/downloads/calibre-web" | ||
XKLB_DB_FILE="/library/calibre-web/xklb-metadata.db" | ||
URL="$1" | ||
XKLB_INTERNAL_CMD="$1" | ||
URL="$2" # Use $2 for the URL argument | ||
|
||
# Or download largest possible HD-style / UltraHD videos, to try to force | ||
# out-of-memory "502 Bad Gateway" for testing of issues like #37 and #79 | ||
|
@@ -16,7 +17,6 @@ XKLB_FULL_CMD="${XKLB_EXECUTABLE} tubeadd ${XKLB_DB_FILE} ${URL} ${VERBOSITY} \ | |
&& ${XKLB_EXECUTABLE} dl ${XKLB_DB_FILE} --prefix ${TMP_DOWNLOADS_DIR} \ | ||
--video ${URL} ${FORMAT_OPTIONS} --write-thumbnail ${VERBOSITY}" | ||
|
||
|
||
mkdir -p ${TMP_DOWNLOADS_DIR} | ||
|
||
# Function to log messages e.g. w/ level "Info", "Warning" or "Error" | ||
|
@@ -26,8 +26,8 @@ log() { | |
echo "$(date +'%Y-%m-%d %H:%M:%S') - [$level] $message" | tee -a ${LOG_FILE} | ||
} | ||
|
||
if [ $# -eq 0 ]; then | ||
log "Error" "No arguments provided. Please provide a URL to download." | ||
if [ $# -ne 2 ]; then | ||
log "Error" "Two arguments are required. Please provide a command (tubeadd/dl) and a URL." | ||
exit 1 | ||
fi | ||
|
||
|
@@ -40,21 +40,30 @@ fi | |
# exit 1 | ||
# fi | ||
|
||
if ! command -v "${XKLB_EXECUTABLE}"; then | ||
log "Error" "xklb could not be found. Please install xklb and try again." | ||
if [ "$XKLB_INTERNAL_CMD" == "tubeadd" ]; then | ||
XKLB_FULL_CMD="${XKLB_FULL_CMD%%&&*}" | ||
elif [ "$XKLB_INTERNAL_CMD" == "dl" ]; then | ||
XKLB_FULL_CMD="${XKLB_FULL_CMD##*&& }" | ||
else | ||
log "Error" "Invalid command. Please choose 'tubeadd' or 'dl'." | ||
exit 1 | ||
fi | ||
|
||
# 2024-01-21: Not needed as XKLB reports its own version# to /var/log/xklb.log | ||
# log "Info" "xklb version: $(${XKLB_EXECUTABLE} --version)" | ||
|
||
log "Info" "Running xklb commands: ${XKLB_FULL_CMD}" | ||
# 2024-01-24: Not needed as we don't discard the database anymore | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
# if mv ${XKLB_DB_FILE} ${XKLB_DB_FILE}.$(date +%F_%T_%Z) 2> /dev/null; then | ||
# log "Info" "Old ${XKLB_DB_FILE} moved aside." | ||
# fi | ||
|
||
log "Info" "Running xklb command: ${XKLB_FULL_CMD}" | ||
|
||
# >(...) "process substitution" explained at https://unix.stackexchange.com/a/324170 | ||
# 1>&2 redirect back-to-STDERR to avoid nested (repeat) logging, explained at https://stackoverflow.com/a/15936384 | ||
eval "${XKLB_FULL_CMD}" \ | ||
> >(while read -r line; do if [[ $line == downloading* ]]; then echo "$line"; else log "Info" "$line"; fi; done) \ | ||
2> >(while read -r line; do if [[ $line == downloading* ]]; then echo "$line"; else log "Debug" "$line" 1>&2; fi; done) & | ||
> >(while read -r line; do if [[ $line == downloading* ]]; then echo "$line"; else log "Info" "$line"; fi; done) \ | ||
2> >(while read -r line; do if [[ $line == downloading* ]]; then echo "$line"; else log "Debug" "$line" 1>&2; fi; done) & | ||
# 2024-01-11: HOW THIS WORKS... | ||
# 0) xklb sends a flood of yt-dlp status message lines like "downloading 59.8% 2.29MiB/s" to STDERR. | ||
# 1) Then, "2> >(...)" reroutes (only those raw lines!) to STDIN, instead of logging them (as "Debug" lines). | ||
|
@@ -71,7 +80,7 @@ rc=$? | |
|
||
# Check return code (exit status) | ||
if [ $rc -eq 0 ]; then | ||
log "Info" "lb-wrapper's xklb commands (download) completed successfully." | ||
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 1 | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Validation on Lines 43-44 should definitely be restored in my opinion:
(...followed by a blank line if possible!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done