fix(dynamic-search-menu): preview script

This commit is contained in:
Benexl
2025-07-28 15:20:05 +03:00
parent d8804c711e
commit ef4a850d75
3 changed files with 19 additions and 19 deletions

View File

@@ -91,16 +91,16 @@ print_kv() {
if [ "$padding_len" -lt 1 ]; then if [ "$padding_len" -lt 1 ]; then
padding_len=1 padding_len=1
value=$(echo $value| fold -s -w "$((WIDTH - key_len - 3))") value=$(echo $value| fold -s -w "$((WIDTH - key_len - 3))")
printf "${C_KEY}%s:${RESET}%*s%s\\n" "$key" "$padding_len" "" " $value" printf "{C_KEY}%s:{RESET}%*s%s\\n" "$key" "$padding_len" "" " $value"
else else
printf "${C_KEY}%s:${RESET}%*s%s\\n" "$key" "$padding_len" "" " $value" printf "{C_KEY}%s:{RESET}%*s%s\\n" "$key" "$padding_len" "" " $value"
fi fi
} }
draw_rule() { draw_rule() {
ll=2 ll=2
while [ $ll -le $FZF_PREVIEW_COLUMNS ];do while [ $ll -le $FZF_PREVIEW_COLUMNS ];do
echo -n -e "${C_RULE}${RESET}" echo -n -e "{C_RULE}─{RESET}"
((ll++)) ((ll++))
done done
echo echo
@@ -156,20 +156,15 @@ if [ -z "$SELECTED_ITEM" ] || [ ! -f "$SEARCH_RESULTS_FILE" ]; then
fi fi
exit 0 exit 0
fi fi
# HACK: the extra dot is cause theres weird character at start
ANIME_ID=$(echo "$SELECTED_ITEM"|sed -E 's/^[[:space:]]+|[[:space:]]+$//g'|sed -E 's/^.\[([0-9]+)\] .*/\1/g')
# Parse the search results JSON and find the matching item # Parse the search results JSON and find the matching item
if command -v jq >/dev/null 2>&1; then if command -v jq >/dev/null 2>&1; then
# Use jq for faster and more reliable JSON parsing # Use jq for faster and more reliable JSON parsing
MEDIA_DATA=$(cat "$SEARCH_RESULTS_FILE" | jq --arg selected "$SELECTED_ITEM" ' MEDIA_DATA=$(cat "$SEARCH_RESULTS_FILE" | jq --arg anime_id "$ANIME_ID" '
.data.Page.media[]? | .data.Page.media[]? |
select( select(.id == ($anime_id | tonumber) )
((.title.english // .title.romaji // .title.native // "Unknown") + ' )
" (" + (.startDate.year // "Unknown" | tostring) + ") " +
"[" + (.status // "Unknown") + "] - " +
((.genres[:3] // []) | join(", ") | if . == "" then "Unknown" else . end)
) == $selected
)
' 2>/dev/null)
else else
# Fallback to Python for JSON parsing # Fallback to Python for JSON parsing
MEDIA_DATA=$(cat "$SEARCH_RESULTS_FILE" | python3 -c " MEDIA_DATA=$(cat "$SEARCH_RESULTS_FILE" | python3 -c "
@@ -274,7 +269,7 @@ CACHE_HASH=$(generate_sha256 "$SELECTED_ITEM")
# Try to show image if available # Try to show image if available
if [ "{PREVIEW_MODE}" = "full" ] || [ "{PREVIEW_MODE}" = "image" ]; then if [ "{PREVIEW_MODE}" = "full" ] || [ "{PREVIEW_MODE}" = "image" ]; then
image_file="${IMAGE_CACHE_PATH}${PATH_SEP}${CACHE_HASH}.png" image_file="{IMAGE_CACHE_PATH}{PATH_SEP}${CACHE_HASH}.png"
# If image not cached and we have a URL, try to download it quickly # If image not cached and we have a URL, try to download it quickly
if [ ! -f "$image_file" ] && [ -n "$COVER_IMAGE" ]; then if [ ! -f "$image_file" ] && [ -n "$COVER_IMAGE" ]; then

View File

@@ -76,7 +76,7 @@ if command -v jq >/dev/null 2>&1; then
"❌ No results found" "❌ No results found"
else else
.data.Page.media[] | .data.Page.media[] |
((.title.english // .title.romaji // .title.native // "Unknown") + "[" + (.id|tostring) + "] " +((.title.english // .title.romaji // .title.native // "Unknown") +
" (" + (.startDate.year // "Unknown" | tostring) + ") " + " (" + (.startDate.year // "Unknown" | tostring) + ") " +
"[" + (.status // "Unknown") + "] - " + "[" + (.status // "Unknown") + "] - " +
((.genres[:3] // []) | join(", ") | if . == "" then "Unknown" else . end)) ((.genres[:3] // []) | join(", ") | if . == "" then "Unknown" else . end))

View File

@@ -122,7 +122,10 @@ class PreviewContext:
return get_character_preview(choice_map, config) return get_character_preview(choice_map, config)
def get_airing_schedule_preview( def get_airing_schedule_preview(
self, schedule_result: AiringScheduleResult, config: AppConfig, anime_title: str = "Anime" self,
schedule_result: AiringScheduleResult,
config: AppConfig,
anime_title: str = "Anime",
) -> str: ) -> str:
"""Get airing schedule preview script with managed workers.""" """Get airing schedule preview script with managed workers."""
if not self._manager: if not self._manager:
@@ -152,8 +155,8 @@ class PreviewContext:
if self._manager: if self._manager:
return self._manager.get_status() return self._manager.get_status()
return { return {
"preview_worker": None, "preview_worker": None,
"episode_worker": None, "episode_worker": None,
"review_worker": None, "review_worker": None,
"character_worker": None, "character_worker": None,
"airing_schedule_worker": None, "airing_schedule_worker": None,
@@ -430,7 +433,9 @@ def get_character_preview(choice_map: Dict[str, Character], config: AppConfig) -
return preview_script return preview_script
def get_airing_schedule_preview(schedule_result: AiringScheduleResult, config: AppConfig, anime_title: str = "Anime") -> str: def get_airing_schedule_preview(
schedule_result: AiringScheduleResult, config: AppConfig, anime_title: str = "Anime"
) -> str:
""" """
Generate the generic loader script for airing schedule previews and start background caching. Generate the generic loader script for airing schedule previews and start background caching.
""" """