This feature enhances BiblioDrift's AI-first book discovery by analyzing GoodReads reviews to determine book "mood" and emotional tone. It provides users with deeper insights into books through sentiment analysis and mood categorization.
- Sentiment Analysis: Uses VADER and TextBlob to analyze review sentiment
- Mood Categories: Detects 10 distinct moods:
cozy- Warm, comforting readsdark- Grim, disturbing themesmysterious- Suspenseful, intriguing plotsromantic- Love stories and relationshipsadventurous- Action-packed journeysmelancholy- Bittersweet, nostalgic tonesuplifting- Inspiring, hopeful narrativesintense- Emotionally powerful storieswhimsical- Quirky, charming talesthought-provoking- Deep, philosophical works
- Mood Tags: Color-coded tags on book covers
- Sentiment Bars: Visual representation of overall sentiment
- Detailed Analysis Modal: In-depth mood breakdown with statistics
- Smart Vibe Generation: Combines GoodReads analysis with fallback AI
- BiblioDrift-Style Descriptions: Generates cozy, bookstore-like recommendations
- Caching System: Stores analyses to avoid re-scraping
class GoodReadsReviewScraper:
- search_book_by_title() # Find books on GoodReads
- scrape_reviews() # Extract review text and ratings
- get_book_reviews() # Complete workflowclass BookMoodAnalyzer:
- analyze_sentiment() # VADER + TextBlob analysis
- extract_mood_keywords() # Keyword-based mood detection
- determine_primary_mood() # Overall mood determination
- generate_bibliodrift_vibe() # Custom vibe generationclass AIBookService:
- analyze_book_mood() # Complete mood analysis
- _load_cache() / _save_cache() # Caching systemGET /- API documentation and endpoint list (visit in browser)GET /api/v1/health- Health checkPOST /api/v1/analyze-mood- Full mood analysis (POST only)POST /api/v1/mood-tags- Quick mood tags (POST only)POST /api/v1/generate-note- Enhanced note generation (POST only)POST /api/v1/chat- Chat with bookseller (POST only)
Note: POST-only endpoints will return 405 Method Not Allowed when accessed via browser GET requests. This is expected behavior.
- Async Mood Loading: Fetches mood data for each book
- Visual Mood Tags: Displays mood indicators on covers
- Interactive Modal: Detailed mood analysis popup
- Fallback System: Graceful degradation when API unavailable
- Mood-Specific Colors: Color-coded mood categories
- Responsive Modal: Mobile-friendly mood analysis display
- Smooth Animations: Polished user interactions
# Using the setup script (recommended)
python setup_mood_analysis.py
# Or manually
pip install -r requirements.txtpython app.pyServer runs on http://localhost:5000
Important for Developers:
- Visit
http://localhost:5000/in your browser to see available API endpoints and usage examples - All mood analysis endpoints are POST-only - visiting them in browser will return 405 Method Not Allowed (this is expected)
- Use curl, Postman, or the frontend JavaScript to test the APIs
Open index.html in your browser. The frontend will automatically connect to the backend for mood analysis.
- Browse Books: Mood tags appear automatically on book covers
- View Details: Click books to see AI-generated vibes enhanced with mood data
- Analyze Mood: Click the brain icon for detailed mood analysis
- Search by Mood: Use emotional search terms like "cozy mystery" or "uplifting romance"
Important: All endpoints except / and /api/v1/health require POST requests with JSON body.
Analyze Book Mood:
# Using curl (recommended for testing)
curl -X POST http://localhost:5000/api/v1/analyze-mood \
-H "Content-Type: application/json" \
-d '{"title": "The Seven Husbands of Evelyn Hugo", "author": "Taylor Jenkins Reid"}'
# Using JavaScript (frontend integration)
const response = await fetch('http://localhost:5000/api/v1/analyze-mood', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
title: "The Seven Husbands of Evelyn Hugo",
author: "Taylor Jenkins Reid"
})
});
const data = await response.json();Get Quick Mood Tags:
# Using curl
curl -X POST http://localhost:5000/api/v1/mood-tags \
-H "Content-Type: application/json" \
-d '{"title": "Where the Crawdads Sing", "author": "Delia Owens"}'
# Using JavaScript
const response = await fetch('http://localhost:5000/api/v1/mood-tags', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
title: "Where the Crawdads Sing",
author: "Delia Owens"
})
});python test_mood_analysis.py- Backend: Use curl or Postman to test API endpoints
- Frontend: Open browser developer tools to monitor API calls
- Integration: Test complete workflow from book search to mood display
- Local Cache: Mood analyses cached in
mood_cache.json - Cache Keys: Based on
title|authorcombination - Persistence: Survives server restarts
- Respectful Scraping: 1-3 second delays between requests
- Limited Reviews: Maximum 15-20 reviews per book
- Error Handling: Graceful fallbacks when scraping fails
- Primary: GoodReads mood analysis
- Secondary: Description-based AI generation
- Tertiary: Static fallback vibes
# Optional: Customize API endpoints
MOOD_API_BASE=http://localhost:5000/api/v1
GOODREADS_DELAY_MIN=1 # Minimum delay between requests
GOODREADS_DELAY_MAX=3 # Maximum delay between requestsEdit mood_keywords dictionary in mood_analyzer.py:
self.mood_keywords = {
'cozy': ['cozy', 'warm', 'comfort', ...],
'dark': ['dark', 'grim', 'disturbing', ...],
# Add custom moods here
}"No reviews found"
- Book may not exist on GoodReads
- Title/author spelling may be incorrect
- GoodReads may be blocking requests (try different book)
"Mood analysis not available"
- Backend server may not be running
- Check
http://localhost:5000/api/v1/health(GET request) - Don't visit POST endpoints in browser - they will return 405 Method Not Allowed (expected behavior)
- Use curl or the frontend JavaScript to test POST endpoints
- Verify CORS settings for cross-origin requests
Slow performance
- Enable caching (should be automatic)
- Reduce
max_reviewsparameter - Check network connection
Enable debug logging:
import logging
logging.basicConfig(level=logging.DEBUG)- Add keywords to
mood_keywordsinmood_analyzer.py - Add CSS styling in
style.css(.mood-{name}class) - Update documentation
- Experiment with different sentiment libraries
- Adjust mood keyword weights
- Fine-tune vibe generation logic
- Add mood filtering to search
- Create mood-based book recommendations
- Implement mood trend visualization
- Mood-Based Search: Filter books by detected moods
- Trend Analysis: Track mood popularity over time
- User Preferences: Learn user mood preferences
- Social Features: Share mood analyses with friends
- Database Integration: Replace JSON cache with PostgreSQL
- Machine Learning: Train custom mood classification models
- Real-time Updates: WebSocket-based live mood updates
- Performance: Async processing and background tasks
This feature is part of BiblioDrift and follows the same MIT License.
- VADER Sentiment: Hutto, C.J. & Gilbert, E.E. (2014)
- TextBlob: Steven Loria and contributors
- GoodReads: Book data and review content
- BiblioDrift Community: Feature inspiration and feedback