Documentation Index Fetch the complete documentation index at: https://mintlify.com/ragaeeb/shamela/llms.txt
Use this file to discover all available pages before exploring further.
Download complete book data including pages and titles from the Shamela library.
Basic Download as JSON
Download a book as JSON:
import { downloadBook } from 'shamela' ;
const bookId = 26592 ;
await downloadBook ( bookId , {
outputFile: { path: `./book_ ${ bookId } .json` }
});
Download as SQLite
Download a book as a SQLite database:
import { downloadBook } from 'shamela' ;
const bookId = 26592 ;
await downloadBook ( bookId , {
outputFile: { path: `./book_ ${ bookId } .db` }
});
Optimize downloads by pre-fetching metadata to avoid extra HTTP calls:
import { getBookMetadata , downloadBook } from 'shamela' ;
const bookId = 26592 ;
// Fetch metadata first
const metadata = await getBookMetadata ( bookId );
console . log ( `Major release: ${ metadata . majorRelease } ` );
console . log ( `Major release URL: ${ metadata . majorReleaseUrl } ` );
if ( metadata . minorReleaseUrl ) {
console . log ( `Minor release available: ${ metadata . minorReleaseUrl } ` );
}
// Use metadata in download
await downloadBook ( bookId , {
bookMetadata: metadata ,
outputFile: { path: `./book_ ${ bookId } .json` }
});
Check for Book Updates
Check if there are updates for a specific book version:
import { getBookMetadata } from 'shamela' ;
const bookId = 26592 ;
// Check for updates from version 1.0
const metadata = await getBookMetadata ( bookId , {
majorVersion: 1 ,
minorVersion: 0
});
console . log ( `Latest major release: ${ metadata . majorRelease } ` );
if ( metadata . minorRelease ) {
console . log ( `Latest minor release: ${ metadata . minorRelease } ` );
}
type GetBookMetadataResponsePayload = {
majorRelease : number ; // Major version number
majorReleaseUrl : string ; // Download URL for major release
minorRelease ?: number ; // Minor version number (optional)
minorReleaseUrl ?: string ; // Download URL for minor release (optional)
};
Example Response {
"majorRelease" : 2 ,
"majorReleaseUrl" : "https://shamela.ws/api/books/26592/download/2.zip" ,
"minorRelease" : 1 ,
"minorReleaseUrl" : "https://shamela.ws/api/books/26592/patch/1.zip"
}
Get Book Cover URL
Generate the URL for a book’s cover image:
import { getCoverUrl , getMaster } from 'shamela' ;
const master = await getMaster ();
// Generate cover URLs for all books
master . books . forEach ( book => {
const coverUrl = getCoverUrl ( book . id );
console . log ( ` ${ book . name } : ${ coverUrl } ` );
});
Single Book Cover
import { getCoverUrl } from 'shamela' ;
const coverUrl = getCoverUrl ( 26592 );
console . log ( coverUrl );
// Output: "https://shamela.ws/covers/26592.jpg"
Download Multiple Books
Batch download multiple books:
import { downloadBook } from 'shamela' ;
const bookIds = [ 26592 , 12345 , 67890 ];
for ( const bookId of bookIds ) {
try {
await downloadBook ( bookId , {
outputFile: { path: `./books/ ${ bookId } .json` }
});
console . log ( `Downloaded book ${ bookId } ` );
} catch ( error ) {
console . error ( `Failed to download book ${ bookId } :` , error );
}
}
The output format is automatically detected from the file extension:
import { downloadBook } from 'shamela' ;
const bookId = 26592 ;
// SQLite format (.db or .sqlite)
await downloadBook ( bookId , {
outputFile: { path: './book.db' } // SQLite
});
await downloadBook ( bookId , {
outputFile: { path: './book.sqlite' } // SQLite
});
// JSON format
await downloadBook ( bookId , {
outputFile: { path: './book.json' } // JSON
});
The library automatically handles patches. If a minor release is available, it will be applied on top of the major release.