mirror of
https://github.com/ceratic/MediaCollectorLibary.git
synced 2026-05-13 23:56:46 +02:00
actor fetching :)
Stash / ADultVideoAPI
This commit is contained in:
@@ -43,8 +43,28 @@
|
||||
<!-- Name -->
|
||||
<div>
|
||||
<label for="name" class="block text-sm font-medium text-gray-700">Name *</label>
|
||||
<input type="text" name="name" id="name" value="{{ actor.name }}" required
|
||||
class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm focus:ring-blue-500 focus:border-blue-500 sm:text-sm px-3 py-2">
|
||||
<div class="flex space-x-2">
|
||||
<input type="text" name="name" id="name" value="{{ actor.name }}" required
|
||||
class="mt-1 block flex-1 border border-gray-300 rounded-md shadow-sm focus:ring-blue-500 focus:border-blue-500 sm:text-sm px-3 py-2">
|
||||
<button type="button" id="fetch-api-data" class="mt-1 bg-green-600 text-white px-4 py-2 rounded-md hover:bg-green-700 focus:outline-none focus:ring-2 focus:ring-green-500 focus:ring-offset-2 text-sm">
|
||||
Fetch from API
|
||||
</button>
|
||||
<button type="button" id="fetch-stash-data" class="mt-1 bg-purple-600 text-white px-4 py-2 rounded-md hover:bg-purple-700 focus:outline-none focus:ring-2 focus:ring-purple-500 focus:ring-offset-2 text-sm">
|
||||
Fetch from Stash
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Stash Search Query (Hidden by default) -->
|
||||
<div id="stash-config" class="hidden border border-purple-200 rounded-md p-4 bg-purple-50">
|
||||
<h4 class="text-sm font-medium text-purple-800 mb-3">Stash Performer Search</h4>
|
||||
<div>
|
||||
<label for="stash_query" class="block text-sm font-medium text-purple-700">Search Query</label>
|
||||
<input type="text" name="stash_query" id="stash_query"
|
||||
placeholder="Performer name to search"
|
||||
class="mt-1 block w-full border border-purple-300 rounded-md shadow-sm focus:ring-purple-500 focus:border-purple-500 sm:text-sm px-3 py-2">
|
||||
</div>
|
||||
<p class="mt-2 text-xs text-purple-600">Enter the performer name to search for in your configured Stash instance. Uses the same API configuration as your Stash sync.</p>
|
||||
</div>
|
||||
|
||||
<!-- Current Image -->
|
||||
@@ -60,14 +80,63 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<!-- Image Upload -->
|
||||
<!-- Image Source Selection -->
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 mb-3">Image Source</label>
|
||||
<div class="space-y-3">
|
||||
<div class="flex items-center">
|
||||
<input type="radio" name="image_source" id="image_source_upload" value="upload"
|
||||
class="h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300"
|
||||
checked>
|
||||
<label for="image_source_upload" class="ml-2 block text-sm text-gray-900">
|
||||
Upload from computer
|
||||
</label>
|
||||
</div>
|
||||
<div class="flex items-center">
|
||||
<input type="radio" name="image_source" id="image_source_url" value="url"
|
||||
class="h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300">
|
||||
<label for="image_source_url" class="ml-2 block text-sm text-gray-900">
|
||||
Download from URL
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Image Upload -->
|
||||
<div id="upload_section">
|
||||
<label for="thumbnail" class="block text-sm font-medium text-gray-700">Upload New Image</label>
|
||||
<input type="file" name="thumbnail" id="thumbnail" accept="image/*"
|
||||
class="mt-1 block w-full text-sm text-gray-500 file:mr-4 file:py-2 file:px-4 file:rounded-full file:border-0 file:text-sm file:font-semibold file:bg-blue-50 file:text-blue-700 hover:file:bg-blue-100">
|
||||
<p class="mt-1 text-sm text-gray-500">Supported formats: JPEG, PNG, GIF, WebP. Maximum file size: 5MB.</p>
|
||||
</div>
|
||||
|
||||
<!-- External URL -->
|
||||
<div id="url_section" class="hidden">
|
||||
<label for="thumbnail_url" class="block text-sm font-medium text-gray-700">Image URL</label>
|
||||
<input type="url" name="thumbnail_url" id="thumbnail_url"
|
||||
placeholder="https://example.com/image.jpg"
|
||||
class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm focus:ring-blue-500 focus:border-blue-500 sm:text-sm px-3 py-2">
|
||||
<p class="mt-1 text-sm text-gray-500">Enter a direct link to an image. The image will be downloaded and stored locally.</p>
|
||||
|
||||
<!-- Image Preview -->
|
||||
<div id="image_preview" class="mt-4 hidden">
|
||||
<label class="block text-sm font-medium text-gray-700 mb-2">Preview</label>
|
||||
<div class="border border-gray-300 rounded-md p-4 bg-gray-50">
|
||||
<div id="preview_loading" class="hidden flex items-center justify-center py-8">
|
||||
<div class="animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600"></div>
|
||||
<span class="ml-2 text-gray-600">Loading preview...</span>
|
||||
</div>
|
||||
<div id="preview_error" class="hidden text-center py-8">
|
||||
<svg class="mx-auto h-12 w-12 text-red-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.964-.833-2.732 0L4.082 16.5c-.77.833.192 2.5 1.732 2.5z" />
|
||||
</svg>
|
||||
<p class="mt-2 text-sm text-red-600" id="preview_error_text">Unable to load image preview</p>
|
||||
</div>
|
||||
<img id="preview_image" class="max-w-full h-auto max-h-64 mx-auto rounded shadow-sm hidden" alt="Image preview">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Biography -->
|
||||
<div>
|
||||
<label for="biography" class="block text-sm font-medium text-gray-700">Biography</label>
|
||||
@@ -277,4 +346,368 @@
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Toggle image source sections
|
||||
document.querySelectorAll('input[name="image_source"]').forEach(radio => {
|
||||
radio.addEventListener('change', function() {
|
||||
const uploadSection = document.getElementById('upload_section');
|
||||
const urlSection = document.getElementById('url_section');
|
||||
const imagePreview = document.getElementById('image_preview');
|
||||
|
||||
if (this.value === 'upload') {
|
||||
uploadSection.classList.remove('hidden');
|
||||
urlSection.classList.add('hidden');
|
||||
imagePreview.classList.add('hidden');
|
||||
} else if (this.value === 'url') {
|
||||
uploadSection.classList.add('hidden');
|
||||
urlSection.classList.remove('hidden');
|
||||
// Check if URL field has a value and show preview if it does
|
||||
const urlInput = document.getElementById('thumbnail_url');
|
||||
if (urlInput.value.trim()) {
|
||||
updateImagePreview(urlInput.value.trim());
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Image URL preview functionality
|
||||
function updateImagePreview(url) {
|
||||
const previewContainer = document.getElementById('image_preview');
|
||||
const loadingDiv = document.getElementById('preview_loading');
|
||||
const errorDiv = document.getElementById('preview_error');
|
||||
const imageElement = document.getElementById('preview_image');
|
||||
|
||||
// Show preview container and loading state
|
||||
previewContainer.classList.remove('hidden');
|
||||
loadingDiv.classList.remove('hidden');
|
||||
errorDiv.classList.add('hidden');
|
||||
imageElement.classList.add('hidden');
|
||||
|
||||
// Create a new image to test loading
|
||||
const testImage = new Image();
|
||||
|
||||
testImage.onload = function() {
|
||||
// Image loaded successfully
|
||||
loadingDiv.classList.add('hidden');
|
||||
errorDiv.classList.add('hidden');
|
||||
imageElement.src = url;
|
||||
imageElement.classList.remove('hidden');
|
||||
};
|
||||
|
||||
testImage.onerror = function() {
|
||||
// Image failed to load
|
||||
loadingDiv.classList.add('hidden');
|
||||
errorDiv.classList.remove('hidden');
|
||||
imageElement.classList.add('hidden');
|
||||
document.getElementById('preview_error_text').textContent = 'Unable to load image. Please check the URL.';
|
||||
};
|
||||
|
||||
// Set a timeout for slow-loading images
|
||||
setTimeout(() => {
|
||||
if (loadingDiv.classList.contains('hidden') === false) {
|
||||
loadingDiv.classList.add('hidden');
|
||||
errorDiv.classList.remove('hidden');
|
||||
document.getElementById('preview_error_text').textContent = 'Image loading timed out. Please try again.';
|
||||
}
|
||||
}, 10000); // 10 second timeout
|
||||
|
||||
testImage.src = url;
|
||||
}
|
||||
|
||||
// Add event listener to URL input
|
||||
document.getElementById('thumbnail_url').addEventListener('input', function() {
|
||||
const url = this.value.trim();
|
||||
|
||||
if (url) {
|
||||
// Debounce the preview update
|
||||
clearTimeout(this.previewTimeout);
|
||||
this.previewTimeout = setTimeout(() => {
|
||||
updateImagePreview(url);
|
||||
}, 500); // Wait 500ms after user stops typing
|
||||
} else {
|
||||
// Hide preview if URL is empty
|
||||
document.getElementById('image_preview').classList.add('hidden');
|
||||
}
|
||||
});
|
||||
|
||||
// Clear preview timeout on form submission
|
||||
document.querySelector('form').addEventListener('submit', function() {
|
||||
const urlInput = document.getElementById('thumbnail_url');
|
||||
if (urlInput.previewTimeout) {
|
||||
clearTimeout(urlInput.previewTimeout);
|
||||
}
|
||||
});
|
||||
|
||||
document.getElementById('fetch-api-data').addEventListener('click', async function() {
|
||||
const nameInput = document.getElementById('name');
|
||||
const actorName = nameInput.value.trim();
|
||||
|
||||
if (!actorName) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Show loading state
|
||||
const button = this;
|
||||
const originalText = button.textContent;
|
||||
button.textContent = 'Fetching...';
|
||||
button.disabled = true;
|
||||
|
||||
try {
|
||||
// Format name for API (firstname%20lastname)
|
||||
const formattedName = actorName.replace(/\s+/g, '%20');
|
||||
const apiUrl = `https://api.adultdatalink.com/pornstar/pornstar-data?name=${formattedName}`;
|
||||
|
||||
const response = await fetch(apiUrl);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`API request failed: ${response.status}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
// Map API data to form fields
|
||||
if (data) {
|
||||
console.log(data);
|
||||
console.log(data.appearance.ethnicity);
|
||||
|
||||
|
||||
console.log(data.date_of_birth)
|
||||
date = new Date(Date.parse(data.date_of_birth));
|
||||
console.log(date);
|
||||
date = date.toLocaleDateString(undefined, {year:'numeric'}) + '-' + date.toLocaleDateString(undefined, {month:'2-digit'}) + '-' + date.toLocaleDateString(undefined, {day:'2-digit'})
|
||||
|
||||
console.log(date);
|
||||
// Basic info
|
||||
if (data.avatar){
|
||||
document.getElementById('image_source_url').value = 'url';
|
||||
document.getElementById('thumbnail_url').value = data.avatar;
|
||||
|
||||
}
|
||||
if (data.biography) document.getElementById('biography').value = data.biography;
|
||||
if (data.birth_date) document.getElementById('birth_date').value = date;
|
||||
if (data.death_date) document.getElementById('death_date').value = data.death_date;
|
||||
if (data.place_of_birth) document.getElementById('birth_place').value = data.place_of_birth;
|
||||
if (data.country) document.getElementById('nationality').value = data.country;
|
||||
if (data.appearance.ethnicity) document.getElementById('ethnicity').value = data.appearance.ethnicity;
|
||||
|
||||
// Gender mapping
|
||||
if (data.gender) {
|
||||
const genderSelect = document.getElementById('gender');
|
||||
const genderMap = {
|
||||
'woman': 'FEMALE',
|
||||
'male': 'MALE',
|
||||
'transgender_female': 'TRANSGENDER_FEMALE',
|
||||
'transgender_male': 'TRANSGENDER_MALE',
|
||||
'intersex': 'INTERSEX',
|
||||
'non_binary': 'NON_BINARY'
|
||||
};
|
||||
const mappedGender = genderMap[data.gender.toLowerCase()] || data.gender.toUpperCase();
|
||||
genderSelect.value = mappedGender;
|
||||
}
|
||||
|
||||
// Physical attributes
|
||||
if (data.appearance.height) document.getElementById('height').value = data.appearance.height;
|
||||
document.getElementById('measurements').value = parseInt(data.appearance.bra)+'-'+ parseInt(data.appearance.waist)+'-'+parseInt(data.appearance.hip);
|
||||
if (data.appearance.cup) document.getElementById('cup_size').value = data.appearance.cup;
|
||||
if (data.appearance.hair_color) document.getElementById('hair_color').value = data.appearance.hair_color;
|
||||
if (data.appearance.eye_color) document.getElementById('eye_color').value = data.appearance.eye_color;
|
||||
|
||||
// Body modifications
|
||||
if (data.appearance.piercing_locations) document.getElementById('piercings').value = data.appearance.piercing_locations;
|
||||
if (data.appearance.tattoo_locations) document.getElementById('tattoos').value = data.appearance.tattoo_locations;
|
||||
|
||||
// Aliases
|
||||
if (data.aliases) document.getElementById('aliases').value = data.aliases;
|
||||
if (data.aliases && Array.isArray(data.aliases)) {
|
||||
document.getElementById('aliases').value = data.aliases.join(', ');
|
||||
}
|
||||
|
||||
|
||||
// Social media
|
||||
if (data.social_media) {
|
||||
if (data.social_media.twitter) document.getElementById('twitter').value = data.social_media.twitter;
|
||||
if (data.social_media.instagram) document.getElementById('instagram').value = data.social_media.instagram;
|
||||
if (data.social_media.onlyfans) document.getElementById('onlyfans').value = data.social_media.onlyfans;
|
||||
if (data.social_media.website) document.getElementById('website').value = data.social_media.website;
|
||||
}
|
||||
|
||||
if (data.career_start) document.getElementById('debut_year').value = data.career_start;
|
||||
if (data.career_end) document.getElementById('retirement_year').value = data.career_end;
|
||||
if (data.career_status !== undefined) document.getElementById('active').checked = data.active;
|
||||
if (data.genres && Array.isArray(data.adult_specific.genres)) {
|
||||
document.getElementById('adult_genres').value = data.adult_specific.genres.join(', ');
|
||||
}
|
||||
|
||||
if (data.tags && Array.isArray(data.tags)) {
|
||||
document.getElementById('specialties').value = data.tags.join(', ');
|
||||
}
|
||||
|
||||
} else {
|
||||
alert('No data found for this performer');
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error fetching data:', error);
|
||||
alert('Error fetching data from API: ' + error.message);
|
||||
} finally {
|
||||
// Reset button state
|
||||
button.textContent = originalText;
|
||||
button.disabled = false;
|
||||
}
|
||||
});
|
||||
|
||||
// Stash API fetch functionality
|
||||
document.getElementById('fetch-stash-data').addEventListener('click', async function() {
|
||||
const nameInput = document.getElementById('name');
|
||||
const actorName = nameInput.value.trim();
|
||||
|
||||
if (!actorName) {
|
||||
alert('Please enter a name first');
|
||||
return;
|
||||
}
|
||||
|
||||
// Show Stash config section
|
||||
const stashConfig = document.getElementById('stash-config');
|
||||
stashConfig.classList.remove('hidden');
|
||||
|
||||
// Pre-fill query with actor name
|
||||
const queryInput = document.getElementById('stash_query');
|
||||
if (!queryInput.value.trim()) {
|
||||
queryInput.value = actorName;
|
||||
}
|
||||
|
||||
// Show loading state
|
||||
const button = this;
|
||||
const originalText = button.textContent;
|
||||
button.textContent = 'Fetching from Stash...';
|
||||
button.disabled = true;
|
||||
|
||||
try {
|
||||
const stashQuery = document.getElementById('stash_query').value.trim();
|
||||
|
||||
if (!stashQuery) {
|
||||
alert('Please enter a search query');
|
||||
return;
|
||||
}
|
||||
|
||||
// Make API call to backend endpoint
|
||||
const response = await fetch('/api/actors/fetch-stash', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
query: stashQuery
|
||||
})
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json();
|
||||
throw new Error(errorData.error || `API request failed: ${response.status}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (data && data.performers && data.performers.length > 0) {
|
||||
const performer = data.performers[0]; // Use first result
|
||||
const stashUrl = data.stash_url; // Get Stash URL from response
|
||||
|
||||
// Map Stash performer data to form fields
|
||||
if (performer.image_path) {
|
||||
// Set image source to URL and populate the URL field
|
||||
document.getElementById('image_source_url').checked = true;
|
||||
document.getElementById('upload_section').classList.add('hidden');
|
||||
document.getElementById('url_section').classList.remove('hidden');
|
||||
|
||||
// Construct full image URL
|
||||
let imageUrl = performer.image_path;
|
||||
if (imageUrl.startsWith('/')) {
|
||||
imageUrl = stashUrl + imageUrl;
|
||||
} else if (!imageUrl.startsWith('http')) {
|
||||
imageUrl = `${stashUrl}/performer/${performer.id}/${imageUrl}`;
|
||||
}
|
||||
document.getElementById('thumbnail_url').value = imageUrl;
|
||||
}
|
||||
|
||||
if (performer.details) document.getElementById('biography').value = performer.details;
|
||||
if (performer.birthdate) document.getElementById('birth_date').value = performer.birthdate;
|
||||
if (performer.death_date) document.getElementById('death_date').value = performer.death_date;
|
||||
if (performer.country) document.getElementById('nationality').value = performer.country;
|
||||
if (performer.ethnicity) document.getElementById('ethnicity').value = performer.ethnicity;
|
||||
|
||||
// Gender mapping
|
||||
if (performer.gender) {
|
||||
const genderSelect = document.getElementById('gender');
|
||||
genderSelect.value = performer.gender.toUpperCase();
|
||||
}
|
||||
|
||||
// Physical attributes
|
||||
if (performer.height_cm) document.getElementById('height').value = performer.height_cm + 'cm';
|
||||
if (performer.measurements) document.getElementById('measurements').value = performer.measurements;
|
||||
if (performer.hair_color) document.getElementById('hair_color').value = performer.hair_color;
|
||||
if (performer.eye_color) document.getElementById('eye_color').value = performer.eye_color;
|
||||
if (performer.weight) document.getElementById('weight').value = performer.weight + 'kg';
|
||||
|
||||
// Body modifications
|
||||
if (performer.piercings) document.getElementById('piercings').value = performer.piercings;
|
||||
if (performer.tattoos) document.getElementById('tattoos').value = performer.tattoos;
|
||||
|
||||
// Aliases
|
||||
if (performer.alias_list && Array.isArray(performer.alias_list)) {
|
||||
document.getElementById('aliases').value = performer.alias_list.join(', ');
|
||||
}
|
||||
|
||||
// Social media
|
||||
if (performer.url) document.getElementById('website').value = performer.url;
|
||||
|
||||
// Adult-specific information
|
||||
if (performer.career_length) {
|
||||
const debutYear = extractDebutYear(performer.career_length);
|
||||
const retirementYear = extractRetirementYear(performer.career_length);
|
||||
if (debutYear) document.getElementById('debut_year').value = debutYear;
|
||||
if (retirementYear) document.getElementById('retirement_year').value = retirementYear;
|
||||
document.getElementById('active').checked = isActivePerformer(performer.career_length);
|
||||
}
|
||||
|
||||
//if (performer.scene_count) document.getElementById('scene_count').value = performer.scene_count;
|
||||
|
||||
// Additional Stash-specific fields
|
||||
//if (performer.disambiguation) document.getElementById('birth_place').value = performer.disambiguation;
|
||||
//if (performer.fake_tits !== undefined) document.getElementById('fake_tits').value = performer.fake_tits ? 'Yes' : 'No';
|
||||
//if (performer.penis_length) document.getElementById('penis_length').value = performer.penis_length;
|
||||
//if (performer.circumcised !== undefined) document.getElementById('circumcised').value = performer.circumcised ? 'Yes' : 'No';
|
||||
|
||||
} else {
|
||||
alert('No performers found matching the query');
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error fetching data from Stash:', error);
|
||||
alert('Error fetching data from Stash: ' + error.message);
|
||||
} finally {
|
||||
// Reset button state
|
||||
button.textContent = originalText;
|
||||
button.disabled = false;
|
||||
}
|
||||
});
|
||||
|
||||
// Helper functions for parsing Stash data
|
||||
function extractDebutYear(careerLength) {
|
||||
if (!careerLength) return null;
|
||||
const match = careerLength.match(/(\d{4})\s*-\s*\d{4}/);
|
||||
return match ? match[1] : null;
|
||||
}
|
||||
|
||||
function extractRetirementYear(careerLength) {
|
||||
if (!careerLength) return null;
|
||||
const match = careerLength.match(/\d{4}\s*-\s*(\d{4})/);
|
||||
return match ? match[1] : null;
|
||||
}
|
||||
|
||||
function isActivePerformer(careerLength) {
|
||||
if (!careerLength) return false;
|
||||
return careerLength.trim().endsWith('-');
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user