Skip to content

Commit

Permalink
Implement shotit-api duration response (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leslie-Wong-H authored Aug 10, 2023
2 parents 0cf5567 + cbf9cc6 commit 9db48cb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ export default async (req, res) => {

result = result
// .reduce((list, { d, hash_id }) => {
.reduce((list, { score: d, hash_id }) => {
.reduce((list, { score: d, hash_id, duration }) => {
// merge nearby results within 5 seconds in the same filename
const imdb_id = String(hash_id.split("/")[0]);
const filename = hash_id.split("/")[1];
Expand All @@ -362,6 +362,7 @@ export default async (req, res) => {
imdb_id,
filename,
t,
duration,
from: t,
to: t,
d,
Expand All @@ -380,7 +381,7 @@ export default async (req, res) => {

const window = 60 * 60; // 3600 seconds
const now = ((Date.now() / 1000 / window) | 0) * window + window;
result = result.map(({ imdb_id, filename, t, from, to, d }) => {
result = result.map(({ imdb_id, filename, t, duration, from, to, d }) => {
const mid = from + (to - from) / 2;
const videoToken = crypto
.createHash("sha1")
Expand All @@ -397,6 +398,7 @@ export default async (req, res) => {
imdb: imdb_id,
filename,
episode: aniep(filename),
duration,
from,
to,
// similarity: (100 - d) / 100,
Expand Down
27 changes: 27 additions & 0 deletions src/search.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ beforeAll(async () => {
max_length: 500,
description: "${imdbID}/${fileName}/${time}",
},
{
name: "duration",
data_type: DataType.Float,
description: "Video duration of the given video file",
},
{
name: "primary_key",
data_type: DataType.Int64,
Expand Down Expand Up @@ -149,6 +154,7 @@ beforeAll(async () => {
0.07166414845048348, 0.14825548206146674, 0.10861803715423188, 0.09339655442625933,
0.11284133872037455, 0.15155493641001572, 0.17421118960338527, 0.1372573008996369,
],
duration: 1422.01,
primary_key: 3694,
},
{
Expand Down Expand Up @@ -180,6 +186,7 @@ beforeAll(async () => {
0.07166414845048348, 0.14825548206146674, 0.10861803715423188, 0.09339655442625933,
0.11284133872037455, 0.15155493641001572, 0.17421118960338527, 0.1372573008996369,
],
duration: 1422.01,
primary_key: 3695,
},
],
Expand Down Expand Up @@ -236,13 +243,15 @@ describe("without API Key", () => {
expect(typeof topResult.imdb).toBe("string");
expect(typeof topResult.filename).toBe("string");
expect(typeof topResult.episode).toBe("number");
expect(typeof topResult.duration).toBe("number");
expect(typeof topResult.from).toBe("number");
expect(typeof topResult.to).toBe("number");
expect(typeof topResult.similarity).toBe("number");
expect(typeof topResult.video).toBe("string");
expect(typeof topResult.image).toBe("string");
expect(topResult.imdb).toBe("21034");
expect(topResult.episode).toBe(1);
expect(Math.floor(topResult.duration)).toBe(1422);
expect(topResult.similarity).toBeGreaterThan(0.9);
},
1000 * 10
Expand All @@ -269,13 +278,15 @@ describe("without API Key", () => {
expect(typeof topResult.imdb).toBe("string");
expect(typeof topResult.filename).toBe("string");
expect(typeof topResult.episode).toBe("number");
expect(typeof topResult.duration).toBe("number");
expect(typeof topResult.from).toBe("number");
expect(typeof topResult.to).toBe("number");
expect(typeof topResult.similarity).toBe("number");
expect(typeof topResult.video).toBe("string");
expect(typeof topResult.image).toBe("string");
expect(topResult.imdb).toBe("21034");
expect(topResult.episode).toBe(1);
expect(Math.floor(topResult.duration)).toBe(1422);
expect(topResult.similarity).toBeGreaterThan(0.9);
await fs.remove("32B15UXxymfSMwKGTObY5e.jpg");
},
Expand Down Expand Up @@ -303,13 +314,15 @@ describe("without API Key", () => {
expect(typeof topResult.imdb).toBe("string");
expect(typeof topResult.filename).toBe("string");
expect(typeof topResult.episode).toBe("number");
expect(typeof topResult.duration).toBe("number");
expect(typeof topResult.from).toBe("number");
expect(typeof topResult.to).toBe("number");
expect(typeof topResult.similarity).toBe("number");
expect(typeof topResult.video).toBe("string");
expect(typeof topResult.image).toBe("string");
expect(topResult.imdb).toBe("21034");
expect(topResult.episode).toBe(1);
expect(Math.floor(topResult.duration)).toBe(1422);
expect(topResult.similarity).toBeGreaterThan(0.9);
await fs.remove("32B15UXxymfSMwKGTObY5e.jpg");
},
Expand All @@ -330,13 +343,15 @@ describe("without API Key", () => {
expect(typeof topResult.imdb).toBe("string");
expect(typeof topResult.filename).toBe("string");
expect(typeof topResult.episode).toBe("number");
expect(typeof topResult.duration).toBe("number");
expect(typeof topResult.from).toBe("number");
expect(typeof topResult.to).toBe("number");
expect(typeof topResult.similarity).toBe("number");
expect(typeof topResult.video).toBe("string");
expect(typeof topResult.image).toBe("string");
expect(topResult.imdb).toBe("21034");
expect(topResult.episode).toBe(1);
expect(Math.floor(topResult.duration)).toBe(1422);
expect(topResult.similarity).toBeGreaterThan(0.9);
},
1000 * 10
Expand All @@ -356,13 +371,15 @@ describe("without API Key", () => {
expect(typeof topResult.imdb).toBe("string");
expect(typeof topResult.filename).toBe("string");
expect(typeof topResult.episode).toBe("number");
expect(typeof topResult.duration).toBe("number");
expect(typeof topResult.from).toBe("number");
expect(typeof topResult.to).toBe("number");
expect(typeof topResult.similarity).toBe("number");
expect(typeof topResult.video).toBe("string");
expect(typeof topResult.image).toBe("string");
expect(topResult.imdb).toBe("21034");
expect(topResult.episode).toBe(1);
expect(Math.floor(topResult.duration)).toBe(1422);
expect(topResult.similarity).toBeGreaterThan(0.9);
},
1000 * 10
Expand All @@ -382,13 +399,15 @@ describe("without API Key", () => {
// expect(typeof topResult.imdb).toBe("object");
// expect(typeof topResult.filename).toBe("string");
// expect(typeof topResult.episode).toBe("number");
// expect(typeof topResult.duration).toBe("number");
// expect(typeof topResult.from).toBe("number");
// expect(typeof topResult.to).toBe("number");
// expect(typeof topResult.similarity).toBe("number");
// expect(typeof topResult.video).toBe("string");
// expect(typeof topResult.image).toBe("string");
// expect(topResult.imdb.id).toBe("21034");
// expect(topResult.episode).toBe(1);
// expect(Math.floor(topResult.duration)).toBe(1422);
// expect(topResult.similarity).toBeGreaterThan(0.9);
// },
// 1000 * 10
Expand All @@ -409,12 +428,14 @@ describe("without API Key", () => {
expect(typeof topResult.imdb).toBe("string");
expect(typeof topResult.filename).toBe("string");
expect(typeof topResult.episode).toBe("number");
expect(typeof topResult.duration).toBe("number");
expect(typeof topResult.from).toBe("number");
expect(typeof topResult.to).toBe("number");
expect(typeof topResult.similarity).toBe("number");
expect(typeof topResult.video).toBe("string");
expect(typeof topResult.image).toBe("string");
expect(topResult.episode).toBe(1);
expect(Math.floor(topResult.duration)).toBe(1422);
expect(topResult.similarity).toBeGreaterThan(0.9);
},
1000 * 10
Expand Down Expand Up @@ -458,13 +479,15 @@ describe("with API Key", () => {
expect(typeof topResult.imdb).toBe("string");
expect(typeof topResult.filename).toBe("string");
expect(typeof topResult.episode).toBe("number");
expect(typeof topResult.duration).toBe("number");
expect(typeof topResult.from).toBe("number");
expect(typeof topResult.to).toBe("number");
expect(typeof topResult.similarity).toBe("number");
expect(typeof topResult.video).toBe("string");
expect(typeof topResult.image).toBe("string");
expect(topResult.imdb).toBe("21034");
expect(topResult.episode).toBe(1);
expect(Math.floor(topResult.duration)).toBe(1422);
expect(topResult.similarity).toBeGreaterThan(0.9);
},
1000 * 10
Expand Down Expand Up @@ -513,13 +536,15 @@ describe("with system system API Key", () => {
expect(typeof topResult.imdb).toBe("string");
expect(typeof topResult.filename).toBe("string");
expect(typeof topResult.episode).toBe("number");
expect(typeof topResult.duration).toBe("number");
expect(typeof topResult.from).toBe("number");
expect(typeof topResult.to).toBe("number");
expect(typeof topResult.similarity).toBe("number");
expect(typeof topResult.video).toBe("string");
expect(typeof topResult.image).toBe("string");
expect(topResult.imdb).toBe("21034");
expect(topResult.episode).toBe(1);
expect(Math.floor(topResult.duration)).toBe(1422);
expect(topResult.similarity).toBeGreaterThan(0.9);
},
1000 * 10
Expand Down Expand Up @@ -601,13 +626,15 @@ describe.each([
expect(typeof topResult.imdb).toBe("string");
expect(typeof topResult.filename).toBe("string");
expect(typeof topResult.episode).toBe("number");
expect(typeof topResult.duration).toBe("number");
expect(typeof topResult.from).toBe("number");
expect(typeof topResult.to).toBe("number");
expect(typeof topResult.similarity).toBe("number");
expect(typeof topResult.video).toBe("string");
expect(typeof topResult.image).toBe("string");
expect(topResult.imdb).toBe("21034");
expect(topResult.episode).toBe(1);
expect(Math.floor(topResult.duration)).toBe(1422);
expect(topResult.similarity).toBeGreaterThan(0.9);
},
1000 * 10
Expand Down

0 comments on commit 9db48cb

Please sign in to comment.