Untitled

 avatar
unknown
plain_text
2 years ago
3.4 kB
6
Indexable
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>YouTube Playlist Downloader</title>
</head>
<body>
  <h1>YouTube Playlist Downloader</h1>
  <input type="text" id="playlist-url" placeholder="Enter YouTube playlist URL">
  <select id="video-quality">
    <option value="1080p">1080p</option>
    <option value="720p">720p</option>
    <option value="480p">480p</option>
    <option value="mp3">mp3</option>
  </select>
  <button onclick="downloadPlaylist()">Download Playlist</button>
  <button onclick="downloadThumbnail()">Download Thumbnail</button>
  <button onclick="downloadThumbnailCover()">Download Thumbnail Cover</button>
  <button onclick="downloadPlaylistAsZip()">Download Playlist as Zip</button>
  <script>
    function downloadPlaylist() {
      // Get the playlist URL from the input field.
      var playlistUrl = document.getElementById("playlist-url").value;
    
      // Create a new XMLHttpRequest object.
      var xhr = new XMLHttpRequest();
    
      // Set the request method to "GET".
      xhr.open("GET", playlistUrl);
    
      // Start the request.
      xhr.send();
    
      // Check the response status code.
      if (xhr.status === 200) {
        // The request was successful.
        // Get the response body.
        var body = xhr.responseText;
    
        // Parse the response body into a JSON object.
        var playlist = JSON.parse(body);
    
        // Create a new directory for the playlist.
        var directory = new Date().getTime();
        mkdir(directory);
    
        // Iterate over the playlist items.
        for (var i = 0; i < playlist.items.length; i++) {
          // Get the video URL from the playlist item.
          var videoUrl = playlist.items[i].snippet.resourceId.videoId;
    
          // Download the video.
          downloadVideo(videoUrl, directory);
        }
    
        // Create a zip file for the playlist.
        var zip = new JSZip();
    
        // Iterate over the directory.
        for (var file in directory) {
          // If the file is a regular file.
          if (directory.hasOwnProperty(file)) {
            // Add the file to the zip file.
            zip.file(file, directory + "/" + file);
          }
        }
    
        // Save the zip file.
        zip.generateAsync({type:"blob"}).then(function(content) {
          var blob = new Blob([content], {type:"application/zip"});
          var filename = playlistUrl.split("/").pop() + ".zip";
          saveAs(blob, filename);
        });
      } else {
        // The request failed.
        console.log("Request failed: " + xhr.status);
      }
    }
    
    function downloadVideo(videoUrl, directory) {
      // Create a new XMLHttpRequest object.
      var xhr = new XMLHttpRequest();
    
      // Set the request method to "GET".
      xhr.open("GET", videoUrl);
    
      // Set the request header to "Accept".
      xhr.setRequestHeader("Accept", "video/mp4");
    
      // Start the request.
      xhr.send();
    
      // Check the response status code.
      if (xhr.status === 200) {
        // The request was successful.
        // Get the response body.
        var body = xhr.responseText;
    
        // Save the response body to a file.
        var blob = new Blob([body], {type: "video/mp4"});
        var filename = videoUrl.split("/").pop();
        saveAs(
Editor is loading...