mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-04-07 20:19:39 +02:00
Scraper fixes + adding multiple sources
This commit is contained in:
parent
9f9c84dbad
commit
8f5b248e57
3 changed files with 51 additions and 0 deletions
|
@ -35,6 +35,7 @@ function setupImageUpload() {
|
|||
const descrEl = $('.js-image-descr-input', form);
|
||||
const tagsEl = $('.js-image-tags-input', form);
|
||||
const sourceEl = $$('.js-source-url', form).find(input => input.value === '');
|
||||
const sourceAdd = $('.js-image-add-source');
|
||||
const fetchButton = $('#js-scraper-preview');
|
||||
if (!fetchButton) return;
|
||||
|
||||
|
@ -116,6 +117,24 @@ function setupImageUpload() {
|
|||
if (descrEl) descrEl.value = descrEl.value || data.description || '';
|
||||
// Add author
|
||||
if (tagsEl && data.author_name) addTag(tagsEl, `artist:${data.author_name.toLowerCase()}`);
|
||||
// Add multiple authors if provided
|
||||
if (tagsEl && data.authors) data.authors.forEach(item => addTag(tagsEl, `artist:${item.toLowerCase()}`));
|
||||
// Add Tags
|
||||
if (tagsEl && data.tags) data.tags.forEach(item => addTag(tagsEl, `${item.toLowerCase()}`));
|
||||
// Add multiple sources
|
||||
if (sourceAdd && data.sources && data.sources.length > 0) {
|
||||
data.sources.forEach(() => {
|
||||
sourceAdd.dispatchEvent(new Event('click'));
|
||||
});
|
||||
|
||||
let index;
|
||||
const inps = document.querySelectorAll('.js-image-source input:placeholder-shown');
|
||||
|
||||
data.sources.forEach(item => {
|
||||
index = data.sources.indexOf(item);
|
||||
if (inps[index]) inps[index].value = item;
|
||||
});
|
||||
}
|
||||
// Clear selected file, if any
|
||||
fileField.value = '';
|
||||
showImages(data.images);
|
||||
|
|
|
@ -6,6 +6,7 @@ defmodule Philomena.Scrapers do
|
|||
Philomena.Scrapers.Tumblr,
|
||||
Philomena.Scrapers.Inkbunny,
|
||||
Philomena.Scrapers.E621,
|
||||
Philomena.Scrapers.Furaffinity,
|
||||
Philomena.Scrapers.Raw
|
||||
]
|
||||
|
||||
|
|
31
lib/philomena/scrapers/furaffinity.ex
Normal file
31
lib/philomena/scrapers/furaffinity.ex
Normal file
|
@ -0,0 +1,31 @@
|
|||
defmodule Philomena.Scrapers.Furaffinity do
|
||||
@url_regex ~r|\Ahttps?://furaffinity\.net/view/([0-9]+)|
|
||||
|
||||
@spec can_handle?(URI.t(), String.t()) :: true | false
|
||||
def can_handle?(_uri, url) do
|
||||
String.match?(url, @url_regex)
|
||||
end
|
||||
|
||||
def scrape(_uri, url) do
|
||||
[_, submission_id] = Regex.run(@url_regex, url, capture: :all)
|
||||
api_url = "https://faexport.spangle.org.uk/submission/#{submission_id}.json"
|
||||
{:ok, %Tesla.Env{status: 200, body: body}} = Philomena.Http.get(api_url)
|
||||
|
||||
json = Jason.decode!(body)
|
||||
[submission] = json
|
||||
|
||||
images = for x <- submission do
|
||||
%{
|
||||
url: "#{x["download"]}",
|
||||
camo_url: Camo.Image.image_url(x["thumbnail"])
|
||||
}
|
||||
end
|
||||
|
||||
%{
|
||||
source_url: url,
|
||||
author_name: submission["name"],
|
||||
description: submission["description"],
|
||||
images: images
|
||||
}
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue