Tyrrrz / YoutubeExplode

Abstraction layer over YouTube's internal API
MIT License
2.95k stars 493 forks source link

Newtonsoft.Json.JsonReaderException in GetVideoEmbedPageAsync #164

Closed FilX closed 6 years ago

FilX commented 6 years ago

Newtonsoft.Json.JsonReaderException: 'Additional text encountered after finished reading JSON content: }. Path '', line 1, position 14816.'

Video ID: wFQqbXk4W8Y and all other

It seems that youtube changed site content.

YoutubeClient.GetVideoEmbedPageConfigAsync cannot find expected string .SubstringUntil(",'");

Possible fix:

Instead

var part = raw.SubstringAfter("yt.setConfig({'PLAYER_CONFIG': ").SubstringUntil(",'");

use

var part = raw.SubstringAfter("yt.setConfig({'PLAYER_CONFIG': ").SubstringUntil("});writeEmbed()");

SlowLogicBoy commented 6 years ago

I'm getting the same error on any video:

Newtonsoft.Json.JsonReaderException: Additional text encountered after finished reading JSON content: }. Path '', line 1, position 14836.
   at Newtonsoft.Json.JsonTextReader.Read()
   at Newtonsoft.Json.Linq.JToken.Parse(String json, JsonLoadSettings settings)
   at YoutubeExplode.YoutubeClient.GetVideoEmbedPageConfigAsync(String videoId) in d:\Code\Git\YoutubeExplode\YoutubeExplode\YoutubeClient.Video.cs:line 34
   at YoutubeExplode.YoutubeClient.GetVideoPlayerContextAsync(String videoId) in d:\Code\Git\YoutubeExplode\YoutubeExplode\YoutubeClient.Video.cs:line 88
   at YoutubeExplode.YoutubeClient.GetVideoMediaStreamInfosAsync(String videoId) in d:\Code\Git\YoutubeExplode\YoutubeExplode\YoutubeClient.Video.cs:line 264

Looks like they've changed the encoding or something like that.

SlowLogicBoy commented 6 years ago

var part = raw.SubstringAfter("yt.setConfig({'PLAYER_CONFIG': ").SubstringUntil(",'"); this part no longer works. Changing to: var part = raw.SubstringAfter("yt.setConfig({'PLAYER_CONFIG': ").SubstringUntil("});writeEmbed();"); it started working for me. Haven't tried on other videos. Works on all videos I've tried.

Edit: @FilX lol haven't noticed that you already fixed it.

Tyrrrz commented 6 years ago

Hotfix is out https://ci.appveyor.com/project/Tyrrrz/youtubeexplode/builds/19559537