Skip to content

Commit

Permalink
Merge branch '8-improved-search' into 'main'
Browse files Browse the repository at this point in the history
Resolve "Improved Search"

Closes #8

See merge request MrMysterius/mangasee-dl!8
  • Loading branch information
MrMysterius committed Jan 28, 2023
2 parents f41b527 + 79dc509 commit 57a7420
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
18 changes: 15 additions & 3 deletions main.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
import { parse } from "https://deno.land/[email protected]/flags/mod.ts";
import * as Color from "https://deno.land/[email protected]/fmt/colors.ts";
import { searchAnime } from "./search.ts";
import { getBasicMetadata } from "./metadata.ts";

const ARGS = parse(Deno.args);

switch (ARGS._[0] || undefined) {
case "search": {
if (ARGS._.length <= 1) break;
const results = await searchAnime(ARGS._.slice(1, ARGS._.length).join(" "));
const results = await searchAnime(ARGS._.slice(1, ARGS._.length).join(" "), parseInt(ARGS.l) || parseInt(ARGS["limit"]) || 5);
for (const result of results) {
if (result.score > 0.05) continue;
console.log(`${Color.white("-")} ${Color.green(result.item.s)} [ ${Color.blue(result.item.i)} ]`);
if (result.score > (parseInt(ARGS.s) || parseInt(ARGS["score-threshold"]) || 0.05)) continue;
let release_year = "";
let chapters_available = "";
if (!ARGS["no-metadata"] && !ARGS.n) {
const metadata = await getBasicMetadata(result.item.i);
release_year = metadata?.release_year || "";
chapters_available = metadata?.chapters_available.toString() || "";
}
console.log(
`${Color.white("-")} ${release_year != "" ? Color.cyan(release_year + " ") : ""}${Color.green(result.item.s)}${
chapters_available != "" ? Color.magenta(" #" + chapters_available) : ""
} [ ${Color.yellow(result.item.i)} ]`
);
}
break;
}
Expand Down
4 changes: 2 additions & 2 deletions search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ interface SearchResult {
score: number;
}

export async function searchAnime(search_term: string): Promise<SearchResult[]> {
export async function searchAnime(search_term: string, limit = 5): Promise<SearchResult[]> {
const res = await fetch(AVAILABLE_URL);
const data: Array<MangaTitles> = JSON.parse(await res.text());

const fuse = new Fuse(data, OPTIONS);
const findings: SearchResult[] = fuse.search(search_term, { limit: 5 });
const findings: SearchResult[] = fuse.search(search_term, { limit });

return findings;
}

0 comments on commit 57a7420

Please sign in to comment.