mirror of
https://github.com/Benexl/FastAnime.git
synced 2025-12-12 15:50:01 -08:00
fix(dynamic-search-menu): preview script
This commit is contained in:
@@ -91,16 +91,16 @@ print_kv() {
|
||||
if [ "$padding_len" -lt 1 ]; then
|
||||
padding_len=1
|
||||
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
|
||||
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
|
||||
}
|
||||
|
||||
draw_rule() {
|
||||
ll=2
|
||||
while [ $ll -le $FZF_PREVIEW_COLUMNS ];do
|
||||
echo -n -e "${C_RULE}─${RESET}"
|
||||
echo -n -e "{C_RULE}─{RESET}"
|
||||
((ll++))
|
||||
done
|
||||
echo
|
||||
@@ -156,20 +156,15 @@ if [ -z "$SELECTED_ITEM" ] || [ ! -f "$SEARCH_RESULTS_FILE" ]; then
|
||||
fi
|
||||
exit 0
|
||||
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
|
||||
if command -v jq >/dev/null 2>&1; then
|
||||
# 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[]? |
|
||||
select(
|
||||
((.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)
|
||||
select(.id == ($anime_id | tonumber) )
|
||||
' )
|
||||
else
|
||||
# Fallback to Python for JSON parsing
|
||||
MEDIA_DATA=$(cat "$SEARCH_RESULTS_FILE" | python3 -c "
|
||||
@@ -274,7 +269,7 @@ CACHE_HASH=$(generate_sha256 "$SELECTED_ITEM")
|
||||
|
||||
# Try to show image if available
|
||||
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 [ ! -f "$image_file" ] && [ -n "$COVER_IMAGE" ]; then
|
||||
|
||||
@@ -76,7 +76,7 @@ if command -v jq >/dev/null 2>&1; then
|
||||
"❌ No results found"
|
||||
else
|
||||
.data.Page.media[] |
|
||||
((.title.english // .title.romaji // .title.native // "Unknown") +
|
||||
"[" + (.id|tostring) + "] " +((.title.english // .title.romaji // .title.native // "Unknown") +
|
||||
" (" + (.startDate.year // "Unknown" | tostring) + ") " +
|
||||
"[" + (.status // "Unknown") + "] - " +
|
||||
((.genres[:3] // []) | join(", ") | if . == "" then "Unknown" else . end))
|
||||
|
||||
@@ -122,7 +122,10 @@ class PreviewContext:
|
||||
return get_character_preview(choice_map, config)
|
||||
|
||||
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:
|
||||
"""Get airing schedule preview script with managed workers."""
|
||||
if not self._manager:
|
||||
@@ -152,8 +155,8 @@ class PreviewContext:
|
||||
if self._manager:
|
||||
return self._manager.get_status()
|
||||
return {
|
||||
"preview_worker": None,
|
||||
"episode_worker": None,
|
||||
"preview_worker": None,
|
||||
"episode_worker": None,
|
||||
"review_worker": None,
|
||||
"character_worker": None,
|
||||
"airing_schedule_worker": None,
|
||||
@@ -430,7 +433,9 @@ def get_character_preview(choice_map: Dict[str, Character], config: AppConfig) -
|
||||
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.
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user