Skip to content

Commit

Permalink
Load file url from details page for DeviantArt (fix #2428)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bionus committed Jul 29, 2021
1 parent c50f4fa commit 746bdec
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/sites/DeviantArt/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function completeImage(img: IImage): IImage {

export const source: ISource = {
name: "DeviantArt",
forcedTokens: ["file_url"],
apis: {
rss: {
name: "RSS",
Expand Down Expand Up @@ -59,18 +60,19 @@ export const source: ISource = {
const rating = image["media:rating"]["#text"].trim();

const img: IImage = {
// page_url: image["link"]["#text"],
page_url: image["link"]["#text"],
created_at: image["pubDate"]["#text"],
name: image["media:title"]["#text"],
author: credit["#text"],
tags: (image["media:keywords"]["#text"] || "").trim().split(", "),
preview_url: thumbnail && (thumbnail["#text"] || thumbnail["@attributes"]["url"]),
file_url: image["media:content"]["#text"] || image["media:content"]["@attributes"]["url"],
width: image["media:content"]["@attributes"]["width"],
height: image["media:content"]["@attributes"]["height"],
preview_width: thumbnail && thumbnail["@attributes"]["width"],
preview_height: thumbnail && thumbnail["@attributes"]["height"],
sample_url: image["media:content"]["#text"] || image["media:content"]["@attributes"]["url"],
sample_width: image["media:content"]["@attributes"]["width"],
sample_height: image["media:content"]["@attributes"]["height"],
rating: rating === "nonadult" ? "safe" : (rating === "adult" ? "explicit" : "questionable"),
};
img.sample_url = img.file_url;

images.push(completeImage(img));
}
Expand All @@ -89,14 +91,24 @@ export const source: ISource = {
return "/search/deviations?q=" + encodeURIComponent(parsed.query) + "&page=" + query.page;
},
parse: (src: string): IParsedSearch => {
console.log(JSON.stringify(Grabber.regexToTags('<a href="[^"]*/search/deviations\\?q=[^"]+" data-tag="(?<name>[^"]+)"[^>]*>[^<]+</a>', src)));
return {
images: Grabber.regexToImages('<section.*?<a data-hook="deviation_link" href="(?<page_url>[^"]+)"[^>]*>.*?<img[^>]+src="(?<preview_url>[^"]+)"[^>]*>.*?<h2[^<]*>(?<name>[^<]+)</h2>', src).map(completeImage),
tags: Grabber.regexToTags('<a href="[^"]*/search/deviations\\?q=[^"]+" data-tag="(?<name>[^"]+)"[^>]*>[^<]+</a>', src),
imageCount: Grabber.regexToConst("count", '>(?<count>\\d+) results<', src),
};
},
},
details: {
url: (id: string, md5: string): IError => {
return { error: "Not supported (page_url)" };
},
parse: (src: string): IParsedDetails => {
return {
tags: Grabber.regexToTags('<a href="[^"]*/tag/(?<name>[^"]+)"', src),
imageUrl: Grabber.regexToConst("url", '<img[^>]*aria-hidden="true"[^>]+src="(?<url>[^"]+)"', src),
};
},
},
},
},
};

0 comments on commit 746bdec

Please sign in to comment.