nhCoder / YouTubeExtractor

Extracts Youtube urls for streaming and downloading purpose.
Apache License 2.0
68 stars 25 forks source link

Error While getting Youtube Data:com.google.gson.stream.MalformedJsonException #32

Closed kawulogustidev closed 4 years ago

kawulogustidev commented 4 years ago

Hello, I receive an error using the latest code. I think, Youtube has made some changes to the player response json.

Error While getting Youtube Data:com.google.gson.stream.MalformedJsonException: Unterminated string at line 1 column 121677 path $.args.player_response

The error is on the following code:

private PlayerResponse parseJson(String body) throws Exception { JsonParser parser = new JsonParser(); LogUtils.log("Body: "+body); response = new GsonBuilder().serializeNulls().create().fromJson(parser.parse(body), Response.class); return new GsonBuilder().serializeNulls().create().fromJson(response.getArgs().getPlayerResponse(), PlayerResponse.class); }

I guess there is need some changes on regex pattern.

yyms3275 commented 4 years ago

I have the same problem. Error While getting Youtube Data : com.google.gson.stream.MalformedJsonException: Unterminated string at line 1 column 101601 path $.args.player_response

craftbox2245 commented 4 years ago

same problem Error While getting Youtube Data : com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Unterminated string at line 1 column 96226 path $.args.player_response

The error is on the following code: private String parsePlayerConfig(String body) throws ExtractorException {

    Log.d("=>=", "parsePlayerConfig: "+ RegexUtils.matchGroup(regexPageLink, body,"logd u streem"));
    if (Utils.isListContain(reasonUnavialable, RegexUtils.matchGroup(regexPageLink, body,"parseplayer if"))) {
        throw new ExtractorException(RegexUtils.matchGroup(regexPageLink, body,"parse player if true"));
    }
    if (body.contains("ytplayer.config")) {
        return RegexUtils.matchGroup(regexPlayerJson, body,"u strem body contain if");
    } else {
        throw new ExtractorException("This Video is unavialable");
    }
}

private PlayerResponse parseJson(String body) throws Exception { JsonParser parser = new JsonParser(); LogUtils.log("Body: "+body); response = new GsonBuilder().serializeNulls().create().fromJson(parser.parse(body), Response.class); return new GsonBuilder().serializeNulls().create().fromJson(response.getArgs().getPlayerResponse(), PlayerResponse.class); }

hhyeok1026 commented 4 years ago

Someone will help us !

solohan33344 commented 4 years ago

I think this has to do with captcha needed for streaming video because of youtube's new policy

FelipeRRM commented 4 years ago

Yeah, same issue here, anybody got a fix for it?

hhyeok1026 commented 4 years ago

I found some revised yesterday in something similar to this project. I'm leaving a link as I think this can help with the correction.

https://github.com/sealedtx/java-youtube-downloader/commit/4a98b11b3ed2fc98e93117929dedf63489c2ecb9

krathore01 commented 4 years ago

change String regexPlayerJson="(?<=ytplayer.config\s=).?((\}(\n|)\}(\n|))|(\}))(?=;)"; to String regexPlayerJson="(?<=ytplayer.config\s=).?((\}(\n|)\}(\n|))|(\}))(?=;ytplayer)";

in YoutubeStreamExtractor.java. It worked for me.

kawulogustidev commented 4 years ago

Another alternative, use https://github.com/sealedtx/java-youtube-downloader, then use the code to the Extractor. It also worked for me.

nhCoder commented 4 years ago

Sorry for no updates.. im busy in exams nowadays... If you find a fix that's good else ill fix myself in next 2 days..

Diazo89 commented 4 years ago

@krathore01 The following error appears https://ibb.co/J7zT5bm

niteshfel commented 4 years ago

@krathore01 The following error appears https://ibb.co/J7zT5bm

use this (?<=ytplayer.config\s=).?((}(\n|)}(\n|))|(}))(?=;ytplayer)

niteshfel commented 4 years ago

Sorry for no updates.. im busy in exams nowadays... If you find a fix that's good else ill fix myself in next 2 days Please solve this ASAP

yyms3275 commented 4 years ago

It doesn't work even if I change it like below String regexPlayerJson="(?<=ytplayer.config\s=).?((\}(\n|)\}(\n|))|(\}))(?=;ytplayer)"; ㅠ_ㅠ

hhyeok1026 commented 4 years ago

@yyms3275

When I try this, it works.

String regexPlayerJson="(?<=ytplayer.config\s=).*?((\}(\n|)\}(\n|))|(\}))(?=;ytplayer)";

image

yyms3275 commented 4 years ago

@hhyeok1026

감사합니다. 다시해보니 잘되네요 ^^ (Thank you. Trying again, it works well ^^)