Skip to content

Fix YouTube transcript caption fetching#1499

Open
sczhengyabin wants to merge 6 commits into
jackwener:mainfrom
sczhengyabin:main
Open

Fix YouTube transcript caption fetching#1499
sczhengyabin wants to merge 6 commits into
jackwener:mainfrom
sczhengyabin:main

Conversation

@sczhengyabin
Copy link
Copy Markdown

@sczhengyabin sczhengyabin commented May 12, 2026

Description

Fix YouTube transcript failures where caption URLs return an empty response.

Root cause:
YouTube’s /api/timedtext caption URLs now require player-generated PO tokens. The old implementation parsed
ytInitialPlayerResponse.captions.captionTracks[].baseUrl from watch HTML and fetched it directly with fmt=srv3. That URL does not include the player-
generated pot parameter, so YouTube returns HTTP 200 with an empty body, causing Caption URL returned empty response.

Changes:

  • Open the real YouTube watch page and wait for the player to initialize.
  • Use the YouTube player captions module to select the requested caption track.
  • Read the player-generated fmt=json3&pot=... timedtext URL from performance.getEntriesByType('resource').
  • Fetch and parse JSON3 captions into the existing { start, end, text } segment shape.
  • Handle auto-caption-only videos where player.getOption('captions', 'tracklist') is empty by constructing a compatible player track from
    player.getPlayerResponse().captions.captionTracks.
  • Keep the old watch HTML captionTracks -> srv3 XML path as a fallback.
  • Update tests to cover both the new player captions path and the legacy fallback path.

Verification:

Related issue: #1376 #1420

Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • 🌐 New site adapter
  • 📝 Documentation
  • ♻️ Refactor
  • 🔧 CI / build / tooling

Checklist

  • I ran the checks relevant to this PR
  • I updated tests or docs if needed
  • I included output or screenshots when useful

Documentation (if adding/modifying an adapter)

  • Added doc page under docs/adapters/ (if new adapter)
  • Updated docs/adapters/index.md table (if new adapter)
  • Updated sidebar in docs/.vitepress/config.mts (if new adapter)
  • Updated README.md / README.zh-CN.md when command discoverability changed
  • Used positional args for the command's primary subject unless a named flag is clearly better
  • Normalized expected adapter failures to CliError subclasses instead of raw Error

Screenshots / Output

node dist/src/main.js youtube transcript -f json https://www.youtube.com/watch\?v\=Lj4LMlGr4og
[
  {
    "timestamp": "0:00",
    "speaker": "",
    "text": "Does using your phone while charging hurt the battery?"
  },
  {
    "timestamp": "0:02",
    "speaker": "",
    "text": "Two years ago we took apart 16 phones to see if fast charging hurts the battery The answer was No After that people started asking Does using your phone while charging hurt the battery?"
  },
  {
    "timestamp": "0:11",
    "speaker": "",
    "text": "Does heat or cold hurt the battery?"
  },
  {
    "timestamp": "0:14",
    "speaker": "",
    "text": "Is wireless charging bad for the battery?"
  },
  {
    "timestamp": "0:15",
    "speaker": "",
    "text": "It feels like people won’t relax until they find a way to break their battery Also is the last 1% of battery extra durable?"
  },
  {
    "timestamp": "0:22",
    "speaker": "",
    "text": "Is the battery health number on your phone even real?"
  },
  {
    "timestamp": "0:25",
    "speaker": "",
    "text": "How much do batteries hurt the environment?"
  },
  {
    "timestamp": "0:27",
    "speaker": "",
    "text": "To answer these questions we did a very long test First we set up 4 phones for normal charging When the battery dropped to 5%, a relay turned on and started charging When it hit 100% the relay cut off and our app started draining the battery down to 5% again This loop kept going To test if using the phone while charging is bad we prepared another 4 phones These phones did the same 5%-100% charging loop But while charging the discharge app was also running — just like using your phone while it’s charging"
  },
  {
    "timestamp": "0:58",
    "speaker": "",
    "text": "Besides that we had 16 more phones in the room Some were put in a hot box some on wireless chargers Each group had their own tests To keep the results fair All phones were bought by us through official stores just like last time To show time passing we planted some plants…"
  },
  {
    "timestamp": "1:41",
    "speaker": "",
    "text": "Time flew by After 193 days we grew 76 cucumbers And all phones finished 2000 hours of discharging The normal charging group did 750 charge cycles Their batteries lost about 9.0% capacity on average The \"charging while using\" group did only 380 cycles because charging while using is slower and their batteries lost about 3.5%."
  },
  {
    "timestamp": "2:04",
    "speaker": "",
    "text": "We then checked how much normal phones dropped after around 400 cycles — about 3.7%."
  },
  {
    "timestamp": "2:09",
    "speaker": "",
    "text": "Very close So in our test what really affects battery life is the number of cycles Using your phone while charging does not hurt the battery more But this result feels strange When you use your phone while charging the temperature is higher In our test Just charging makes battery warms up to 33°C(91.4℉) Charging while using makes battery warms up to 37°C(98.6℉) 1°C(33.8℉)hotter than playing games Isn’t higher temperature supposed to hurt the battery?"
  },
  {
    "timestamp": "2:34",
    "speaker": "",
    "text": "That’s what we tested next We put 4 phones in a hot box at around 35°C(95℉) During charging they heated up to 45°C(113℉) We also put 4 phones into a cold box around 0°C(32℉) Their max temperature was only 3°C(37.4℉) After 2000 hours In the hot box batteries dropped about 9.6% A little more than normal but not much In the cold box 3 phones dropped about 7.8%, but one phone suddenly dropped 45%."
  },
  {
    "timestamp": "2:58",
    "speaker": "",
    "text": "This made the cold test results unreliable Overall As long as you use your phone within the normal temperature range battery life is fine Still I don’t recommend using your phone while charging — it just feels bad when the phone gets too hot But you know when I do worry about battery life?"
  },
  {
    "timestamp": "3:13",
    "speaker": "",
    "text": "When my phone hits 1%."
  },
  {
    "timestamp": "3:15",
    "speaker": "",
    "text": "A lot of people feel like the last 1% of battery and the 100%-99% drop last a long time Is it true?"
  },
  {
    "timestamp": "3:22",
    "speaker": "",
    "text": "We charged 3 phones to 100%, ran our discharge app and used a shortcut to record battery every 5 seconds After 15 tests From 99% to 1%, each percent lasted about 110 seconds pretty even But from 100% to 99%, it lasted more than 350 seconds — 3 to 5 times longer!"
  },
  {
    "timestamp": "3:41",
    "speaker": "",
    "text": "Turns out people’s feeling was right We tested other phone models too Same result Our friends at ChargerLab told us: Phones might \"show\" 100% before they are fully full Because the closer you get to 100%, the slower the charging If they waited for true 100%, it would take longer and once you unplug and start using it you’d immediately drop to 99%, which would feel bad As for 1% battery to shutdown: After 15 tests the phones lasted between 120 and 300 seconds So it could die fast or last a few minutes — it’s random"
  },
  {
    "timestamp": "4:14",
    "speaker": "",
    "text": "Best way?"
  },
  {
    "timestamp": "4:15",
    "speaker": "",
    "text": "Just plug it in as soon as possible Also a lot of my coworkers kept a wireless charger on their desk When they work they just pick up the phone when needed and put it back down to charge when done It keeps the battery level high But does frequent charging hurt the battery?"
  },
  {
    "timestamp": "4:28",
    "speaker": "",
    "text": "Is wireless charging worse than wired?"
  },
  {
    "timestamp": "4:31",
    "speaker": "",
    "text": "We tested 8 phones: One group charged wirelessly from 5% to 100% One group charged from 80% to 95% wirelessly Results after 2000 hours: 5%-100% group lost about 9.0% — same as normal wired charging 80%-95% group only lost about 3.9% — much better!"
  },
  {
    "timestamp": "4:48",
    "speaker": "",
    "text": "So: Wireless charging does not hurt more than wired charging Avoiding deep discharge helps keep your battery healthy So charge whenever you want Pick up whenever you want It might even make your battery last longer Finally is the battery health number on your iPhone accurate?"
  },
  {
    "timestamp": "5:02",
    "speaker": "",
    "text": "In the test we checked battery health every 200 hours and physically measured the battery Result The iPhone’s battery health reading is roughly accurate It shows the general trend But it’s not exact Sometimes it’s off by less than 1%, but sometimes over 4%."
  },
  {
    "timestamp": "5:17",
    "speaker": "",
    "text": "That’s because it’s based on estimated data like cycle count voltage current, not a real measurement Still you can trust it for a general idea And that’s everything we found We spent so much time and effort on this test because first many viewers were truly curious and second because when I got my first phone I treated it like the most precious thing I had I hope this video helps you use your phone more freely — without worry Just like last time we have replaced the batteries of all 24 phones used in the experiment with brand-new ones and gave them away"
  },
  {
    "timestamp": "5:48",
    "speaker": "",
    "text": "we gave all the old batteries to recycling Why can't you just throw old phone batteries in the trash?"
  },
  {
    "timestamp": "5:53",
    "speaker": "",
    "text": "We put some battery chemicals into soil planted some plants and here’s what happened"
  }
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant