Login Register






Thread Rating:
  • 0 Vote(s) - 0 Average


Gold Downloading video from Youtube using JAVA filter_list
Author
Message
RE: Downloading video from Youtube using JAVA #11
Hi all! Are people here who want to know how to convert any video from youtube to AAC? I searched for a long time for a site where I could convert videos, and some days ago, I found the solution. Finally, some friends found a website where you do this for free. There are all the steps and a lot of helpful information about this topic. It's straightforward to understand, and the quality is very high. All you should do is follow all the steps, and no install is required. I hope this information is available for you and you will start to use this as well.







_______________________________
this site: https://coconvert.com/youtube-aac-converter.html
(This post was last modified: 07-19-2021, 01:06 PM by freemonne.)

Reply

RE: Downloading video from Youtube using JAVA #12
(07-01-2021, 10:11 PM)freemonne Wrote: Cool. Do you know any converter for YouTube videos? I want to change the format

I guess you need a converter in Java? if that, am not really aware if there is any.

(07-01-2021, 10:17 PM)_Anthony_ Wrote: Nice brooo keep it up expecting big from you

Thank you much 💪
(This post was last modified: 07-01-2021, 11:42 PM by Mr.Kurd.)
Die  But Don't Lie
“Oh Abu Dharr! Don’t look at the smallness of the sin but look at the one you disobeyed.” Prophet Muhammad (pbuh)
[Image: p_237m2jx1.png]
Click for Free VPN

Reply

RE: Downloading video from Youtube using JAVA #13
(07-01-2021, 10:11 PM)freemonne Wrote: Do you know any converter for YouTube videos? I want to change the format
What type of file format do you wish to convert It to?
[Image: AD83g1A.png]

Reply

RE: Downloading video from Youtube using JAVA #14
(07-01-2021, 10:11 PM)freemonne Wrote: Cool. Do you know any converter for YouTube videos? I want to change the format
https://9convert.com/youtube-to-mp4/en7 =MP4
https://ytmp3.cc/youtube-to-mp3/ =MP3
I HIT THE CTRL KEY, BUT I'M STILL NOT IN CONTROL!

Reply

RE: Downloading video from Youtube using JAVA #15
I use the Ukc YouTube Downloader to download YouTube videos for free. It's really amazing tool.

Reply

RE: Downloading video from Youtube using JAVA #16
(02-06-2019, 07:46 PM)Mr.Kurd Wrote:
In The Name OF Allah
Al-Salam Alekum

[Image: 10-Ways-to-Learn-Java-in-Just-a-Couple-of-Weeks.jpg]

Guys today am going to teach you How to download Youtubes video using Java but you can make your own tool with any other language the tutorial purpose is to understand the method used to download videos.

For any video we are getting its ID in ex. https://www.youtube.com/watch?v=B7bqAsxee4I The ID = B7bqAsxee4I
What to do next is getting this Video info, Youtube provide us a way to get any video info, Which contain URLs we can download videos from: https://www.youtube.com/get_video_info?&video_id=ID_Here

We will fetch our video info by visiting this URL: https://www.youtube.com/get_video_info?&...7bqAsxee4I
You will download a file called get_video_info Basically we will search for a URL, you may find more than a URL which used for different Qualities of the Video.

[Image: Screenshot-7.png]

In this file we will search for a wrod: "url_encoded_fmt_stream_map" What come after it, You should see URLs start with &url= or url=
This file had been encoded with URL Encoding for batter understanding it and making it easier to search for URL even IF we used a tool it is somewhat hard to get the URL because they had been encoded. We will decode it Two times using any decoding method for example this websites: https://www.urldecoder.org/

[Image: Screenshot-9.png]

You can see the URL batter now, IF we visit any of these URLs we are getting the video and using an Open stream in any Programming language we can download the Video. The URL start from url= to &tag Some of videos its URL differ so may need another way of Parsing.

Let us download this video using a simple Java tool:
Source:
PHP Code:
package youtubedownloader;

import java.io.BufferedInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;


/**
 *
 * @author Mr.Kurd
 */
public class downloading {

    
/**
     * @param args the command line arguments
     */
    
private static URL downloadURL;
    
    public static 
void main(String[] args) {
        try {  
            
downloadURL = new URL("URL Here");
        } catch (
MalformedURLException ex) {
            
Logger.getLogger(downloading.class.getName()).log(Level.SEVEREnullex);
        }
        
long length;  
        
boolean completed false;  
        
int count 0;  
        try (
BufferedInputStream bis = new BufferedInputStream(downloadURL.openStream()); FileOutputStream fos = new FileOutputStream("Kurdy.mp4")) {  
            
length downloadURL.openConnection().getContentLength();  
            
int i 0;  
            final 
byte[] data = new byte[1024];  
            while ((
count bis.read(data)) != -1) {  
                    
+= count;  
                    
fos.write(data0count);  
                    }                          
            } catch (
IOException ex) {}                                             
    }


Replace your Download link with URL HERE in side the source and run it, Video Downloaded:
[Image: Screenshot-11.png]

I think you got the idea, Now what our program will do to download video is auto doing steps above.
  • Getting the Video ID.
  • Downloading get_video_info.
  • Parsing the info file till getting the URL.
  • Open stream downloading the video from the URL.

The tool "Created and Developed by Deepank Pant" The Source:


PHP Code:
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package YoutubeDownloader;

import java.io.BufferedInputStream;  
import java.io.BufferedReader;  
import java.io.FileOutputStream;  
import java.io.IOException;  
import java.io.InputStreamReader;  
import java.net.HttpURLConnection;  
import java.net.MalformedURLException;  
import java.net.URL;  
import java.net.URLDecoder;  
import javafx.application.Application;  
import javafx.concurrent.Service;  
import javafx.concurrent.Task;  
import javafx.concurrent.WorkerStateEvent;  
import javafx.event.ActionEvent;  
import javafx.scene.Group;  
import javafx.scene.Scene;  
import javafx.scene.control.Alert;  
import javafx.scene.control.Alert.AlertType;  
import javafx.scene.control.Button;  
import javafx.scene.control.Label;  
import javafx.scene.control.ProgressBar;  
import javafx.scene.control.TextField;  
import javafx.scene.text.Font;  
import javafx.stage.Stage;  
/** 
 * 
 * @author Passionate Coder 
 */  
public class download extends Application {  
    
/*java fx UI element used in the javafx application*/  
    
private Button downloadBtn = new Button();  
    private 
TextField youtubeUrlField = new TextField();  
    private 
TextField fileName = new TextField();  
    private 
Label label1 = new Label();  
    private 
Label label2 = new Label();  
    private 
Label about = new Label("Created and Developed by Deepank Pant");  
    private 
ProgressBar pbar = new ProgressBar(0);  
    private 
URL downloadURL;  
    @
Override  
    
public void start(Stage primaryStage) {  
        
/*Font used in the project*/  
        
Font poorRichard = new Font("Poor Richard"16);  
        
Font poorRichard2 = new Font("Poor Richard"13);  
        
/*setting for the UI element*/  
        
downloadBtn.setText("Download");  
        
downloadBtn.setFont(poorRichard);  
        
downloadBtn.setLayoutX(10);  
        
downloadBtn.setLayoutY(200);  
        
youtubeUrlField.setFont(poorRichard);  
        
youtubeUrlField.setLayoutX(10);  
        
youtubeUrlField.setLayoutY(80);  
        
youtubeUrlField.setPrefColumnCount(23);  
        
fileName.setFont(poorRichard);  
        
fileName.setLayoutX(10);  
        
fileName.setLayoutY(150);  
        
fileName.setPrefColumnCount(23);  
        
label1.setFont(poorRichard);  
        
label1.setText("Youtube URL");  
        
label1.setLayoutX(10);  
        
label1.setLayoutY(50);  
        
label2.setFont(poorRichard);  
        
label2.setText("File Name (Optional)");  
        
label2.setLayoutX(10);  
        
label2.setLayoutY(120);  
        
pbar.setVisible(false);  
        
pbar.setPrefWidth(350);  
        
pbar.setLayoutX(100);  
        
pbar.setLayoutY(200);  
        
about.setFont(poorRichard2);  
        
about.setLayoutX(20);  
        
about.setLayoutY(260);  
        
/*Event is triggered when we press the download button*/  
        
downloadBtn.setOnAction((ActionEvent event) -> {  
            
sendHTTPRequest.restart();  
        });  
        
/*Event is triggered when the sendHTTP request service completed successfully*/  
        
sendHTTPRequest.setOnSucceeded((WorkerStateEvent we) -> {  
            try {  
                
System.out.print(getURLS(sendHTTPRequest.getValue()).toString());
                
downloadURL = new URL(getURLS(sendHTTPRequest.getValue()));  
                
pbar.progressProperty().unbind();  
                
pbar.setProgress(0);  
                
pbar.progressProperty().bind(VideoDownload.progressProperty());  
                
pbar.setVisible(true);  
                
/*if everything goes right then it will start a new service to download the video*/  
                
VideoDownload.restart();  
            } catch (
MalformedURLException ex) {  
                
Alert msg = new Alert(AlertType.INFORMATION);  
                
msg.setTitle("Message from Youtube Downloader");  
                
msg.setContentText("Invalid Url");  
                
msg.showAndWait();  
            }  
        });  
        
/*Event is fired when videDownload service is completed successfully*/  
        
VideoDownload.setOnSucceeded((WorkerStateEvent we) -> {  
            
boolean val VideoDownload.getValue();  
            
System.out.println(val);  
            if (
val) {  
                
Alert msg = new Alert(AlertType.INFORMATION);  
                
msg.setTitle("Message from Youtube Downloader");  
                
msg.setContentText("Download complete");  
                
msg.showAndWait();  
            } else {  
                
Alert msg = new Alert(AlertType.INFORMATION);  
                
msg.setTitle("Message from Youtube Downloader");  
                
msg.setContentText("Download Failed");  
                
msg.showAndWait();  
            }  
            
pbar.setVisible(false);  
        });  
        
Group root = new Group();  
        
root.getChildren().add(downloadBtn);  
        
root.getChildren().add(youtubeUrlField);  
        
root.getChildren().add(fileName);  
        
root.getChildren().add(label1);  
        
root.getChildren().add(label2);  
        
root.getChildren().add(pbar);  
        
root.getChildren().add(about);  
        
Scene scene = new Scene(root500280);  
        
primaryStage.setTitle("Youtube Downloader");  
        
primaryStage.setScene(scene);  
        
primaryStage.setResizable(false);  
        
primaryStage.show();  
    }  
    
/*Method to extract the video id from the url. 
    if the url does not contain 'v=' parameter 
    then it will not work. It will accept only 
    standard url*/  
    
private String getVideoID(String url) {  
        
int index url.indexOf("v=");  
        
String id "";  
        
index += 2;  
        for (
int i indexurl.length(); i++) id += url.charAt(i);  
        return 
id;  
    }  
    
/*This service send the HTTP Request to the youtube server. In response the youtube server 
    sends the video information. This information contains the url in the encoded format. This 
    method decode the url return it as a StringBuilder Object*/  
    
final private Service StringBuilder sendHTTPRequest = new Service StringBuilder > () {  
        @
Override  
        
protected Task StringBuilder createTask() {  
            return new 
Task StringBuilder > () {  
                @
Override  
                
protected StringBuilder call() {  
                    
String response;  
                    
StringBuilder res = new StringBuilder();  
                    
StringBuilder refinedres = new StringBuilder();  
                    try {  
                        
URL url = new URL("https://www.youtube.com/get_video_info?&video_id=" getVideoID(youtubeUrlField.getText()));  
                        
System.out.println(url.toString());  
                        
HttpURLConnection conn = (HttpURLConnectionurl.openConnection();  
                        
conn.setRequestMethod("GET");  
                        
System.out.println(conn.getResponseMessage());  
                        
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));  
                        while ((
response in .readLine()) != nullres.append(response);  
                        
refinedres.append(URLDecoder.decode(URLDecoder.decode(res.toString(), "UTF-8"), "UTF-8")); in .close();  
                        return 
refinedres;  
                    } catch (
MalformedURLException ex) {} catch (IOException ex) {}  
                    return 
null;  
                }  
            };  
        }  
    };  
    
/*This service will download the videos using the URL*/  
    
Service Boolean VideoDownload = new Service Boolean > () {  
        @
Override  
        
protected Task Boolean createTask() {  
            return new 
Task Boolean > () {  
                @
Override  
                
protected Boolean call() throws Exception {  
                    
long length;  
                    
boolean completed false;  
                    
int count 0;  
                    try (
BufferedInputStream bis = new BufferedInputStream(downloadURL.openStream()); FileOutputStream fos = new FileOutputStream(fileName.getText().length() == "video.mp4" fileName.getText().concat(".mp4"))) {  
                        
length downloadURL.openConnection().getContentLength();  
                        
int i 0;  
                        final 
byte[] data = new byte[1024];  
                        while ((
count bis.read(data)) != -1) {  
                            
+= count;  
                            
fos.write(data0count);  
                            
updateProgress(ilength);  
                        }  
                        
completed true;  
                    } catch (
IOException ex) {}  
                    return 
completed;  
                }  
            };  
        }  
    };  
    
/*This methid receives refined response as a paramter and extract the url from the 
    response which will be used to download the video from the youtube*/  
    
private String getURLS(StringBuilder response) {  
        
StringBuilder temp1 = new StringBuilder();  
        
String[] temp2temp3temp4;  
        try {  
            
int index response.indexOf("url_encoded_fmt_stream_map");  
            for (
int i indexresponse.length(); i++) {  
                
temp1.append(response.charAt(i));  
            }  
            
temp2 temp1.toString().split("&url=");  
            if (
temp2.length 0) {  
                
temp3 temp2[1].split(";");  
                if (
temp3.length 0) {  
                    
temp4 temp3[0].split(",");  
                    if (
temp4.length 0) return temp4[0];  
                    else return 
temp3[0];  
                } else return 
temp2[1];  
            }  
        } catch (
Exception e) {  
            
Alert msg = new Alert(AlertType.INFORMATION);  
            
msg.setTitle("Message form youtube Downloader");  
            
msg.setContentText("Error in downloading");  
            
msg.showAndWait();  
        }  
        return 
null;  
    }  
    
/** 
     * @param args the command line arguments 
     */  
    
public static void main(String[] args) {  
        
launch(args);  
    }  


[Image: Screenshot-12.png]

I hope you liked the tutorial..
For any grammatically error am sorry and if you have any question ask below.

Heart
Wa Salam Alekum

crazy the value of this guide! thanks thanks thanksss

Reply

RE: Downloading video from Youtube using JAVA #17
(12-30-2023, 09:36 PM)johnkennedyazores Wrote:
(02-06-2019, 07:46 PM)Mr.Kurd Wrote:
In The Name OF Allah
Al-Salam Alekum

[Image: 10-Ways-to-Learn-Java-in-Just-a-Couple-of-Weeks.jpg]

Guys today am going to teach you How to download Youtubes video using Java but you can make your own tool with any other language the tutorial purpose is to understand the method used to download videos.

For any video we are getting its ID in ex. https://www.youtube.com/watch?v=B7bqAsxee4I The ID = B7bqAsxee4I
What to do next is getting this Video info, Youtube provide us a way to get any video info, Which contain URLs we can download videos from: https://www.youtube.com/get_video_info?&video_id=ID_Here

We will fetch our video info by visiting this URL: https://www.youtube.com/get_video_info?&...7bqAsxee4I
You will download a file called get_video_info Basically we will search for a URL, you may find more than a URL which used for different Qualities of the Video.

[Image: Screenshot-7.png]

In this file we will search for a wrod: "url_encoded_fmt_stream_map" What come after it, You should see URLs start with &url= or url=
This file had been encoded with URL Encoding for batter understanding it and making it easier to search for URL even IF we used a tool it is somewhat hard to get the URL because they had been encoded. We will decode it Two times using any decoding method for example this websites: https://www.urldecoder.org/

[Image: Screenshot-9.png]

You can see the URL batter now, IF we visit any of these URLs we are getting the video and using an Open stream in any Programming language we can download the Video. The URL start from url= to &tag Some of videos its URL differ so may need another way of Parsing.

Let us download this video using a simple Java tool:
Source:
PHP Code:
package youtubedownloader;

import java.io.BufferedInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;


/**
*
* @author Mr.Kurd
*/
public class downloading {

    /**
    * @param args the command line arguments
    */
    private static URL downloadURL;
    
    
public static void main(String[] args) {
        try {  
            downloadURL 
= new URL("URL Here");
        } catch (MalformedURLException ex) {
            Logger.getLogger(downloading.class.getName()).log(Level.SEVEREnullex);
        }
        long length;  
        boolean completed 
false;  
        int count 
0;  
        
try (BufferedInputStream bis = new BufferedInputStream(downloadURL.openStream()); FileOutputStream fos = new FileOutputStream("Kurdy.mp4")) {  
            length 
downloadURL.openConnection().getContentLength();  
            int i 
0;  
            
final byte[] data = new byte[1024];  
            
while ((count bis.read(data)) != -1) {  
                    i 
+= count;  
                    fos
.write(data0count);  
                    
}                          
            
} catch (IOException ex) {}                                            
    
}


Replace your Download link with URL HERE in side the source and run it, Video Downloaded:
[Image: Screenshot-11.png]

I think you got the idea, Now what our program will do to download video is auto doing steps above.
  • Getting the Video ID.
  • Downloading get_video_info.
  • Parsing the info file till getting the URL.
  • Open stream downloading the video from the URL.

The tool "Created and Developed by Deepank Pant" The Source:


PHP Code:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package YoutubeDownloader;

import java.io.BufferedInputStream;  
import java
.io.BufferedReader;  
import java
.io.FileOutputStream;  
import java
.io.IOException;  
import java
.io.InputStreamReader;  
import java
.net.HttpURLConnection;  
import java
.net.MalformedURLException;  
import java
.net.URL;  
import java
.net.URLDecoder;  
import javafx
.application.Application;  
import javafx
.concurrent.Service;  
import javafx
.concurrent.Task;  
import javafx
.concurrent.WorkerStateEvent;  
import javafx
.event.ActionEvent;  
import javafx
.scene.Group;  
import javafx
.scene.Scene;  
import javafx
.scene.control.Alert;  
import javafx
.scene.control.Alert.AlertType;  
import javafx
.scene.control.Button;  
import javafx
.scene.control.Label;  
import javafx
.scene.control.ProgressBar;  
import javafx
.scene.control.TextField;  
import javafx
.scene.text.Font;  
import javafx
.stage.Stage;  
/** 

* @author Passionate Coder 
*/
  
public class download extends Application {  
    
/*java fx UI element used in the javafx application*/  
    
private Button downloadBtn = new Button();  
    
private TextField youtubeUrlField = new TextField();  
    
private TextField fileName = new TextField();  
    
private Label label1 = new Label();  
    
private Label label2 = new Label();  
    
private Label about = new Label("Created and Developed by Deepank Pant");  
    
private ProgressBar pbar = new ProgressBar(0);  
    
private URL downloadURL;  
    
@Override  
    
public void start(Stage primaryStage) {  
        
/*Font used in the project*/  
        Font poorRichard 
= new Font("Poor Richard"16);  
        Font poorRichard2 
= new Font("Poor Richard"13);  
        
/*setting for the UI element*/  
        downloadBtn
.setText("Download");  
        downloadBtn
.setFont(poorRichard);  
        downloadBtn
.setLayoutX(10);  
        downloadBtn
.setLayoutY(200);  
        youtubeUrlField
.setFont(poorRichard);  
        youtubeUrlField
.setLayoutX(10);  
        youtubeUrlField
.setLayoutY(80);  
        youtubeUrlField
.setPrefColumnCount(23);  
        fileName
.setFont(poorRichard);  
        fileName
.setLayoutX(10);  
        fileName
.setLayoutY(150);  
        fileName
.setPrefColumnCount(23);  
        label1
.setFont(poorRichard);  
        label1
.setText("Youtube URL");  
        label1
.setLayoutX(10);  
        label1
.setLayoutY(50);  
        label2
.setFont(poorRichard);  
        label2
.setText("File Name (Optional)");  
        label2
.setLayoutX(10);  
        label2
.setLayoutY(120);  
        pbar
.setVisible(false);  
        pbar
.setPrefWidth(350);  
        pbar
.setLayoutX(100);  
        pbar
.setLayoutY(200);  
        about
.setFont(poorRichard2);  
        about
.setLayoutX(20);  
        about
.setLayoutY(260);  
        
/*Event is triggered when we press the download button*/  
        downloadBtn
.setOnAction((ActionEvent event) -> {  
            sendHTTPRequest
.restart();  
        
});  
        
/*Event is triggered when the sendHTTP request service completed successfully*/  
        sendHTTPRequest
.setOnSucceeded((WorkerStateEvent we) -> {  
            
try {  
                System
.out.print(getURLS(sendHTTPRequest.getValue()).toString());
                downloadURL = new URL(getURLS(sendHTTPRequest.getValue()));  
                pbar
.progressProperty().unbind();  
                pbar
.setProgress(0);  
                pbar
.progressProperty().bind(VideoDownload.progressProperty());  
                pbar
.setVisible(true);  
                
/*if everything goes right then it will start a new service to download the video*/  
                VideoDownload
.restart();  
            
} catch (MalformedURLException ex) {  
                Alert msg 
= new Alert(AlertType.INFORMATION);  
                msg
.setTitle("Message from Youtube Downloader");  
                msg
.setContentText("Invalid Url");  
                msg
.showAndWait();  
            
}  
        
});  
        
/*Event is fired when videDownload service is completed successfully*/  
        VideoDownload
.setOnSucceeded((WorkerStateEvent we) -> {  
            boolean val 
VideoDownload.getValue();  
            System
.out.println(val);  
            
if (val) {  
                Alert msg 
= new Alert(AlertType.INFORMATION);  
                msg
.setTitle("Message from Youtube Downloader");  
                msg
.setContentText("Download complete");  
                msg
.showAndWait();  
            
} else {  
                Alert msg 
= new Alert(AlertType.INFORMATION);  
                msg
.setTitle("Message from Youtube Downloader");  
                msg
.setContentText("Download Failed");  
                msg
.showAndWait();  
            
}  
            pbar
.setVisible(false);  
        
});  
        Group root 
= new Group();  
        root
.getChildren().add(downloadBtn);  
        root
.getChildren().add(youtubeUrlField);  
        root
.getChildren().add(fileName);  
        root
.getChildren().add(label1);  
        root
.getChildren().add(label2);  
        root
.getChildren().add(pbar);  
        root
.getChildren().add(about);  
        Scene scene 
= new Scene(root500280);  
        primaryStage
.setTitle("Youtube Downloader");  
        primaryStage
.setScene(scene);  
        primaryStage
.setResizable(false);  
        primaryStage
.show();  
    
}  
    
/*Method to extract the video id from the url. 
    if the url does not contain 'v=' parameter 
    then it will not work. It will accept only 
    standard url*/
  
    
private String getVideoID(String url) {  
        int index 
url.indexOf("v=");  
        String id 
"";  
        index 
+= 2;  
        
for (int i indexurl.length(); i++) id += url.charAt(i);  
        
return id;  
    
}  
    
/*This service send the HTTP Request to the youtube server. In response the youtube server 
    sends the video information. This information contains the url in the encoded format. This 
    method decode the url return it as a StringBuilder Object*/
  
    
final private Service StringBuilder sendHTTPRequest = new Service StringBuilder > () {  
        
@Override  
        
protected Task StringBuilder createTask() {  
            
return new Task StringBuilder > () {  
                
@Override  
                
protected StringBuilder call() {  
                    String response
;  
                    StringBuilder res 
= new StringBuilder();  
                    StringBuilder refinedres 
= new StringBuilder();  
                    
try {  
                        URL url 
= new URL("https://www.youtube.com/get_video_info?&video_id=" getVideoID(youtubeUrlField.getText()));  
                        System
.out.println(url.toString());  
                        HttpURLConnection conn 
= (HttpURLConnectionurl.openConnection();  
                        conn
.setRequestMethod("GET");  
                        System
.out.println(conn.getResponseMessage());  
                        BufferedReader in 
= new BufferedReader(new InputStreamReader(conn.getInputStream()));  
                        
while ((response in .readLine()) != nullres.append(response);  
                        refinedres
.append(URLDecoder.decode(URLDecoder.decode(res.toString(), "UTF-8"), "UTF-8")); in .close();  
                        
return refinedres;  
                    
} catch (MalformedURLException ex) {} catch (IOException ex) {}  
                    
return null;  
                
}  
            
};  
        
}  
    
};  
    
/*This service will download the videos using the URL*/  
    Service 
Boolean VideoDownload = new Service Boolean > () {  
        
@Override  
        
protected Task Boolean createTask() {  
            
return new Task Boolean > () {  
                
@Override  
                
protected Boolean call() throws Exception {  
                    long length
;  
                    boolean completed 
false;  
                    int count 
0;  
                    
try (BufferedInputStream bis = new BufferedInputStream(downloadURL.openStream()); FileOutputStream fos = new FileOutputStream(fileName.getText().length() == "video.mp4" fileName.getText().concat(".mp4"))) {  
                        length 
downloadURL.openConnection().getContentLength();  
                        int i 
0;  
                        
final byte[] data = new byte[1024];  
                        
while ((count bis.read(data)) != -1) {  
                            i 
+= count;  
                            fos
.write(data0count);  
                            updateProgress
(ilength);  
                        
}  
                        completed 
true;  
                    
} catch (IOException ex) {}  
                    
return completed;  
                
}  
            
};  
        
}  
    
};  
    
/*This methid receives refined response as a paramter and extract the url from the 
    response which will be used to download the video from the youtube*/
  
    
private String getURLS(StringBuilder response) {  
        StringBuilder temp1 
= new StringBuilder();  
        String
[] temp2temp3temp4;  
        
try {  
            int index 
response.indexOf("url_encoded_fmt_stream_map");  
            
for (int i indexresponse.length(); i++) {  
                temp1
.append(response.charAt(i));  
            
}  
            temp2 
temp1.toString().split("&url=");  
            
if (temp2.length 0) {  
                temp3 
temp2[1].split(";");  
                
if (temp3.length 0) {  
                    temp4 
temp3[0].split(",");  
                    
if (temp4.length 0) return temp4[0];  
                    
else return temp3[0];  
                
} else return temp2[1];  
            
}  
        
} catch (Exception e) {  
            Alert msg 
= new Alert(AlertType.INFORMATION);  
            msg
.setTitle("Message form youtube Downloader");  
            msg
.setContentText("Error in downloading");  
            msg
.showAndWait();  
        
}  
        
return null;  
    
}  
    
/** 
    * @param args the command line arguments 
    */
  
    
public static void main(String[] args) {  
        launch
(args);  
    
}  
}  

[Image: Screenshot-12.png]

I hope you liked the tutorial..
For any grammatically error am sorry and if you have any question ask below.

Heart
Wa Salam Alekum

crazy the value of this guide! thanks thanks thanksss
Always welcome Smile
Die  But Don't Lie
“Oh Abu Dharr! Don’t look at the smallness of the sin but look at the one you disobeyed.” Prophet Muhammad (pbuh)
[Image: p_237m2jx1.png]
Click for Free VPN

Reply

RE: Downloading video from Youtube using JAVA #18
I hope i could be able to do this by myself

Reply

RE: Downloading video from Youtube using JAVA #19
(09-03-2024, 08:25 PM)kingzlatan Wrote: I hope i could be able to do this by myself
Can't be easier..
Die  But Don't Lie
“Oh Abu Dharr! Don’t look at the smallness of the sin but look at the one you disobeyed.” Prophet Muhammad (pbuh)
[Image: p_237m2jx1.png]
Click for Free VPN

Reply







Users browsing this thread: 4 Guest(s)