Skip to content

Commit 331c2fd

Browse files
committed
improved parsing
1 parent 4f34033 commit 331c2fd

File tree

3 files changed

+16
-21
lines changed

3 files changed

+16
-21
lines changed

src/lib/components/VideoCard.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
);
5050
5151
if (!response.ok) {
52-
throw new Error(`Failed to fetch duration: ${response.status}`);
52+
return;
5353
}
5454
5555
const data = await response.json();

src/routes/api/youtube-duration/+server.ts

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,23 @@ export const GET: RequestHandler = async ({ url }) => {
2424
}
2525

2626
const html = await response.text();
27-
const patterns = [
28-
/"lengthSeconds":"(\d+)"/,
29-
/"approxDurationMs":"(\d+)"/,
30-
/"videoDetails":\s*\{[^}]*"lengthSeconds":\s*"(\d+)"/,
31-
/"lengthSeconds":\s*"(\d+)"/,
32-
/"duration":\s*"PT(\d+)S"/,
33-
/itemprop="duration"\s+content="PT(\d+)S"/
34-
];
35-
3627
let durationSeconds = 0;
3728

38-
for (const pattern of patterns) {
39-
const match = html.match(pattern);
29+
const schemaMatch = html.match(/itemprop="duration" content="([^"]+)"/);
30+
if (schemaMatch) {
31+
const duration = schemaMatch[1];
32+
const match = duration.match(/PT(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?/);
4033
if (match) {
41-
if (pattern.source.includes('DurationMs')) {
42-
durationSeconds = Math.floor(parseInt(match[1]) / 1000);
43-
} else {
44-
durationSeconds = parseInt(match[1]);
45-
}
46-
if (durationSeconds > 0) {
47-
break;
48-
}
34+
const hours = parseInt(match[1] || '0');
35+
const minutes = parseInt(match[2] || '0');
36+
const seconds = parseInt(match[3] || '0');
37+
durationSeconds = hours * 3600 + minutes * 60 + seconds;
38+
}
39+
}
40+
if (durationSeconds === 0) {
41+
const lengthMatch = html.match(/"lengthSeconds":"(\d+)"/);
42+
if (lengthMatch) {
43+
durationSeconds = parseInt(lengthMatch[1]);
4944
}
5045
}
5146

src/routes/docs/products/databases/quick-start/+page.markdoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: Start with Databases
44
description: Get started with Appwrite Databases. Follow a step-by-step guide to create your first database, define tables, and perform basic data operations.
55
---
66

7-
{% video_card href="https://youtu.be/dh0pJdgY6Lc?si=ZOoAkhmPhsBdXZ_s" title="Learn how to create and manage databases" /%}
7+
{% video_card href="https://youtu.be/-g1yKRo5XtY?si=p4wf-EbWE4wjmQmb" title="Learn how to create and manage databases" /%}
88

99
{% section #create-database step=1 title="Create database" %}
1010
Head to your [Appwrite Console](https://cloud.appwrite.io/console/) and create a database and name it `Oscar`.

0 commit comments

Comments
 (0)