* Parses an ISO 8601 duration (e.g. `PT1M30S`, `PT2H`, `P1DT2H`) into total seconds. * Returns null when the value is missing or unparseable.
(value: string | undefined)
| 83 | * Returns null when the value is missing or unparseable. |
| 84 | */ |
| 85 | function parseIso8601Duration(value: string | undefined): number | null { |
| 86 | if (!value) return null |
| 87 | const match = value.match(/^P(?:(\d+)D)?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?)?$/) |
| 88 | if (!match) return null |
| 89 | const [, days, hours, minutes, seconds] = match |
| 90 | if (!days && !hours && !minutes && !seconds) return null |
| 91 | return ( |
| 92 | Number(days ?? 0) * 86400 + |
| 93 | Number(hours ?? 0) * 3600 + |
| 94 | Number(minutes ?? 0) * 60 + |
| 95 | Number(seconds ?? 0) |
| 96 | ) |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Resolves a channel reference to its "uploads" playlist ID via `channels.list`. |