Feature: Add Download counts to search result displays and Download sidebar (#1336)

Having the download counts from AA as an input on choosing which of the
many search results to pick for downloading is useful. This PR makes the
downloads numbers available on all the search result pages and also on
the Download sidebar after the user presses a download button for a
Direct Download.

I have also included a SKILL.md and associated download_books.py that
can be used just as a reference or with an LLM harness for automation.
The Downloads info is used by the script to pick which search result to
download out of the many available.

Since a picture is worth a thousand words:

<img width="1225" height="812" alt="search-results-with-downloads"
src="https://github.com/user-attachments/assets/e108ebe2-4cad-45e2-bb6a-d4f49b502de9"
/>

<img width="443" height="267" alt="download-sidebar-with-downloads"
src="https://github.com/user-attachments/assets/9ce9e6c4-dcf5-4f7c-ab22-71850398b534"
/>

Coded with llama.cpp and 🤖
This commit is contained in:
Paul Rimmer authored and GitHub committed 2026-09-17 15:49:57 -04:00
1 parent c6b70a6844
commit 2ed2e9a5d4
21 files changed
+729 -26

No files matched your search

@@ -1,4 +1,5 @@
import type { Book, RequestRecord, StatusData } from '../../types';
import { getDownloadsCount } from '../../types';
import { STATUS_LABELS, isActiveDownloadStatus } from './activityStyles.js';
import type { ActivityItem, ActivityVisualStatus } from './activityTypes';
@@ -87,10 +88,13 @@ export const downloadToActivityItem = (book: Book, statusKey: DownloadStatusKey)
typeof book.request_id === 'number' && Number.isFinite(book.request_id) && book.request_id > 0
? Math.trunc(book.request_id)
: undefined;
const downloadsCount = getDownloadsCount(book);
const downloadsText = downloadsCount != null ? `${downloadsCount.toLocaleString()} downloads` : undefined;
const metaLine = joinMetaParts([
toOptionalText(book.format)?.toUpperCase(),
toOptionalText(book.size),
toOptionalText(book.source_display_name) || toSourceLabel(book.source),
downloadsText,
toOptionalText(book.username),
]);
const progress = getDownloadProgress(visualStatus, book.progress);
@@ -115,6 +119,7 @@ export const downloadToActivityItem = (book: Book, statusKey: DownloadStatusKey)
downloadRetryAvailable,
downloadPath: toOptionalText(book.download_path),
sizeRaw: toOptionalText(book.size),
downloads: downloadsCount ?? undefined,
requestId,
};
};
@@ -32,6 +32,7 @@ export interface ActivityItem {
progress?: number;
progressAnimated?: boolean;
sizeRaw?: string;
downloads?: number;
timestamp: number;
username?: string;
@@ -2,6 +2,7 @@ import { useState } from 'react';
import { useSearchMode } from '../../contexts/SearchModeContext';
import type { Book, ButtonStateInfo } from '../../types';
import { getDownloadsCount } from '../../types';
import { bookSupportsTargets } from '../../utils/bookTargetLoader';
import { BookActionButton } from '../BookActionButton';
import { BookTargetDropdown } from '../BookTargetDropdown';
@@ -210,6 +211,7 @@ export const CardView = ({
<span>{book.size}</span>
</>
)}
{searchMode !== 'universal' && (() => { const d = getDownloadsCount(book); return d != null && d > 0 ? <> <span>•</span> <span>{d.toLocaleString()}</span> </> : null; })()}
</div>
)}
</div>
@@ -2,6 +2,7 @@ import { useState } from 'react';
import { useSearchMode } from '../../contexts/SearchModeContext';
import type { Book, ButtonStateInfo } from '../../types';
import { getDownloadsCount } from '../../types';
import { bookSupportsTargets } from '../../utils/bookTargetLoader';
import { BookActionButton } from '../BookActionButton';
import { BookTargetDropdown } from '../BookTargetDropdown';
@@ -221,6 +222,7 @@ export const CompactView = ({
<span>{book.size}</span>
</>
)}
{(() => { const d = getDownloadsCount(book); return d != null && d > 0 ? <> <span>•</span> <span>{d.toLocaleString()}</span> </> : null; })()}
</div>
)}
@@ -2,6 +2,7 @@ import { useState } from 'react';
import { useSearchMode } from '../../contexts/SearchModeContext';
import type { Book, ButtonStateInfo, DisplayField } from '../../types';
import { getDownloadsCount } from '../../types';
import { bookSupportsTargets } from '../../utils/bookTargetLoader';
import { getFormatColor, getLanguageColor } from '../../utils/colorMaps';
import { BookActionButton } from '../BookActionButton';
@@ -167,7 +168,7 @@ export const ListView = ({
className={`grid w-full items-center gap-2 sm:gap-x-0.5 sm:gap-y-1 ${
searchMode === 'universal'
? 'grid-cols-[auto_minmax(0,1fr)_auto_auto] sm:grid-cols-[auto_minmax(0,2fr)_minmax(50px,0.25fr)_minmax(90px,0.5fr)_minmax(90px,0.5fr)_minmax(120px,0.7fr)_auto]'
: 'grid-cols-[auto_minmax(0,1fr)_auto_auto] sm:grid-cols-[auto_minmax(0,2fr)_minmax(50px,0.25fr)_minmax(60px,0.3fr)_minmax(60px,0.3fr)_minmax(60px,0.3fr)_auto]'
: 'grid-cols-[auto_minmax(0,1fr)_auto_auto] sm:grid-cols-[auto_minmax(0,2fr)_minmax(50px,0.25fr)_minmax(60px,0.3fr)_minmax(60px,0.3fr)_minmax(60px,0.3fr)_minmax(70px,0.35fr)_auto]'
}`}
>
{/* Thumbnail */}
@@ -287,6 +288,13 @@ export const ListView = ({
</div>
)}
{/* Direct mode: Downloads - Desktop only */}
{searchMode !== 'universal' && (
<div className="hidden justify-center text-xs text-gray-700 sm:flex dark:text-gray-200">
{(() => { const d = getDownloadsCount(book); return d != null && d > 0 ? d.toLocaleString() : '-'; })()}
</div>
)}
{/* Action Buttons */}
<div className="flex flex-row justify-end gap-0.5 sm:gap-1 sm:pr-3">
{bookSupportsTargets(book) && targetProvider && targetBookId && (
+1
View File
@@ -103,6 +103,7 @@ const parseHistoryBook = (value: unknown): Book | null => {
...(typeof value.retry_available === 'boolean'
? { retry_available: value.retry_available }
: {}),
...(typeof value.downloads === 'number' ? { downloads: value.downloads } : {}),
};
};
+1
View File
@@ -540,6 +540,7 @@ export type DownloadReleasePayload = {
format?: string;
size?: string;
size_bytes?: number;
downloads?: number;
download_url?: string;
protocol?: string;
indexer?: string;
+17
View File
@@ -56,6 +56,23 @@ export interface Book {
titles_by_language?: Record<string, string>;
username?: string;
retry_available?: boolean;
downloads?: number;
extra?: Record<string, unknown>;
}
/**
* Extract download count from a book's data.
* Checks both the direct `downloads` field and the `extra.downloads` fallback.
*/
export function getDownloadsCount(book: Book): number | null {
if (book.downloads != null && book.downloads > 0) {
return book.downloads;
}
const extraDownloads = book.extra?.downloads;
if (extraDownloads != null && typeof extraDownloads === 'number' && extraDownloads > 0) {
return extraDownloads;
}
return null;
}
// Status response types
@@ -62,6 +62,7 @@ interface SourceBackedBookData {
language?: unknown;
format?: unknown;
size?: unknown;
downloads?: unknown;
preview?: unknown;
publisher?: unknown;
info?: Record<string, string | string[]>;
@@ -157,6 +158,7 @@ const transformSourceBackedDataToBook = (data: SourceBackedBookData): Book => {
language: toOptionalText(data.language),
format: toOptionalText(data.format),
size: toOptionalText(data.size),
downloads: typeof data.downloads === 'number' ? data.downloads : undefined,
preview: toOptionalText(data.preview),
publisher: toOptionalText(data.publisher),
info: data.info,
@@ -181,6 +183,7 @@ export function transformReleaseToDirectBook(release: Release): Book {
language: release.language || extra.language,
format: release.format,
size: release.size,
downloads: extra.downloads,
preview: extra.preview,
publisher: extra.publisher,
info: parseBookInfo(extra.info),
+10
View File
@@ -30,6 +30,16 @@ export function buildReleaseDownloadPayload(
format: release.format,
size: release.size,
size_bytes: release.size_bytes,
downloads:
typeof release.extra?.downloads === 'number'
? release.extra.downloads
: typeof book.downloads === 'number' && book.downloads > 0
? book.downloads
: typeof book.extra?.downloads === 'number'
? book.extra.downloads
: Array.isArray(book.info?.Downloads) && book.info.Downloads.length > 0
? Number(book.info.Downloads[0]) || 0
: 0,
download_url: release.download_url,
protocol: release.protocol,
indexer: release.indexer,
+24 -17
View File
@@ -95,23 +95,30 @@ export const buildReleaseDataFromMetadataRelease = (
};
};
export const buildReleaseDataFromDirectBook = (book: Book) => {
const source = getBrowseSource(book);
return {
source,
source_id: book.id,
title: book.title || 'Unknown title',
author: book.author,
year: book.year,
format: book.format,
size: book.size,
preview: book.preview,
content_type: 'ebook' as const,
// Browsing a source directly means the book record IS the release record.
language: book.language,
search_mode: 'direct' as const,
};
};
export const buildReleaseDataFromDirectBook = (book: Book) => {
const source = getBrowseSource(book);
const downloads =
typeof book.downloads === 'number' && book.downloads > 0
? book.downloads
: Array.isArray(book.info?.Downloads) && book.info.Downloads.length > 0
? Number(book.info.Downloads[0]) || 0
: 0;
return {
source,
source_id: book.id,
title: book.title || 'Unknown title',
author: book.author,
year: book.year,
format: book.format,
size: book.size,
downloads,
preview: book.preview,
content_type: 'ebook' as const,
// Browsing a source directly means the book record IS the release record.
language: book.language,
search_mode: 'direct' as const,
};
};
export const buildDirectRequestPayload = (book: Book): CreateRequestPayload => {
const bookData = buildDirectBookRequestData(book);