header ads

Html code for YouTube downloader blogger

 To create an HTML code for a YouTube downloader on your Blogger site, you can use JavaScript and the YouTube Data API. Here's an example code snippet for a basic YouTube downloader:


```html

<!DOCTYPE html>

<html>

<head>

    <title>YouTube Downloader</title>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

</head>

<body>

    <h1>YouTube Downloader</h1>


    <input type="text" id="videoId" placeholder="Enter YouTube video ID" />

    <button onclick="getVideo()">Download</button>


    <script>

        function getVideo() {

            var videoId = document.getElementById("videoId").value;


            $.ajax({

                url: "https://www.googleapis.com/youtube/v3/videos?part=contentDetails&id=" + videoId + "&key=YOUR_YOUTUBE_API_KEY",

                dataType: "json",

                success: function(response) {

                    var duration = response.items[0].contentDetails.duration;

                    var formattedDuration = formatDuration(duration);


                    var downloadUrl = "https://www.youtube.com/watch?v=" + videoId;

                    var downloadLink = "<a href='" + downloadUrl + "' download>Download</a>";


                    var result = "Duration: " + formattedDuration + "<br>" + "Download Link: " + downloadLink;


                    document.getElementById("result").innerHTML = result;

                },

                error: function() {

                    document.getElementById("result").innerHTML = "Error occurred";

                }

            });

        }


        function formatDuration(duration) {

            // Convert ISO 8601 duration format (PT#H#M#S) to a more readable format

            var pattern = /P(\d+D)?T(\d+H)?(\d+M)?(\d+S)?/;

            var matches = duration.match(pattern);


            var days = matches[1] ? matches[1].replace("D", "") + " days" : "";

            var hours = matches[2] ? matches[2].replace("H", "") + " hours" : "";

            var minutes = matches[3] ? matches[3].replace("M", "") + " minutes" : "";

            var seconds = matches[4] ? matches[4].replace("S", "") + " seconds" : "";


            return days + hours + minutes + seconds;

        }

    </script>


    <div id="result"></div>

</body>

</html>

```


In the above code, make sure to replace `YOUR_YOUTUBE_API_KEY` with your own YouTube Data API key obtained from the Google Cloud Console.


This code includes an input field to enter the YouTube video ID, and when the 'Download' button is clicked, it retrieves the video's duration using the YouTube Data API and generates a download link for the video. The video's duration is also formatted to a more readable format.


You can embed this code in a Blogger post or create a new HTML/JavaScript gadget on your Blogger layout to display the YouTube downloader.

Post a Comment

0 Comments