libre-tube / LibreTube

An alternative frontend for YouTube, for Android.
https://libretube.dev
GNU General Public License v3.0
8.74k stars 446 forks source link

Show size of downloading file (video) before starting download itself. #3278

Closed heartlog closed 1 year ago

heartlog commented 1 year ago

Feature request

Show size of file after choosing the resolution and audio quality.

1.After selecting the resolution of the file, the application could calculate the size of the file to be downloaded.

2.The calculated size of the file could then be displayed next to the resolution option selected, perhaps in a different color or font to make it more visible.

How should it be ?

Selection of video resolution

Screenshot_20230310_132832_LibreTube

Select audio quality

Screenshot_20230310_132839_LibreTube

Resulting last interface

Screenshot_20230310_134103_LibreTube

Other details

Why we need it ?

By this user's can download video according to storage and dataplan while considering the network šŸ›œ speed.. Not to mention Newpipe already have this feature, you can see that for reference..

šŸ‘

Acknowledgements

Bnyro commented 1 year ago

How would you want to calculate the file sizes of the download? The API doesn't return information about it, therefore it could only be guessed based on a formula. Fetching the size for each possible stream individually would cause a lot of unneeded network traffic. I found an article which could be started of with, however I'm not sure how appropriate it would be.

heartlog commented 1 year ago

Well I have an idea Well you you can try Stackoverflow article

Bnyro commented 1 year ago

I already stated out previously that it's not a solution as it would cause unneeded network traffic.

heartlog commented 1 year ago

Why not try then newpipes method ?

heartlog commented 1 year ago

As far as i khow newpipe also extract the video source url and somehow determines the size of video

heartlog commented 1 year ago

size of a video in Java based on its playback URL, you can use following code ..

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;

public class VideoSize {

    public static void main(String[] args) throws IOException {
        URL url = new URL("https://pipedproxy-bom.kavin.rocks/videoplayback?expire=1678474107&ei=GycLZPqaAcyGvw%3D%3D&cpn=jbveMn4EKPCy0CDH&host=rr1---sn-cvh76nls.googlevideo.com");

        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("HEAD");
        int fileSize = connection.getContentLength();
        System.out.println("File size: " + fileSize + " bytes");
    }
}

This code sends a HEAD request to the video URL to retrieve the header information, which includes the content length of the video file. The content length is then printed to the console in bytes.

FireMasterK commented 1 year ago

You can send a HEAD request to each streaming URL, then calculate it based on the Content-Length header.

Bnyro commented 1 year ago

I'm aware, we're already doing that when starting a download. However, that would need to be done for 20 streams in parallel and in my opinion cause unneeded server traffic.

heartlog commented 1 year ago

I'm aware, we're already doing that when starting a download. However, that would need to be done for 20 streams in parallel and in my opinion cause unneeded server traffic.

How about using nested list (multiline drop-down was it ?) like structure? Ex. 1) 144p ā†“

Then if I click 480 then the format option will become apparent. Like this you can divide 20 stream according and limit to less request to server at time. āˆ“ only 2-3 (max 4) request required for 1 resolution at time.

heartlog commented 1 year ago

This is my idea

Untitled43_20230311155102

By this there will be no load on server and also it'll be fast.

heartlog commented 1 year ago

.

FireMasterK commented 1 year ago

https://github.com/libre-tube/LibreTube/blob/master/CODE_OF_CONDUCT.md

Please don't tag maintainers/members.

heartlog commented 1 year ago

Sorry, about that

Bnyro commented 1 year ago

That's now possible thanks to https://github.com/TeamPiped/Piped-Backend/pull/599

heartlog commented 1 year ago

Thank God !! Good work Bnyro !! šŸ„°