previewVideoId property
String?
previewVideoId
Implementation
String? get previewVideoId =>
root
.get('playabilityStatus')
?.get('errorScreen')
?.get('playerLegacyDesktopYpcTrailerRenderer')
?.getT<String>('trailerVideoId') ??
Uri.splitQueryString(
root
.get('playabilityStatus')
?.get('errorScreen')
?.get('')
?.get('ypcTrailerRenderer')
?.getT<String>('playerVars') ??
'',
)['video_id'] ??
root
.get('playabilityStatus')
?.get("errorScreen")
?.get("ypcTrailerRenderer")
?.getT<String>("playerResponse")
// From https://github.com/Tyrrrz/YoutubeExplode
// YouTube uses weird base64-like encoding here that I don't know how to deal with.
// It's supposed to have JSON inside, but if extracted as is, it contains garbage.
// Luckily, some of the text gets decoded correctly, which is enough for us to
// extract the preview video ID using regex.
?.replaceAll('-', '+')
.replaceAll('_', '/')
.pipe(base64.decode)
.pipe(utf8.decode)
.pipe(
(value) => RegExp('video_id=(.{11})').firstMatch(value)?.group(1),
)
?.nullIfWhitespace;