Skip to content

Commit

Permalink
sources: add support for showing followed results on Pixiv
Browse files Browse the repository at this point in the history
  • Loading branch information
Bionus committed Feb 13, 2023
1 parent cad50e9 commit eff25a0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/_sources/pixiv.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Whatever URL is entered when adding a site with this source, it will be override
* `mode:{partial,full,tc}`: tag search type (default: `partial`)
* `bookmarks:USER_ID`: fetch a given user's bookmarks
* `user:USER_ID`: fetch art from a given user
* `is:followed`: show illustrations from artists you follow
* `type:{illust,manga}`: only load works of a given type (only applies to `user:` and empty searches)

### Date
Expand Down
17 changes: 14 additions & 3 deletions src/sites/Pixiv/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const meta: ISource["meta"] = {
},
};

function parseSearch(search: string): { mode: string, tags: string[], bookmarks?: number, user?: number, startDate?: string, endDate?: string, type?: string } {
function parseSearch(search: string): { mode: string, tags: string[], bookmarks?: number, user?: number, followed: boolean, startDate?: string, endDate?: string, type?: string } {
const modes: any = {
"partial": "partial_match_for_tags",
"full": "exact_match_for_tags",
Expand All @@ -40,6 +40,7 @@ function parseSearch(search: string): { mode: string, tags: string[], bookmarks?
const type = parsed.type;

const tags = [];
let followed = false;
let startDate = undefined;
let endDate = undefined;

Expand All @@ -66,11 +67,15 @@ function parseSearch(search: string): { mode: string, tags: string[], bookmarks?
}
continue;
}
if (part === "is:followed") {
followed = true;
continue;
}

tags.push(part);
}

return { mode, tags, bookmarks, user, startDate, endDate, type };
return { mode, tags, bookmarks, user, followed, startDate, endDate, type };
}

function parseImage(image: any, fromGallery: boolean): IImage {
Expand Down Expand Up @@ -134,7 +139,7 @@ function parseImage(image: any, fromGallery: boolean): IImage {

export const source: ISource = {
name: "Pixiv",
modifiers: ["mode:partial", "mode:full", "mode:tc", "bookmarks:", "user:", "date:"],
modifiers: ["mode:partial", "mode:full", "mode:tc", "bookmarks:", "user:", "date:", "is:followed"],
forcedTokens: [],
searchFormat: {
and: " ",
Expand Down Expand Up @@ -203,6 +208,12 @@ export const source: ISource = {
return "https://app-api.pixiv.net/v1/user/illusts?" + illustParams.join("&");
}

// User's follows
if (search.followed) {
illustParams.push("restrict=public");
return "https://app-api.pixiv.net/v2/illust/follow?" + illustParams.join("&");
}

// Newest (when no tag is provided)
if (search.tags.length === 0) {
if (search.type) {
Expand Down

0 comments on commit eff25a0

Please sign in to comment.