sealedtx / java-youtube-downloader

Simple, almost zero-dependency java parser for retrieving youtube video metadata
Other
426 stars 117 forks source link

response.data() returns null #103

Closed rajjys closed 2 years ago

rajjys commented 2 years ago

RequestVideoInfo request = new RequestVideoInfo(videoId); Response<VideoInfo> response = downloader.getVideoInfo(request); VideoInfo video = response.data(); /// response.data() is null

Returns null hence can't retrieve videoInfo. I also was wondering if a Youtube API KEY is required for this to work

sealedtx commented 2 years ago

before calling response.data() you should check if request was successful -response.ok() if it returns false you can check what is returned by response.error()

you don't need API KEY, this library works as web scraper

rajjys commented 2 years ago

response.ok() returns false and response.error() gives

"java.util.concurrent.ExecutionException: com.alibaba.fastjson2.JSONException: class java.lang.String cannot be converted to class java.lang.String"

sealedtx commented 2 years ago

class java.lang.String cannot be converted to class java.lang.String seems very strange, may be you have some issues with java versions?

rajjys commented 2 years ago

Which versions should i use? At the same time, YoutubeVideoExtractor_Tests.java returns "getVideo should be successful for default videos without signature" YoutubeDownloader_Tests returns: "download subtitles should work" as well as "download video should work" Maybe its me that do not understand how this work

sealedtx commented 2 years ago

Java 8+ should works, but I mean maybe you have messed up classpath? Also provide full stacktrace response.error().printStackTrace()

rajjys commented 2 years ago

`java.util.concurrent.ExecutionException: com.alibaba.fastjson2.JSONException: class java.lang.String cannot be converted to class java.lang.String

at java.base/java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:191)
at com.github.kiulian.downloader.downloader.response.ResponseImpl.error(ResponseImpl.java:96)
at MainClass.videoInfo(MainClass.java:70)
at MainClass.main(MainClass.java:46)

Caused by: com.alibaba.fastjson2.JSONException: class java.lang.String cannot be converted to class java.lang.String

at com.alibaba.fastjson.JSONArray.toJavaList(JSONArray.java:817)
at com.github.kiulian.downloader.model.videos.VideoDetails.<init>(VideoDetails.java:30)
at com.github.kiulian.downloader.parser.ParserImpl.parseVideoDetails(ParserImpl.java:182)
at com.github.kiulian.downloader.parser.ParserImpl.parseVideoAndroid(ParserImpl.java:104)
at com.github.kiulian.downloader.parser.ParserImpl.parseVideo(ParserImpl.java:63)
at com.github.kiulian.downloader.parser.ParserImpl.lambda$0(ParserImpl.java:49)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:833)

`

sealedtx commented 2 years ago

check which version of com.alibaba.fastjson do you have in classpath

rajjys commented 2 years ago

Yeah, like you pointed before, i had a problem with my classpath and the overall project configuration. I reset everything and started from scratch, now it works fine. Thank you for the amazing work. Just one quick question before i close: if i have the googlevideo.com/videoplayback link from an API call and i just want to use this library for the download part, how do i proceed?

sealedtx commented 2 years ago

Not familiar with youtube API, what exactly link do you have? If it is direct link to video file you can simply copy code snippet responsible for downloading file. Or you can manually create Format, fill it with your data, create RequestVideoFileDownload and call Downloader#downloadVideoAsFile https://github.com/sealedtx/java-youtube-downloader/blob/34b683810f5aa1e74782e56a49230cc3ea283e79/src/main/java/com/github/kiulian/downloader/downloader/DownloaderImpl.java#L117

rajjys commented 2 years ago

Yeah and that's the question actually, i have not found a way to manually create a Format object with my desired data(url) protected Format(JSONObject json, boolean isAdaptive, String clientVersion) is the only option i see but can't use.

ex: https://rr2---sn-ap90pquxaxjvh-3bae.googlevideo.com/videoplayback?expire=1657223644&ei=fOXGYq2_KI_XxwKOtIpI&ip=102.223.208.45&id=o-AOBVMm6U9AAvktoluvlYoDLhZN4ZEmuVKzWsA7T-EBdN&itag=22&source=youtube&requiressl=yes&mh=Bi&mm=31%2C29&mn=sn-ap90pquxaxjvh-3bae%2Csn-hc57enee&ms=au%2Crdu&mv=m&mvi=2&pl=24&initcwndbps=131250&vprv=1&mime=video%2Fmp4&cnr=14&ratebypass=yes&dur=101.517&lmt=1647898851406326&mt=1657201771&fvip=5&fexp=24001373%2C24007246&c=ANDROID&txp=6318224&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cvprv%2Cmime%2Ccnr%2Cratebypass%2Cdur%2Clmt&sig=AOq0QJ8wRAIgZDLRT2KmeHbfZzJdSLOTRDLmyXf9ZIPajRdCuv31_vACICUliwDqh4N8LSDoIVgamYV2GedBdRoAbDHpbqo0WQSe&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRQIgIL1vA3bSLVi2aUqU9uRE_w1N-IZGrM9zWlLa_l3FQdICIQCoLH7NRFT19BUI7WzryPv1xpCRQxRnvZ3BMPrmgR_LTA%3D%3D

which is basically what i got from it.url() in the code But assume i got this link from another source, how do i create a Format object with it?

sealedtx commented 2 years ago

yes, indeed there is no constructor for such case but you can create JSONObject json and populate it with required fields

rajjys commented 2 years ago

Thank you Mr. Igor and sorry for taking too much of your time. I've learned a lot from this conversation alone. Keep up the good work and stay safe.