sealedtx / java-youtube-downloader

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

Format.contentLength() returns null #104

Closed rajjys closed 2 years ago

rajjys commented 2 years ago

Hi brother! is it possible to know the size of each video/audio format object? I've tried with Format.ContentLength() but it throws Null Pointer Exception from AudioFormat or VideoFormat

sealedtx commented 2 years ago

Hi, share please videoId you are trying to get size, code snippet and stacktrace

rajjys commented 2 years ago

yeah for example the code List<VideoFormat> videoList = video.VideoWithAudioFormat(); for(var it : videoList){ System.out.println(it.height + "p" + "has size:" + it.contentLength() + "Mb"); ////this throws NPE }

What i want to display is something like 144p has size 28Mb 360p has size 38Mb 720p has size 50Mb and so on, but contentLength() throw null

sealedtx commented 2 years ago

which version of java-youtube-downloader do you use? And also share your videoId, because I just tested on random video and it works for me

rajjys commented 2 years ago

yeah version is 3.1.0. For all videos i just tested i got this 144p has 2983948 bytes 360p has 4922939 bytes 720p has null bytes ///Probably the one throwing NPE I wonder maybe I'm using this wrong but for many videoId like these for example: https://www.youtube.com/watch?v=LcrnbWhlE0c https://www.youtube.com/watch?v=rddozSfttT4 https://www.youtube.com/watch?v=TaQwW5eQZeY (haha i love 50Cent by the way) I get a false response from response.ok() with this error: com.github.kiulian.downloader.YoutubeException$BadPageException: streamingData not found

Maybe i should open another issue for the next one i see on HD and 4K videos like these: https://www.youtube.com/watch?v=mkggXE5e2yk, https://www.youtube.com/watch?v=LXb3EKWsInQ is Error parsing format: unknown itag 701 Error parsing format: unknown itag 700 Error parsing format: unknown itag 699 Error parsing format: unknown itag 698 Error parsing format: unknown itag 697 Error parsing format: unknown itag 696 Error parsing format: unknown itag 695 Error parsing format: unknown itag 694

sealedtx commented 2 years ago

yes, I can see, that for some formats contentLength is absent in youtube metadata, in such case you can get approximate size like this: bitrate / 8 * approxDurationMs / 1000 = size in bytes

I can't reproduce streamingData not found exception on those videos you shared, it could be your side problem, like network issue, or youtube blocks scrapping and send you not the original webpage

Regarding new formats and itag you can open new issue and help me investigate it, thank you

rajjys commented 2 years ago

I will open another issue. But the com.github.kiulian.downloader.YoutubeException$BadPageException: streamingData not found is due to my location, apparently the videos they are blocked for my country or location idk. I used a vpn on top and it worked. Thanks