-
Notifications
You must be signed in to change notification settings - Fork 1
fix: videos (LF) not updating, related to and closes #207 #210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -15,6 +15,41 @@ import getSinglePlaylistAndReturnVideoData, { | |||||||||||||||||
| PlaylistType, | ||||||||||||||||||
| } from "./getSinglePlaylistAndReturnVideoData"; | ||||||||||||||||||
|
|
||||||||||||||||||
| /** | ||||||||||||||||||
| * Parse an ISO 8601 duration string (e.g. "PT1H2M3S") into total seconds. | ||||||||||||||||||
| */ | ||||||||||||||||||
| function parseISO8601Duration(duration: string): number { | ||||||||||||||||||
| const match = duration.match(/PT(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?/); | ||||||||||||||||||
| if (!match) return 0; | ||||||||||||||||||
| const hours = parseInt(match[1] || "0", 10); | ||||||||||||||||||
| const minutes = parseInt(match[2] || "0", 10); | ||||||||||||||||||
| const seconds = parseInt(match[3] || "0", 10); | ||||||||||||||||||
| return hours * 3600 + minutes * 60 + seconds; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| /** | ||||||||||||||||||
| * Fetch the duration (in seconds) of a video using the YouTube Videos API. | ||||||||||||||||||
| * Returns 0 if the duration cannot be determined. | ||||||||||||||||||
| */ | ||||||||||||||||||
| async function fetchVideoDuration(videoId: string): Promise<number> { | ||||||||||||||||||
| const res = await fetch( | ||||||||||||||||||
| `https://youtube.googleapis.com/youtube/v3/videos?part=contentDetails&id=${videoId}&key=${env.youtubeApiKey}`, | ||||||||||||||||||
| ); | ||||||||||||||||||
|
|
||||||||||||||||||
| if (!res.ok) { | ||||||||||||||||||
| console.error( | ||||||||||||||||||
| "Error fetching video duration:", | ||||||||||||||||||
| res.statusText, | ||||||||||||||||||
| ); | ||||||||||||||||||
| return 0; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| const data = await res.json(); | ||||||||||||||||||
| if (!data.items || data.items.length === 0) return 0; | ||||||||||||||||||
|
|
||||||||||||||||||
| return parseISO8601Duration(data.items[0].contentDetails.duration); | ||||||||||||||||||
|
||||||||||||||||||
| return parseISO8601Duration(data.items[0].contentDetails.duration); | |
| const firstItem = data.items[0]; | |
| const durationStr = firstItem?.contentDetails?.duration; | |
| if (typeof durationStr !== "string") { | |
| return 0; | |
| } | |
| return parseISO8601Duration(durationStr); |
Copilot
AI
Feb 12, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The duration threshold hard-codes 180 seconds and treats >= 180 as “cannot be a short”. If that assumption is ever wrong (e.g., policy changes or edge cases at exactly 180s), shorts could be misclassified as regular videos and routed to the wrong subscription flags. Consider avoiding duration-based gating for Shorts classification (or at minimum make the threshold configurable and document the assumption).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parseISO8601Durationonly matchesPT...and will ignore the day component if YouTube ever returns durations likeP1DT2H3M(regex will match from thePT...substring and undercount). Consider parsing the full ISO-8601 duration (e.g., support an optionalP(\d+)Dpart and anchor the regex) so duration-based classification stays correct for very long videos/streams.