Fix Discogs API integration with proper authentication

- Updated to use python3-discogs-client==2.8 library
- Added environment variable configuration for API keys
- Implemented proper error handling for missing API credentials
- Added .env file for configuration management
- Enhanced search functionality with graceful fallbacks
- Updated README with Discogs API setup instructions
This commit is contained in:
2025-08-11 16:15:15 +07:00
parent 28f927e973
commit d9f184d084
8 changed files with 655 additions and 0 deletions

23
templates/base.html Normal file
View File

@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{% block title %}Media Inventory App{% endblock %}</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="/static/style.css" rel="stylesheet">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container">
<a class="navbar-brand" href="/">📚 Media Inventory</a>
</div>
</nav>
<div class="container mt-4">
{% block content %}{% endblock %}
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

86
templates/index.html Normal file
View File

@@ -0,0 +1,86 @@
{% extends "base.html" %}
{% block title %}Search Media - Media Inventory App{% endblock %}
{% block content %}
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">
<h2 class="card-title mb-0">🔍 Search Media</h2>
</div>
<div class="card-body">
{% if error %}
<div class="alert alert-danger" role="alert">
{{ error }}
</div>
{% endif %}
<form method="post" action="/search">
<div class="mb-3">
<label for="media_type" class="form-label">Media Type</label>
<select class="form-select" id="media_type" name="media_type" required>
<option value="">Select media type...</option>
<option value="book">📚 Book</option>
<option value="vinyl">🎵 Vinyl Record</option>
<option value="cd">💿 CD</option>
<option value="cassette">📼 Cassette</option>
</select>
</div>
<div class="mb-3">
<label for="query" class="form-label">Search Query</label>
<input type="text" class="form-control" id="query" name="query"
placeholder="Enter title, album name, or keywords..." required>
<div class="form-text">
For books: Enter book title or author name<br>
For music: Enter album title or song name
</div>
</div>
<div class="mb-3" id="artist-field" style="display: none;">
<label for="artist" class="form-label">Artist (Optional)</label>
<input type="text" class="form-control" id="artist" name="artist"
placeholder="Enter artist name...">
<div class="form-text">
Helps narrow down music search results
</div>
</div>
<button type="submit" class="btn btn-primary btn-lg w-100">
🔍 Search
</button>
</form>
</div>
</div>
<div class="mt-4">
<div class="card">
<div class="card-header">
<h5 class="card-title mb-0"> How it works</h5>
</div>
<div class="card-body">
<ul class="list-unstyled">
<li><strong>📚 Books:</strong> Searches OpenLibrary.org for book information</li>
<li><strong>🎵 Music (Vinyl/CD/Cassette):</strong> Searches Discogs.com for music releases</li>
<li><strong>🎯 Tips:</strong> Be specific with your search terms for better results</li>
</ul>
</div>
</div>
</div>
</div>
</div>
<script>
document.getElementById('media_type').addEventListener('change', function() {
const artistField = document.getElementById('artist-field');
const selectedType = this.value;
if (selectedType === 'vinyl' || selectedType === 'cd' || selectedType === 'cassette') {
artistField.style.display = 'block';
} else {
artistField.style.display = 'none';
}
});
</script>
{% endblock %}

84
templates/results.html Normal file
View File

@@ -0,0 +1,84 @@
{% extends "base.html" %}
{% block title %}Search Results - Media Inventory App{% endblock %}
{% block content %}
<div class="row">
<div class="col-12">
<div class="d-flex justify-content-between align-items-center mb-4">
<h2>Search Results</h2>
<a href="/" class="btn btn-outline-primary">🔍 New Search</a>
</div>
<div class="alert alert-info">
<strong>Query:</strong> "{{ query }}"
<strong>Media Type:</strong>
{% if media_type == 'book' %}📚 Book{% endif %}
{% if media_type == 'vinyl' %}🎵 Vinyl Record{% endif %}
{% if media_type == 'cd' %}💿 CD{% endif %}
{% if media_type == 'cassette' %}📼 Cassette{% endif %}
</div>
{% if results %}
<div class="row">
{% for item in results %}
<div class="col-md-6 col-lg-4 mb-4">
<div class="card h-100">
{% if item.cover_url %}
<img src="{{ item.cover_url }}" class="card-img-top" alt="Cover"
style="height: 200px; object-fit: cover;">
{% else %}
<div class="card-img-top bg-light d-flex align-items-center justify-content-center"
style="height: 200px;">
<span class="text-muted">No Image</span>
</div>
{% endif %}
<div class="card-body d-flex flex-column">
<h5 class="card-title">{{ item.title }}</h5>
{% if media_type == 'book' %}
<p class="card-text">
<strong>Author:</strong> {{ item.author }}<br>
<strong>Year:</strong> {{ item.year }}<br>
{% if item.isbn %}
<strong>ISBN:</strong> {{ item.isbn }}<br>
{% endif %}
</p>
{% else %}
<p class="card-text">
<strong>Artist:</strong> {{ item.artist }}<br>
<strong>Year:</strong> {{ item.year }}<br>
<strong>Label:</strong> {{ item.label }}<br>
<strong>Format:</strong> {{ item.format }}
</p>
{% endif %}
<div class="mt-auto">
{% if media_type == 'book' and item.openlibrary_url %}
<a href="{{ item.openlibrary_url }}" target="_blank"
class="btn btn-primary btn-sm">
📚 View on OpenLibrary
</a>
{% elif media_type != 'book' and item.discogs_url %}
<a href="{{ item.discogs_url }}" target="_blank"
class="btn btn-primary btn-sm">
🎵 View on Discogs
</a>
{% endif %}
</div>
</div>
</div>
</div>
{% endfor %}
</div>
{% else %}
<div class="alert alert-warning">
<h4>No results found</h4>
<p>Try adjusting your search terms or selecting a different media type.</p>
<a href="/" class="btn btn-primary">🔍 Try Another Search</a>
</div>
{% endif %}
</div>
</div>
{% endblock %}