Closed rajjys closed 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
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"
class java.lang.String cannot be converted to class java.lang.String
seems very strange, may be you have some issues with java versions?
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
Java 8+ should works, but I mean maybe you have messed up classpath?
Also provide full stacktrace
response.error().printStackTrace()
`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)
`
check which version of com.alibaba.fastjson
do you have in classpath
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?
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
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.
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?
yes, indeed there is no constructor for such case
but you can create JSONObject json
and populate it with required fields
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.
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